Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Sleep and timer T0

2005-06-17 by Jim Wagner

Where do you tell it to sleep again? Has it really finished
everything needed for the next int before being put to
sleep?

Jim

On Fri, 17 Jun 2005 01:46:23 -0500
 Dave VanHorn <dvanhorn@dvanhorn.org> wrote:
> 
> I must be missing something..
> 
> I have timer T0 running as a PWM generator with the AS0
> bit in ASSR 
> set, and external 32kHz crystal.
> Now I want to put the system to sleep, and have T0 wake
> me up once a 
> second for time keeping.
> The problem is that once I go to sleep, the T0 int only
> happens ONCE!
> It gets better though.. If I hang a breakpoint in the T0
> ISR, and F10 
> through it, I get through the loop just fine, and I keep
> getting to 
> the T0 int. It's only when I let the code run without
> F10ing it, that 
> it fails to hit the T0OV isr.
> 
> Without the sleep, the T0 int fires once a second, and
> everything 
> acts like it should.
> 
> As I read the data sheet, T0 is supposed to be enabled to
> the 
> external crystal in ESB mode, so what's not right here?
> 
> 
> 
> At this point, I've decided to go to sleep:
> So, I configure T0 for normal operation instead of PWM
> 
>       ;Set timer 0 for once a
> second wakeups
> 
>      
> ldi     
>      
> TEMP,128      ;
>      
> OUT     
>      
> TCNT0,TEMP      ;LOAD THE COUNT
> UP COUNTER
> 
>      
> ldi     
>      
> TEMP,$06      ;
>      
> out     
>      
> TCCR0,TEMP      ;
> 
> I wait to make sure everything "took"
> 
> T0_Sleep_Update:
> 
>      
> in     
> TEMP,ASSR     
>      
> ;0000XXXX      Reserved
>      
> andi     
> TEMP,$07     
>      
> ;XXXXX111      T0 async mode
> enable
>      
>      
>      
>      
>      
> ;00000---      Busy flags, 1 if
> register updating
>      
> brne     
> T0_Sleep_Update      ;
> 
> I clear off the T0 int flags:
> 
>      
> in     
> TEMP,TIFR     
>       ;
>      
> andi     
> TEMP,$03     
>       ;Mask out non T0 bits
>      
> out     
> TIFR,TEMP     
>       ;Turn off flags by writing
> 1's to them
> 
> I turn off the T2 overflow int that was doing my
> timekeeping while awake.
> I turn on the T0 overflow int.
> 
>      
> in     
> TEMP,TIMSK      ;
>      
> andi     
> TEMP,$BF      ;10111111 T2
> overflow off
>      
> ori     
> TEMP,$01      ;00000001 T0
> overflow on
>      
> out     
> TIMSK,TEMP      ;
> 
> I set the sleep mode
> 
> Snooz_Loop:
> 
>       ;Set up the sleep mode
>      
> in     
>      
> TEMP,MCUCR     
>      
>       ;
>      
> ori     
>      
> TEMP,$3C     
>      
>       ; Extended Standby mode
>      
> out     
>      
> MCUCR,TEMP     
>      
>       ;
> 
> Then I sleep:
>      
> sleep     
>      
>      
>      
>      
>       ;
> 
>      
> in     
>      
> TEMP,MCUCR     
>      
>       ;
>      
> andi     
>      
> TEMP,$DF     
>      
>       ; disable sleep
>      
> out     
>      
> MCUCR,TEMP     
>      
>       ;
> 
> 
>       ;Wake up here on pressed
> button ints, or T0 overflow
> 
>       I do some checks here
> after I wake up and the T0 ISR exits,
> 
>      
> breq     
> Snooz_Loop     
>      
>       ;If nothing going on,
> resume sleeping
> 
> If I was to get that far, then i would restore everything
> on the way 
> back to normal operation.
> 
> 
> 
>       
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Yahoo! Groups Links
> 
> To visit your group on the web, go
> to:http://groups.yahoo.com/group/AVR-Chat/ 
> To unsubscribe from this group, send an email
> to:AVR-Chat-unsubscribe@yahoogroups.com 
> Your use of Yahoo! Groups is subject to the Yahoo! Terms
> of Service.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.