A current budget and battery life
Average current from states and durations, datasheet figures, measuring it, and what batteries really deliver.
Battery life is arithmetic
A battery-powered product's life is decided long before the firmware is written, by one number: the average current. Two AA alkaline cells hold about 2 500 mAh; at an average of 1 mA they last 2 500 hours, about 3.5 months; at 50 µA, five years. Everything in low-power design is about pulling that average down, and the way to do it is to see where it comes from.
A device's life is a cycle of states: asleep, waking, measuring, transmitting, back to sleep. Each draws its own current for its own time. The average is the charge of one cycle divided by its length:
I_avg = Σ (I_state × t_state) / T_cycle
| State | Current | Time per 15-minute cycle | Charge |
|---|---|---|---|
| Sleep (RTC running) | 2 µA | 899.6 s | 1 799 µA·s |
| Wake and measure | 3 mA | 50 ms | 150 µA·s |
| Radio transmit | 25 mA | 300 ms | 7 500 µA·s |
| Total | 900 s | 9 449 µA·s |
The average is 9 449 / 900 = 10.5 µA. Two things jump out, and they always do. The state that lasts 99.96 % of the time, sleep, contributes a fifth; the radio, on for a third of a second, contributes almost 80 %. Cutting the sleep current from 2 µA to 1 µA buys 10 %; sending half as often buys 40 %.
#include <stdio.h>
typedef struct { const char *name; double ua; double seconds; } phase_t;
int main(void) {
const phase_t cycle[] = {
{ "sleep", 2.0, 899.65 },
{ "measure", 3000, 0.05 },
{ "transmit", 25000, 0.30 },
};
double charge = 0, period = 0;
for (int i = 0; i < 3; i++) { charge += cycle[i].ua * cycle[i].seconds; period += cycle[i].seconds; }
double avg = charge / period;
printf("average: %.1f uA\n", avg);
for (int i = 0; i < 3; i++) printf(" %-8s %4.1f %% of the charge\n", cycle[i].name, 100 * cycle[i].ua * cycle[i].seconds / charge);
/* 2500 mAh, 80 % usable before the voltage is too low. */
printf("2 x AA: %.1f years\n", 2500.0 * 0.8 / (avg / 1000) / 24 / 365);
return 0;
}
Where the figures come from
Each state's current is a sum of what draws in it, and the datasheet tables give most of them:
- The core in Run mode, as base plus µA per MHz: an STM32F103 draws about 27 mA at 72 MHz with its peripherals off, an STM32G0 about 100 µA/MHz, an STM32L5 under 70 µA/MHz with its SMPS. The tables say which code ran (usually a loop from flash with the cache on): your code may differ by 10 to 30 %.
- Clocked peripherals: each timer, UART or ADC with its clock enabled draws a few µA per MHz even when idle. The F103's Run current goes from 27 to 36 mA with all of them on. Tables of "peripheral current consumption" list each one.
- Sleep modes, as fixed figures: Sleep (the core stopped, the clocks running), Stop (the clocks stopped, RAM kept, a few µA), Standby (RAM lost, wake by reset, about 1 µA), Shutdown.
- What the pins drive: an LED at 5 mA through a pin is more than the whole MCU in most states, and a pull-up held low by a closed switch draws V/R all the time (3.3 V through 10 kΩ: 330 µA).
- The rest of the board: the regulator's quiescent current (an AMS1117 draws 5 mA doing nothing; an MCP1700, 1.6 µA), a power LED (2 to 5 mA), a USB bridge (10 to 15 mA), sensors left powered, leakage through a voltage divider that measures the battery (1 MΩ total at 3 V: 3 µA, more than the MCU asleep).
The last item is where projects fail. An Arduino Uno draws about 45 mA whatever its sketch does, because of its USB bridge, regulators and power LED; its ATmega328P asleep draws a fraction of a microamp. A Nucleo board has an IDD jumper for this reason: take it off and an ammeter in its place measures the MCU alone.
Measuring it
Datasheet figures are a start; the board's real current is the answer. Three ways to measure, in rising order of usefulness:
- A multimeter in series reads the average of a slowly changing current. It cannot follow a 300 ms radio burst, and its shunt's burden voltage (a 10 Ω shunt drops 250 mV at 25 mA) can make the device brown out at exactly the moment you want to measure.
- A shunt and an oscilloscope: a small resistor in the supply, its voltage on a scope, shows the shape of each state. Use a differential probe or a current probe, and a shunt small enough not to disturb the device.
- A power analyser or a source-measure unit (Nordic's PPK2, Joulescope, Otii) logs the current over minutes with a range from nanoamps to amps, integrates the charge, and marks the states with a GPIO you toggle from firmware.
The simulator's Power tool is the first step of this: it estimates the chip's current from the state it is in, its clock, its clocked peripherals and what its pins drive, using the chip's datasheet figures, and draws the trace with the average, the time in each state and a battery's life. It is an estimate, labelled with where its figures come from; a real part differs by tens of percent. Use it to compare designs, then measure the board.
Batteries are not tanks of charge
The formula life = capacity / I_avg assumes the battery delivers its rated mAh whatever you draw. Real cells do not:
- Rated capacity is at a low current. An alkaline AA rated 2 500 mAh at 25 mA gives about 1 500 mAh at 500 mA. A CR2032 coin cell is rated 220 mAh at 0.2 mA; draw 15 mA pulses from it and its voltage collapses, and a buffer capacitor is needed to carry the radio bursts.
- The cut-off voltage decides the usable part. The device stops when the cell's voltage drops below what the regulator or the MCU needs: two alkaline cells from 3.2 V to perhaps 2.0 V, with 10 to 20 % of the charge still inside. Hence the 80 % in the estimates here.
- Self-discharge and temperature: an alkaline cell loses 2 to 3 % a year, a Li-SOCl₂ cell under 1 %; at −20 °C most chemistries give a fraction of their capacity.
For a five-year product, budget for the worst case: the lowest temperature, the end of the cell's life, the most frequent reporting a user can configure.
Going deeper
Interview question: How do you estimate the battery life of a device that sleeps most of the time and wakes periodically?
Answer: Build a current budget: list each state (sleep, wake-up, measurement, radio transmit and receive, any retries), the current in it from datasheets or measurement, and its duration per cycle. The average current is the sum of current times time divided by the cycle length. Battery life is the usable capacity divided by that average, with the capacity derated for the load current, the cut-off voltage at which the device stops working, self-discharge and temperature. Then check which state dominates the charge, usually the radio or a long wake-up rather than sleep, and measure the real board with a power analyser to confirm, including the regulator's quiescent current and any leakage paths such as dividers and pull-ups.
Interview question: Your board sleeps at 300 µA instead of the 2 µA the MCU's datasheet promises. Where do you look?
Answer: Measure the MCU alone first, through the board's IDD jumper or by lifting its supply, to split the problem. If the MCU draws it, check that every peripheral clock is off, that the debug interface is not keeping the core powered (a connected debugger often does), that unused pins are analog inputs or driven rather than floating inputs, and that the deep sleep mode really was entered. If the rest of the board draws it, check the regulator's quiescent current, LEDs, pull-ups held against a low line, battery-measurement dividers, sensors and radios left powered, and level shifters. Remove parts or cut tracks one at a time while measuring.
Explain it: In your own words, explain why the state that lasts longest is often not the one to optimise first.
Answer: The average current is each state's current times its duration, summed and divided by the cycle. A sleep state that lasts 99.9 % of the time at 2 µA adds about 2 µA; a radio burst that lasts 0.03 % of the time at 25 mA adds 7.5 µA. The burst's share is larger because its current is ten thousand times higher, so shortening it, sending less often or with less retrying, saves more than shaving the sleep current. Working out each state's share of the charge shows where the effort pays.