-
Notifications
You must be signed in to change notification settings - Fork 84
Description
In order to disable BOD during sleep (see Table 7-1 on page 33) the BODS bit must be written to
logic one. This is controlled by a timed sequence and the enable bit, BODSE in MCUCR. First,both BODS and BODSE must be set to one. Second, within four clock cycles, BODS must be
set to one and BODSE must be set to zero.
I think the current implementation violates the "4 clock cycle rule". OR ing the bits takes too much time. This results in an power down current consumption of ~27µA (BOD is active if not disabled by fuses).
I propose the following implementation of the sleep function.
void inline sleep() {
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
//MCUCR |= _BV(BODS) | _BV(BODSE); //disable brownout detection during sleep
//MCUCR &=~ _BV(BODSE);
uint8_t mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);
uint8_t mcucr2 = mcucr1 & ~_BV(BODSE);
MCUCR = mcucr1;
MCUCR = mcucr2;
sleep_cpu();
sleep_disable();
}
There might still be room for improvement (https://github.com/LowPowerLab/LowPower/blob/master/LowPower.cpp#L41) but this solution works for me.
Now my chirp consumes only 6µA instead of 27µA during power down.