So I'm trying to power down my ATtiny85 to save power, but for some reason the ATtiny doesn't power down when I'm using the default IDLE
mode, but when I start using the SLEEP_MODE_PWR_DOWN
the ATtiny appears to go to sleep.
I'm testing it by calling a checkPower()
method that blinks an LED after the sleepNow()
method. In other words, if the ATtiny goes to sleep then the checkPower()
method should not be reached and the LED should not blink. Here is the code:
void loop()
{
doStuff();
sleepNow();
checkPower();
}
void sleepNow()
{
// Choose our preferred sleep mode:
set_sleep_mode(SLEEP_MODE_IDLE);
// Set sleep enable (SE) bit:
sleep_enable();
// Put the device to sleep:
sleep_mode();
// Upon waking up, sketch continues from this point.
sleep_disable();
}
void checkArrays()
{
for(i = 0; i < 15; i++)
{
digitalWrite(1, HIGH);
delay(1000);
digitalWrite(1, LOW);
delay(1000);
}
}
Any idea why my LED would continue to blink when using the IDLE
mode but no the PWR_DOWN
mode?
1 Answer 1
In IDLE mode the timers still run. Arduino uses timer0 for millis. So when timer0 overflows the ATTiny will wake up and call the ISR.
So the ATTiny will go to 'sleep' but wake up a number of microseconds later.
-
So what can I use besides IDLE? If I try PWR_DOWN I won't be able to use an interrupt to wake the microprocessor. Is there an alternatice. Also how long does IDLE make the ATtiny sleep?Isabel Alphonse– Isabel Alphonse06/21/2016 17:44:11Commented Jun 21, 2016 at 17:44
-
1You can wake from power down using either a pin change interrupt or a watchdog timer interrupt.bigjosh– bigjosh06/21/2016 18:30:35Commented Jun 21, 2016 at 18:30
-
@IsabelAlphonse: IDLE is fine. You just have to check, whenever you wake up, if there is job to do. If not, just go back to sleep.Edgar Bonet– Edgar Bonet06/21/2016 19:29:34Commented Jun 21, 2016 at 19:29
-
As bigjosh said, pin change and watchdog timer interrupts will wake the processor from power-down. See my page about power - not specifically about the Attiny85, but the same processor family.06/21/2016 21:15:18Commented Jun 21, 2016 at 21:15