Power profiling and measurement
Measuring microamps to amps and finding where the energy goes.
You cannot optimise what you have not measured
Battery-powered products live or die by their average current, and the numbers that matter span six orders of magnitude: a microcontroller sleeping at 1 µA wakes for a millisecond at 5 mA, and a radio burst briefly draws 100 mA or more. Datasheet figures are a starting point; only measurement on the real board tells you what the product does.
Why a multimeter is not enough
A multimeter averages over a slow sampling window and has a fixed range. On a device that sleeps and wakes in bursts it shows a meaningless number, and its burden voltage (the voltage drop across its shunt) on the µA range can be large enough to make the device brown out when it wakes and draws milliamps. It is fine for checking a steady sleep current, nothing more.
Tools
| Tool | Range and speed | Use |
|---|---|---|
| Multimeter (µA range) | Steady currents | Quick check of the sleep floor |
| Shunt resistor + oscilloscope | Fast, but one range; measure across a small resistor in the supply | Seeing burst shapes and timing |
| Current probes (Hall-effect clamp) | Higher currents, poor at µA | Motors, power stages |
| Source-measure units / power analysers (Joulescope, Nordic Power Profiler Kit II, Qoitech Otii, Keysight N6705 with SMU modules) | nA to A with automatic fast range switching, high sample rates, integrated charge and energy | The standard tools for low-power work |
| On-board measurement (current-sense amplifier, coulomb counter, fuel gauge) | Product-level | Field telemetry, battery state of charge |
The specialised tools also act as the power supply, can emulate a battery (including its internal resistance), and often have digital inputs to correlate current with GPIO markers from the firmware.
What to measure
- Sleep floor. The current in the deepest sleep state. If it is several times the datasheet value, something is still on: find it before anything else, because it usually dominates battery life.
- Each active event's charge (in µC or µAh): the area under the current curve for a sensor reading, a radio transmission, a wake-up. Optimise the biggest ones.
- The full-cycle average over a representative period (including rare events like daily synchronisation), which is what the battery sees.
- Peak current, to check that the battery and regulator can deliver it without the supply sagging.
#include <stdio.h>
int main(void) {
/* Integrating a captured current trace (µA samples every 100 µs) into charge and average current. */
double samples_ua[] = { 2, 2, 2, 850, 4200, 4300, 9800, 11000, 10500, 3100, 900, 2, 2, 2, 2, 2 };
int n = sizeof samples_ua / sizeof samples_ua[0];
double dt_s = 100e-6;
double charge_uc = 0, peak = 0;
for (int i = 0; i < n; i++) {
charge_uc += samples_ua[i] * dt_s; /* µA × s = µC */
if (samples_ua[i] > peak) peak = samples_ua[i];
}
double window_s = n * dt_s;
printf("window %.1f ms, charge %.2f uC, average %.0f uA, peak %.1f mA\n",
window_s * 1000, charge_uc, charge_uc / window_s, peak / 1000);
/* If this burst happens once a minute and the device sleeps at 2 µA otherwise: */
double per_min_avg = (charge_uc + 2.0 * (60.0 - window_s)) / 60.0;
printf("once a minute: average %.2f uA\n", per_min_avg);
return 0;
}
Correlating current with code
The most useful technique: toggle a spare GPIO at the start and end of each firmware phase (sensor read, processing, radio) and capture it alongside the current trace. You can then attribute every bump in the current to a line of code, and see things like a peripheral left on after its phase ends.
Software estimation
Before hardware exists, or to monitor in the field:
- Power budget spreadsheet from datasheet values and duty cycles (see low-power design).
- Energy-aware profiling tools in vendor IDEs (Simplicity Studio Energy Profiler, STM32CubeMonitor-Power) that combine measured current with program counter sampling.
- State-time accounting in firmware: keep counters of how long the device spent in each state (radio on, CPU active, sleep) and multiply by calibrated currents to estimate consumption, and report it in telemetry. Cheap and surprisingly accurate once calibrated against a bench measurement.
Measurement hygiene
- Disconnect the debugger (and its power and SWD lines). A connected probe keeps debug clocks and power domains alive and can add milliamps.
- Remove or isolate LEDs, USB-serial chips and development-board extras that draw current; measure on the product hardware, or cut the jumper that isolates the MCU supply.
- Power-cycle after flashing: some debug state persists until a power-on reset.
- Measure at temperature extremes: leakage roughly doubles every 10 °C, so sleep current at 60 °C can be several times the room-temperature figure.
- Measure many units: part-to-part variation and assembly faults (a leaky capacitor) show up in some boards only.
- Keep the measurement instrument's burden in mind: use a tool with low burden or one that regulates its output.
Pitfall: Measuring sleep current a few seconds after boot can mislead: many devices finish start-up work, radio calibration or flash writes over the first minute. Capture long enough to see the true steady state, and the periodic events within it.
Interview question: How would you find out why a device's battery life is half the estimate?
Answer: Measure with a proper profiler (Joulescope, PPK2, Otii) on production hardware with the debugger disconnected, over a long enough window to include all periodic events. Compare the sleep floor with the datasheet; if high, find what is still powered by disabling peripherals and checking pin states. Then measure the charge of each active event with GPIO markers to attribute it to code, and compare event frequency with the design (unexpected retries, radio reconnects, long timeouts). Check at the real operating temperature and with the real battery, whose capacity falls at high pulse currents and low temperatures.
Interview question: How can firmware estimate its own energy use in the field?
Answer: Keep time counters for each power state (CPU active, each sleep mode, radio transmit and receive, sensors on), accumulated with a low-power timer on every state change. Multiply each by a current calibrated on the bench for that state to get charge used, and report it periodically. Combined with a fuel gauge or battery-voltage readings, it reveals units consuming more than expected and which state is responsible, without any measurement hardware in the field.
Build it: will the battery last a week?
This is step 3 of the module project. The product promise is 7 days on one charge with a 40 mAh battery. The optical heart-rate sensor flashes an LED for every sample, and a faster sampling rate gives better readings but drains the battery faster. Measure, calculate, then choose.
Lab: Average current, battery life and the fastest safe sampling rate
A current profile is a list of phases, each with a current in microamps and a duration in microseconds, repeated forever. The power analyser measured the watch for one second:
| Phase | Current | Time each second |
|---|---|---|
| asleep | 3 µA | the rest of the second |
| one heart-rate sample (LED + ADC) | 2000 µA | 1 ms per sample |
| Bluetooth update | 8000 µA | 5 ms |
avg_current_ua(p, n)returns the time-weighted average current,sum(I * t) / sum(t), rounded down. Use 64-bit arithmetic for the products.battery_hours(capacity_mah, avg_ua)returns the hours the battery lasts, rounded down. Only 80 % of the rated capacity is usable (cold, ageing, the cut-off voltage): hours =capacity_mah * 1000 * 80 / 100 / avg_ua.best_rate(capacity_mah, hours_needed)tries the sampling rates inRATES(25, 50, 100, 200 Hz) and returns the highest rate whose battery life is at leasthours_needed, or 0 if none is. Build each rate's one-second profile with the providedbuild_profile.
Going deeper
Interview question: How would you prove a wireless earbud reaches its claimed battery life?
Answer: Measure current over a realistic usage profile with a power analyser that captures both microamp sleep and milliamp radio peaks, integrate it to an average, and compare with the battery's usable capacity across temperature and age. Profile each feature to find the biggest consumers, and repeat on every firmware release to catch regressions.
Interview question: How do you measure the energy of one event, such as a radio transmission?
Answer: Capture the current trace with a profiler at a high sample rate, use a GPIO marker or the trace's shape to find the start and end of the event, and integrate current over that interval to get charge (µC or µAh), multiplying by supply voltage for energy. Subtract the baseline sleep current. Repeat over many events and use the average and worst case in the power budget.
Interview question: Why should sleep current be measured over a long window?
Answer: Devices have periodic background activity: RTC wake-ups, radio keep-alives, sensor sampling, watchdog refreshes, logging. A short capture may fall between them and show an unrealistically low floor. Measuring for a full cycle of all periodic events, minutes or longer, captures the true average the battery sees.
Explain it: In your own words, explain why a multimeter is a poor tool for measuring a battery device's consumption.
Answer: Battery devices spend most of their time asleep at microamps and wake briefly at milliamps, changing within microseconds. A multimeter averages slowly over a fixed range, so it shows a meaningless number for such a waveform, misses short bursts or cannot follow them. On its microamp range its shunt drops enough voltage at milliamp currents to make the device brown out when it wakes. Dedicated profilers sample quickly with automatic range switching and integrate charge, showing both the sleep floor and each burst.