How to sleep an ATMega328p on less than 1µA with timer wakeup

How to configure an ATMega328p to consume lest than 1uA, while still retaining the ability to wake the processor up periodically via timer (or external interrupt).

last updated: May 27, 2024

atmega328p

Image courtesy of Microchip Inc.

Many MCU-based battery powered applications spend most of the time doing nothing productive. This is especially true for IoT applications like remote sensors, which periodically monitor a variable and react to it’s value, performing some local work or transmiting it elsewhere.

For these types of applications, the ability to expend very little energy during idle periods, while retaining the ability to wake-up when required, is critically important.

The front page of the ATMega328p datasheet advertises a current of 0.8µA in power-save mode at 1.8V with a 32 kHz RTC. We don’t expect hyperbole in datasheets and thankfully in this instance, our expectations are met :)

Steps to achieve the lowest power consumption

Configure a deep sleep mode

Since the device will spend most of its time sleeping, achieving the lowest power consumption during this time is crucial. AVRs have a number of different sleep modes with varying power consumption. For this application we are restricted to modes that will allow the device to wake up periodically without any user intervention.

Watchdog Wakeup 2V 3V 5V
Power-down off pin level 0.1µA 0.1µA 0.1µA
Power-down on watchdog 3.8µA 4.4µA 6.5µA
Power-save (32kHz crystal) off timer 2 0.6µA 0.6µA 0.7µA

Full power-down without the watchdog timer running is the lowest possible power mode for the MCU. The downside of choosing this mode is that there are no timers running at all, so it is necessary to use an external timer to trigger a pin interrupt and wake the MCU when required.

If the power budget was extra tight, I would choose this mode and use a Texas Instruments TPL5010 (35 nA @ 2.5V) to wake the device, giving a total draw of ~135 nA, or 338 nW @ 2.5V.

At that usage (ignoring the waking power consumption), a single 2500 mAh AA battery would theoretically last over 1200 years:

2.5 Ah * 1.5 / 338e-9 W / 24 / 365.25 = 1265.65 years

An external crystal allows us to wake without exernal components

Thankfully things aren’t quite that tight. That leaves using the watchdog timer in power-down mode or timer2 with an external crystal in power-save mode. Both provide for a maximum sleep duration of 8 seconds, but the crystal oscillator consumes significantly less power.

Another benefit of using the external crystal is that it will allow for much improved accuracy on the wake intervals when compared with the internal RC oscillator.

Note that this crystal doesn’t need to be usd for the main clock, only for timer2. The main clock can still run from the internal RC oscillator and so the oscillator startup delays associated with waking from sleep when using an external crystal can be avoided.

Source Frequency Start-up time*
External crystal 128kHz - 20MHz 258 - 32k CK
Internal calibrated RC oscillator 8MHz 6 CK
Internal oscillator 128kHz 6 CK
External clock 0 - 20MHz 6 CK

* From Power-down and Power-save modes (clock cycles)

Source: Atmel ATmega328/P Datasheet

The downside of using an external crystal is their finickiness. The below images are taken from the Microchip application note AN2648 - Selecting and Testing 32 KHz Crystal Oscillatorsfor Microchip AVR® Microcontroller:

Source: Microchip Inc.

These are some recommended mounting styles to avoid common issues related to parasitic capacitance and noise issues stemming from poor PCB layout. As pointed out in the note:

Ultra low-power 32 KHz oscillators typicallydissipate significantly below 1 μW, and the current flowing in the circuit is, therefore, extremely small. Inaddition, the crystal frequency is highly dependent on the capacitive load.

It’s a minor miracle that I was able to run the below test on a breadboard.

Disable the ADCs and comparator

At 3V @ 25°C, the ADC consumes ~87µA while the analog comparator uses ~51µA.

Disable the brown-out detector (BOD)

Brown-out detection monitors supply voltages for dips below a minimum threshold and resets the device if such dips are encountered. Running a microcontroller (MCU) at a supply voltage that is below the minimum specified, but above the threhold at which the chip won’t operate at all can be dangerous, as the controllers behavior is not predictable. In most circumstances, it is preferable for the controller to not operate at all than to operate with undefined behaviour.

If the worst case outcome of the MCU gone haywire in your application is acceptable - i.e. not going to damage property or people - then the BOD system can be disabled for greater power saving.

BOD can be completely disabled via the fuses, or can be disabled for sleep modes only via the MCU control register MCUCR (on Pico Power devices). We’ll be totally disabiling it.

At 25°C, the brown-out detector uses ~16uA @ 2V, 18uA @ 3V, and 21.5uA @ 5V.

Use this fuse calculator to determine the appropriate values, which helpfully also provides the AVRDUDE command line paramters.

Enable pull-ups on unused I/O pins

Configure unused I/O as input with pull-up enabled. They’ll be disabled in power-save mode, but pulling them up will prevent the possibility of them switching when running.

Use the most efficient frequency when running

Lower frequencies consume less power, but they may not result in a lower average power consumption in situations where the device is waking up periodically to perform a task. Although this wont affect the power consumption while sleeping, all applications need to do some work at some point.

The amount of energy consumed per wakeup will be equal to the power usage multiplied by the time taken. Since lower frequencies will result in the task taking a longer time to complete, we need to look at the energy used per cycle rather than the power consumption.

At 1.8V, power consumption increases a little less than 1:1, making higher frequencies slightly more efficient for tasks that require a fixed number of cycles:

Voltage Freq. Icc Energy per cycle
1.8 V 0.1 MHz 0.025 mA 0.45 nJ
1.8 V 0.5 MHz 0.125 mA 0.45 nJ
1.8 V 1.0 MHz 0.245 mA 0.44 nJ
1.8 V 4.0 MHz 0.850 mA 0.38 nJ
1.8 V 8.0 MHz 1.600 mA 0.36 nJ

Source: ATMega328p datasheet

Since 4.0 MHz is the maximum rated speed at 1.8V, 4 MHz at 1.8V is optimal, although 1-4 MHz is not too much worse.

Success: 1.35µW @ 1.8V

Measured current draw with wakeup via timer 2 using a 32KHz crystal

Measured current draw with wakeup via timer 2 using a 32KHz crystal

  • Note: The photographed multimeter’s accuracy is insuffient at thius level, but the results were verified with more precise tools.
Prev in section:
STM32 microcontroller cheat sheet…