While I´m waiting to receive some switching regulators, I´ve been tinkering with sleep modes (Power Save Mode)
In my application I have a big delays (300 ms) and as Paul said, could be a big improvement....and looking the results, it´s clear!!
I´ve done a test that tonggle the diecimila led about 2 seconds. I´m using Timer2 (to wake up).
-Sleep Mode and turn off devices=> Led_on=12,98 mA & Led_off=9,91 mA
-No Sleep and turn off devices => Led_on=28,9 mA & Led_off=25,9 mA
-No Sleep => Led_on=32,2 mA & Led_off=29,2 mA
SLEEP MODE TEST CODE
Code:
#include <avr/interrupt.h>
#include <avr/sleep.h>
volatile int cont;
void setup()
{
pinMode(13,OUTPUT);
TCCR2A=0;
TCCR2B=(0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1)|(1<<0);
// Bit 0.- Overflow
TIMSK2=(0<<2)|(0<<1)|(1<<0);
//Power Save Mode
SMCR=(0<<3)|(1<<2)|(1<<1)|(0<<0);
}
ISR(TIMER2_OVF_vect)
{
cont++;
}
void loop()
{
sleep_enable();
//Turn off ADC
ADCSRA=0;
// TWI | TIMER2 | TIMER0 | VOID | TIMER1 | SPI | USART | ADC
PRR=(1<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);
sei();
while (cont<122)
{
//Go to Sleep
sleep_mode();
}
//Disable Sleep
sleep_disable();
//Disable interrupts
cli();
cont=0;
digitalWrite(13,!digitalRead(13));
}
#include <avr/sleep.h>
volatile int cont;
void setup()
{
pinMode(13,OUTPUT);
TCCR2A=0;
TCCR2B=(0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1)|(1<<0);
// Bit 0.- Overflow
TIMSK2=(0<<2)|(0<<1)|(1<<0);
//Power Save Mode
SMCR=(0<<3)|(1<<2)|(1<<1)|(0<<0);
}
ISR(TIMER2_OVF_vect)
{
cont++;
}
void loop()
{
sleep_enable();
//Turn off ADC
ADCSRA=0;
// TWI | TIMER2 | TIMER0 | VOID | TIMER1 | SPI | USART | ADC
PRR=(1<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);
sei();
while (cont<122)
{
//Go to Sleep
sleep_mode();
}
//Disable Sleep
sleep_disable();
//Disable interrupts
cli();
cont=0;
digitalWrite(13,!digitalRead(13));
}
NO SLEEP AND TURN OFF DEVICES
Code:
#include <avr/interrupt.h>
#include <avr/sleep.h>
volatile int cont;
void setup()
{
pinMode(13,OUTPUT);
TCCR2A=0;
TCCR2B=(0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1)|(1<<0);
// Bit 0.- Overflow
TIMSK2=(0<<2)|(0<<1)|(1<<0);
//Turn off ADC
ADCSRA=0;
// TWI | TIMER2 | TIMER0 | VOID | TIMER1 | SPI | USART | ADC
PRR=(1<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);
sei();
}
ISR(TIMER2_OVF_vect)
{
cont++;
if (cont<122)
{
cont=0;
digitalWrite(13,!digitalRead(13));
}
}
void loop()
{
}
#include <avr/sleep.h>
volatile int cont;
void setup()
{
pinMode(13,OUTPUT);
TCCR2A=0;
TCCR2B=(0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1)|(1<<0);
// Bit 0.- Overflow
TIMSK2=(0<<2)|(0<<1)|(1<<0);
//Turn off ADC
ADCSRA=0;
// TWI | TIMER2 | TIMER0 | VOID | TIMER1 | SPI | USART | ADC
PRR=(1<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);
sei();
}
ISR(TIMER2_OVF_vect)
{
cont++;
if (cont<122)
{
cont=0;
digitalWrite(13,!digitalRead(13));
}
}
void loop()
{
}
NO SLEEP
Code:
#include <avr/interrupt.h>
#include <avr/sleep.h>
volatile int cont;
void setup()
{
pinMode(13,OUTPUT);
TCCR2A=0;
TCCR2B=(0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1)|(1<<0);
// Bit 0.- Overflow
TIMSK2=(0<<2)|(0<<1)|(1<<0);
//Turn off ADC
//ADCSRA=0;
// TWI | TIMER2 | TIMER0 | VOID | TIMER1 | SPI | USART | ADC
//PRR=(1<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);
sei();
}
ISR(TIMER2_OVF_vect)
{
cont++;
if (cont==122)
{
cont=0;
digitalWrite(13,!digitalRead(13));
}
}
void loop()
{
}
#include <avr/sleep.h>
volatile int cont;
void setup()
{
pinMode(13,OUTPUT);
TCCR2A=0;
TCCR2B=(0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1)|(1<<0);
// Bit 0.- Overflow
TIMSK2=(0<<2)|(0<<1)|(1<<0);
//Turn off ADC
//ADCSRA=0;
// TWI | TIMER2 | TIMER0 | VOID | TIMER1 | SPI | USART | ADC
//PRR=(1<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);
sei();
}
ISR(TIMER2_OVF_vect)
{
cont++;
if (cont==122)
{
cont=0;
digitalWrite(13,!digitalRead(13));
}
}
void loop()
{
}
Regards,

Igor R.

