avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Sleeping Code


From: harshit suri
Subject: [avr-gcc-list] Sleeping Code
Date: Sat, 14 Feb 2004 01:48:10 -0800 (PST)

Hi 
im trying to learn the sleep mode of the atmega128.
The datasheet says that if an interrupt occurs when
the cpu is sleeping. It wakes up -> executes interrupt
-> then executes the next instruction after the sleep
instruction. So Does this mean that it wont go back to
sleep again?
This is the code i wrote and the 8 bit timer produces
interrupts on every overflow. so i made a infinite
loop to keep sending the CPU back to sleep. If the
while(1) loop wasnt there then the cpu would have woke
up and stayed woken up . Is that correct?

Please advise if I have written the code to send the
MCU to sleep correctly. I saw a decrease in current
draw(not toooo much though). I have a feeling that
there must be a better way to do it.Thanks


SIGNAL(SIG_OVERFLOW0) //interrupt handler for the
overflow of the 8 bit timer
{
PORTB ^= 0x10;
}

int main(void)
{
DDRB = 0x10; //set pin OC1 PB4 as o/p to show waveform
using the interrupt
TCCR0 = 0x01; //set in normal mode.OC0 disconnected.
No prescalar (~64Khz).
ASSR = BV(AS0);//use external asynch clock of
32.768Khz

//now configure the timer interrupt control registers
TIMSK = BV(TOIE0); //enable timer overflow interrupt
sei();//enable the I bit in status register :Global
Interrupt Enable
//keep sending the cpu to sleep
while(1)
{
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}
return 0;
}

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html


reply via email to

[Prev in Thread] Current Thread [Next in Thread]