Tuesday, December 30, 2008

AVR in sleep mode. (power saving mode)

I used AVR tiny13 for small applications very often, and mostly it is powered by only small battery. It is easy to put the AVR MCU to power save mode with avrlib, just few lines of code would do. To wake up the AVR MCU, you should setup interrupt before falling into sleep mode, either pin change interrupt or external INT0.

Here is my sample code (waked up by pin change interrupt)

//do nothing in interrupt func.

//main code:

//setup interrupt
GIMSK |= 1<< PCIE;
PCMSK |= 1<< PCINT0;

on_bulb(); //turn on light bulb

while(1) {
b1_low; //turn off
sei(); //enable interrupt
set_sleep_mode(SLEEP_MODE_PWR_DOWN); //set sleep mode
sleep_mode(); //sleep now
//wake up point here //

while (PINB & 0x1) { //if PINB is high


I only measured once I finished the demo circuit, and it should use around 10 times less power when AVR is in sleep mode. Have fun.

No comments: