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 Francisco Silva

Hi Dave,

2005/6/17, Dave VanHorn <dvanhorn@dvanhorn.org>:
> 
> I must be missing something..
> 

In assynchronous mode you must wait for the registers update (up to 2
32kHz cycles). I use the following code on a atmega8.

inline static void PowerSave(void)
{
    MCUCR = (1 << SE)				// enable sleep mode
	|(0 << SM2) | (1 << SM1) | (1 << SM0);	// selects power save mode
    asm("sleep");
    MCUCR = 0;
}


#define WaitT2Upd() {while (ASSR & ((1 << TCR2UB) | (1 << OCR2UB) | (1
<< TCN2UB)));}

static u16 tcnt2_shadow;
// I maintain a shadow because its expensive to read TCNT2 in async mode

.... loop ....
	WaitT2Upd();
	PowerSave();
	// setup next wake as soon as possible
	tcnt2_shadow += 8 * 256;
	OCR2 = tcnt2_shadow;
.... loop ....


-- 
Francisco

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.