Struggeling to reduce power consumption's to a minimum

Hi. I'm trying to make my atmega328p use as little current as possible while in sleep mode. I don't need any functions at all while it's sleeping, I only need it to be able to wake up with an interrupt.

Right now I'm using the Power-down mode and at first the power consumption went down to about 790uA. I then turned off the ADC which brought it down to about 380uA, but this is still a far stretch from the TYP 0.1uA given in the datasheet. I'm supplying it with 5V, but I will supply it with 3V when my circuit is complete. I'm using a 16Mhz crystal and I know reducing voltage and clock speed will reduce power consumption, but I'm guessing that the clock speed isn't relevant during sleep mode as it is turned off, right?

Reading the datasheet I see that turning off, ADC, analog comparator, brown-out detector, internal voltage reference, watchdog timer and on-chip debug system will further reduce the power consumption. The analog comparator should not be operational in this sleep mode anyway, and I haven't enabled the internal voltage reference, so I don't think that's an issue either. If I understood correctly, the watchdog timer is disabled by default by the arduino bootload, right? I still tried to disable it, but it didn't have any effect on the current draw. I also tried disabling the born-out detection as this can draw quite a bit of current, but my code seems to have no effect:

MCUCR |= (1<<BODS) || (1<<BODSE);
  MCUCR |= (1<<BODS);
  MCUCR |= ~(1<<BODSE);
  sleep_mode();

This is what the datasheet says. Enable both BODS and BODSE, then enable BODS and disable BODSE, then enter sleep within four clock cycles. This has no effect on the power consumption.

I'm also a little unsure about the fuses in this thing. I think I know what they do, but can they be changed in the code like this? Or do I need a new bootloader to change the fuses? Why is my atmega328p drawing this much current? :frowning:

Nick Gammon has done quite concise article on power saving here

Thank you, I've seem to have reduced it to less than or around 1uA. Turning off the ADC by typing ADCSRA = 0; was the biggest change even though I thought writing PRADC: Power Reduction ADC to 1 in the PRR register was doing just that (it says "Writing a logic one to this bit shuts down the ADC" in the datasheet).

Another difference was typing "sleep_cpu();" instead of "sleep_mode();". Just typing sleep_mode() made it use 60uA more. I would like to know what the difference between the two are :frowning:

Plecto:
Another difference was typing "sleep_cpu();" instead of "sleep_mode();". Just typing sleep_mode() made it use 60uA more. I would like to know what the difference between the two are :frowning:

Definition of sleep_mode() in sleep.h:

#define sleep_mode() \
do {                 \
    sleep_enable();  \
    sleep_cpu();     \
    sleep_disable(); \
} while (0)

I think the line sleep_enable(); inside the sleep_mode() function resets the BODS bits and anything else that you may have set between your first call to sleep_enable() and the call to sleep_mode().

In the first line of the code in your first post, I believe you may have boolean and bitwise operators mixed up.

Also, MCUCR |= ~(1<<BODSE); may not be turning that bit off.

This may be better: MCUCR &= ~(1<<BODSE);

Seems you may have gotten it figured with the other posts related to sleep.h

The first time I tried to sleep (using power down) a 328p, it used 40x more power asleep than awake. Come to find out I didn't manage my pin states and hardware correctly prior to entering sleep and a serial device was sucking the battery dry when the mcu went to sleep.

Dave