I'm having some bother putting my Atmega328P-PU to sleep into the microAmp ranges...
I've been all over Nick Gammon's thread on his site here:- https://www.gammon.com.au/forum/?id=11497 following as many of the steps as possible but I can't get my Atmega to draw any less than 1.4mA when put to sleep.
I am using this sketch as my benchmark / baseline to test the Atmega (also from Nick Gammon's Site):-
//LOW POWER BASE LINE TEST SKETCH H FROM NICK GAMMON FORUMS - https://www.gammon.com.au/forum/?id=11497
#include <avr/sleep.h>
#include <avr/wdt.h>
const byte LED = 9;
void flash ()
{
pinMode (LED, OUTPUT);
for (byte i = 0; i < 10; i++)
{
digitalWrite (LED, HIGH);
delay (50);
digitalWrite (LED, LOW);
delay (50);
}
pinMode (LED, INPUT);
} // end of flash
// watchdog interrupt
ISR (WDT_vect)
{
wdt_disable(); // disable watchdog
} // end of WDT_vect
void setup () { }
void loop ()
{
flash ();
// disable ADC
ADCSRA = 0;
// clear various "reset" flags
MCUSR = 0;
// allow changes, disable reset
WDTCSR = bit (WDCE) | bit (WDE);
// set interrupt mode and an interval
WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0); // set WDIE, and 8 seconds delay
wdt_reset(); // pat the dog
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);
MCUCR = bit (BODS);
interrupts (); // guarantees next instruction executed
sleep_cpu ();
// cancel sleep as a precaution
sleep_disable();
} // end of loop
My Atmega is set up on a breadboard running at 3V3 @ 8Mhz INTERNAL with nothing connected to it other than VCC and GND which is supplied by the 3V3 and GND pins from a NANO. My DMM is in series with the 3V3 wire coming from the NANO to the Atmega. I don't have the LED connected as shown in the Arduino Sketch.
When I run Nick's Sketch, I can see that the Atmega is doing something along the lines of going to sleep because I can see the meter periodically jumping up and then back down as expected but the current consumption isn't what I'd expected.
When the Atmega comes out of Sleep, my DMM shows around 5.5mA and when the Atmega goes to sleep again, it drops to 1.5mA. Not the microAmp ranges I'd hoped for.
Now you can't get a simpler circuit setup than I've got on breadboard and you can't get a more simple sketch to test with so I'm at a loss as to why my Atmega won't do what I think it's meant to do.
The only thing left really is fuses. And until now, fuses are a subject I've happily avoided having to deal with. I tend to use the board files inside of the Arduino IDE so that could be where the issue is, I don't know.
What I can tell you is that I struggled to find a board file for Atmega328 at 3V3 @ 8Mhz Internal Oscillator. Eventually I found a board file but it took a lot of faffing about to install it in the modern Arduino IDE for it to find so I could burn it to the chip. So maybe I've done something wrong there?
I couldn't find much up to date information on telling an Atmega to run at those speeds and voltages so I went with what I could.
This is the BOARDS.TXT File I have been using to program my Atmegas and I've had to put it into folders in my Arduino projects folder like so: Libraries/Documents/Arduino/Hardware/Breadboard/AVR/Boards.TXT
##############################################################
atmega328bb.name=ATmega328P-PU (8 MHz internal clock)
atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600
atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F
atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard
atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdude
Any help appreciated!
Thx!