Battery-Driven-App w/Atmel Studio 7 & UNO Serie(Episode #05)
In the last post we used a pin change interrupt to detect whether a switch was pressed.
Now the main benefit of using interrupts as opposed to polling is that we’re not keeping the processor occupied just with one task but besides to be able to put the CPU down to low-power and reduce dramatically the power consumption of an application.
It’s particularly important for battery-driven app and the like.
Now low-power is really one of Atmel core’s technologies.
In this post we will apply one of this technology to put the processor in sleep mode!
Let’s get started!
Step#01→ Notice first of all in page one of the datasheet:
https://www.sparkfun.com/datasheets/Components/SMD/ATMega328.pdf
Low Power Consumption at 1 MHz, 1.8V, 25°C for ATmega48P/88P/168P:
— Active Mode: 0.3 mA
— Power-down Mode: 0.1 µA — Power-save Mode: 0.8 µA (Including 32 kHz RTC)
See the consumption of power-down mode is little as 100 nA (micro down to nano ampere! that’s awesome!) so let’s see if we can use power down mode, right?
Step#02→ Head over to page 75, PRR — Power Reduction Register.
This provides a way to stop the clock to individual peripherals to reduce power consumptions.
You turn off everything you’re not using.
So, to turn everything off put this on setup:
PRR =0xFF;Step#03→ Now using LibC on the top and Right before while method:
#include <avr/sleep.h>sei();
while(...)Step#04→ Set and call sleep mode:
(…)
PRR =0xFF;
set_sleep_mode();while(){
sleep_mode();//call it!

Step#05→ Add a parameter to this last method, like this:
set_sleep_mode( SLEEP_MODE_PWR_DOWN)The 6 different modes are (sleep.h):
- * SLEEP_MODE_IDLE — the least power saving
- * SLEEP_MODE_ADC
- * SLEEP_MODE_PWR_SAVE
- * SLEEP_MODE_STANDBY
- * SLEEP_MODE_EXT_STANDBY
- * SLEEP_MODE_PWR_DOWN — the most power savings
Step#06→ Load & Run the app by selecting, first hit F7 then Tool >Send to Arduino UNO and see if you have the same funcionality as before: when switch on Pin 8 was pressed the LED on Pin 7 are toggle.
But now in a much slower asleep. We are now really saving power!
Here is the complete code till now:
https://github.com/giljr/avr/tree/master/atmel
look for Episode #05.
Bye!
References & Credits
Follow along with the entire ‘Getting Started with AVR’ series: http://bit.ly/GettingStartedwithAVR
→Goto Episode#06
Complete Serie:
#00 HowTo-Load-Into-Arduino-AS7
#05_Battery-Driven-App
#08
#09
#10
