Files
Arduino/Sleep_C/Sleep_C.ino
Jérôme Delacotte 7b30d6e298 first commit
2025-03-06 11:15:32 +01:00

33 lines
1.0 KiB
C++
Executable File

#include <avr/sleep.h>
//Brown-out disable
//Another power saving can be made by disabling the brown-out detection.
//To detect low voltages the processor must generate a voltage source for
//comparison purposes. You can change the "extended fuse" (efuse) by using AVRdude,
//like this:
//avrdude -c usbtiny -p m328p -U efuse:w:0x07:m
//
//In SLEEP_MODE_PWR_DOWN mode, with brown-out disabled, the power went down
//from 360 µA to 335 µA, a saving of 25 µA.
//
//Another way of turning off brown-out detection is to temporarily disable it like this:
void setup ()
{
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
noInterrupts (); // timed sequence follows
sleep_enable();
// turn off brown-out enable in software
MCUCR = bit (BODS) | bit (BODSE); // turn on brown-out enable select
MCUCR = bit (BODS); // this must be done within 4 clock cycles of above
interrupts (); // guarantees next instruction executed
sleep_cpu (); // sleep within 3 clock cycles of above
} // end of setup
void loop () { }