Hi - I have an ATMEGA168PV that I would like to put in to power save mode quite frequently. I'm using AVR Studio 5.0 and using AVR GCC.
The idea is to have the timer2 interrupt periodically wake up the sleeping AVR and then put the AVR back into power save mode. It will just repeat in this loop for quite some time.
So, at the end of my timer2 interrupt handler, I have this code:
SMCR = (1<<SM1) | (1<<SM0) | (1<<SE); sleep_cpu();
Which I believe will put the AVR into power save mode.
Is that all I have to do?
I think that after it executes this code, the AVR will go to sleep, wait for the timer2 interrupt to fire, and then start from the beginning of the timer2 interrupt handler. But this line sort of sketches me out:
If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The MCU
is then halted for four cycles in addition to the start-up time, executes the interrupt routine, and
resumes execution from the instruction following SLEEP
So the way I read that is that it won't really affect me at all since I will be sleeping before exiting the interrupt routine. However, once I'm ready to stop sleeping (which will happen), I finally will exit the timer2 interrupt routine (instead of sleeping before I exit), and then, judging from the quote above, I'll jump right back into the interrupt routine (starting just below the sleep_cpu(); line)
Does this make sense?