Low-power design techniques
Battery budgets, duty cycling, sleep modes and wake sources.
Battery life is an average
A battery-powered device's lifetime is its battery capacity divided by its average current. The device might draw 10 mA while its radio transmits, but if it does that for 20 ms every minute and sleeps at 2 µA otherwise, the average is a few microamps and a coin cell lasts years. Low-power design is the craft of keeping the device in its lowest state for as much of the time as possible, and making the active bursts short.
The power budget
List every state, its current and how long the device spends in it per cycle:
#include <stdio.h>
typedef struct { const char *state; double ma; double ms_per_cycle; } phase_t;
int main(void) {
/* A sensor that wakes every 60 s, measures, and transmits over BLE. */
phase_t p[] = {
{ "sleep (RTC running)", 0.0025, 59600 },
{ "wake + sensor read", 1.5, 200 },
{ "BLE advertise burst", 6.0, 10 },
{ "processing", 3.0, 190 },
};
double cycle_ms = 0, charge = 0;
for (int i = 0; i < 4; i++) { cycle_ms += p[i].ms_per_cycle; charge += p[i].ma * p[i].ms_per_cycle; }
double avg_ua = charge / cycle_ms * 1000;
printf("average current: %.1f uA\n", avg_ua);
for (int i = 0; i < 4; i++)
printf(" %-22s %5.1f%% of the charge\n", p[i].state, 100 * p[i].ma * p[i].ms_per_cycle / charge);
double capacity_mah = 220 * 0.8; /* CR2032, derated for temperature and pulse load */
printf("CR2032 life: about %.0f days\n", capacity_mah / (avg_ua / 1000) / 24);
return 0;
}
The breakdown shows where to work: here the 190 ms of processing costs more than the radio. Optimise the biggest slice first.
Derate the battery: capacity falls at low temperature and with high pulse currents (a coin cell cannot deliver 10 mA without its voltage sagging, which is why designs add a large capacitor), and self-discharge takes a few percent a year.
Techniques
Duty cycling
Wake, do the work as fast as possible, sleep. Run at a higher clock to finish sooner ("race to sleep") unless the work waits on something slow anyway. Batch work: one radio transmission with ten readings costs much less than ten transmissions, because every transmission has a fixed overhead (radio start-up, connection, protocol).
Use the deepest sleep mode you can
| Mode | What stays on | Typical current | Wake time |
|---|---|---|---|
| Sleep | Peripherals, RAM | Hundreds of µA | µs |
| Stop / deep sleep | RAM, RTC, wake logic | 1 to 10 µA | µs to tens of µs |
| Standby / shutdown | RTC, backup registers | 0.1 to 1 µA | Like a reset: ms |
Deeper modes cost wake-up time and energy, and lose state. If the device wakes every 10 ms, the wake-up overhead of standby may outweigh its savings.
Turn off what you are not using
- Peripheral clocks off when the peripheral is idle.
- External sensors on a switched rail (a load switch or a GPIO powering a low-current sensor) instead of their own sleep mode, if their sleep current is high.
- Resistor dividers and pull-ups that conduct continuously: switch them, or use larger values.
- Debug features: a connected debugger or enabled debug-in-sleep keeps clocks running and can add milliamps.
Pins
Floating inputs waste current (the input buffer sits mid-rail) and pick up noise. Before sleeping, configure every unused pin as analog, and every used pin in its lowest-current state. A pin driving high into an external pull-down wastes current continuously.
Let hardware do the waiting
- Use timers, RTC alarms and pin interrupts to wake, not busy loops.
- Let DMA and peripherals collect data while the core sleeps (an ADC triggered by a low-power timer, a UART with wake-up on address match).
- Use sensors with built-in FIFOs and thresholds: an accelerometer that interrupts on motion lets the MCU sleep until something happens.
Radios dominate
Radios draw milliamps when on. Reduce on-time: fewer, larger messages; lower data rates only if they do not lengthen transmissions too much; longer connection intervals in BLE; power-save modes in Wi-Fi and cellular (PSM, eDRX).
Measuring
Current ranges from sub-microamp to hundreds of milliamps within milliseconds, which a multimeter cannot follow. Use a dedicated tool (Nordic Power Profiler Kit, Joulescope, Otii) or a shunt with a scope, and measure:
- the sleep floor, which must match the datasheet; if it is ten times higher, something is still on
- the energy of each active burst, to see what each optimisation buys
- the average over a full cycle, which is what the battery sees
Pitfall: Sleep current measured with the debugger attached is meaningless. Disconnect the probe, or at least its power and SWD lines, and power-cycle before measuring.
Interview question: A battery device's sleep current measures 300 µA instead of the 3 µA in the datasheet. How do you find the cause?
Answer: Remove the debugger and power-cycle, since debug connections keep clocks alive. Then check the MCU actually enters the intended mode (pending interrupts or a running SysTick can prevent stop mode). Check every pin: floating inputs, outputs driving into pull resistors, peripherals left enabled. Then the board: external sensors not powered down, dividers and pull-ups conducting, a regulator with high quiescent current, LEDs. Bisect by removing or disabling components one at a time while watching a current profiler.
Interview question: How would you estimate the battery life of a new IoT sensor before building it?
Answer: Build a power budget: list each state (deep sleep, wake-up, sensor measurement, processing, radio transmission and reception) with its current from datasheets and its duration and frequency per day, compute the charge per day and the average current. Divide the derated battery capacity (accounting for temperature, pulse-load capability, self-discharge and cut-off voltage) by that average. Then validate early with a prototype on a current profiler, because radio and wake-up overheads are usually larger than datasheets suggest.
Build it: sleep as deeply as each gap allows
This is step 1 of the module project, a wireless door and window sensor for an alarm system, running ten years on one CR2032 coin cell. It wakes when the door's reed switch changes, sends a heartbeat every minute so the alarm panel knows it is alive, and sleeps the rest of the time. Before each sleep it knows how long the gap is, and picks the mode that costs the least charge over that gap, wake-up included.
Lab: Pick the sleep mode, and program the RTC wake-up
sleep_pick(gap_us, need_ram)returns the index inMODESof the mode to use for an idle gap ofgap_usmicroseconds. The charge a mode costs over the gap iscurrent_na × gap_us + wake_cost(in nA·µs; use 64 bits). A mode can be used only if itswake_usfits in the gap (or the sensor would wake late), and, whenneed_ramis set, only if it keeps RAM (standby loses it, and with it any data not yet sent). Pick the lowest charge; at equal charge the shallower mode, the one earlier in the table. If nothing fits, useMODE_RUN(stay awake).rtc_wakeup(seconds, ms, w)sets up the RTC wake-up timer, clocked by a 32 768 Hz crystal through a divider of 2, 4, 8 or 16 (w->div), countingw->reload + 1ticks of it. Use the smallest divider whose reload fits in 16 bits, for the best resolution, withreload = ticks − 1andticks = ms × 32768 / (div × 1000), rounded to the nearest. Periods too long for divider 16 use the RTC's seconds counter instead: thendivis 0 andreload = seconds − 1, withmsrounded to the nearest second when it was given. Whenmsis 0, the period isseconds. Return 0, or -1 when even the seconds counter cannot reach (more than 65 536 s, or 0).
Going deeper
Interview question: How would you get a smart water meter to last 15 years on one battery?
Answer: Make the deepest sleep the normal state, wake only on a timer or the flow sensor's pulses (counted by a low-power peripheral), keep each wake-up short, and send data rarely and in batches. Measure the whole current profile, budget every activity, and allow for battery self-discharge, temperature and ageing.
Interview question: Why is waking up often the most expensive part of a low-power cycle?
Answer: Waking from deep sleep means restarting oscillators and waiting for them to stabilise, possibly restoring clocks and peripherals, and for radios recalibrating and reconnecting, during which current is high but no useful work is done. For short frequent wake-ups this overhead dominates. Reduce it by using the shallowest mode that still meets the budget, waking less often and batching work, starting from fast internal oscillators, and keeping state in retained RAM.
Interview question: How does peripheral clock gating save power?
Answer: Every enabled peripheral clock toggles flip-flops and consumes dynamic power even when the peripheral is idle. Disabling the clock to unused peripherals in the clock controller (RCC on STM32) removes that consumption; many MCUs also offer separate low-power clock enable bits for each sleep mode. Enable a peripheral's clock only while it is in use.
Explain it: In your own words, explain how to estimate a device's battery life.
Answer: List each state the device goes through, such as deep sleep, waking, measuring, processing and transmitting, with the current in each and how long and how often it occurs. Multiply current by time for each to get the charge per cycle, add them, and divide by the cycle length to get the average current. Divide the battery's usable capacity, reduced for temperature, high pulse currents, self-discharge and the cut-off voltage, by that average to get the lifetime. Then measure the real device, because overheads are usually larger than the datasheets suggest.