Firmware Power Management
Low-power firmware is not only a sleep instruction. It is a design discipline: turn off work that is not needed, wake only for meaningful events, finish tasks quickly, and prove the current budget with measurements.
Learning Objectives
By the end of this lesson, you should be able to estimate average current, choose sleep modes, configure wake sources, shut down peripherals safely, and debug why a product draws more current than expected.
Power States
Most embedded products use several power states:
| State | Typical behavior |
|---|---|
| Active | CPU, clocks, peripherals, and radios may run |
| Idle | CPU paused, fast wake, selected peripherals active |
| Sleep | most clocks stopped, RAM retained, interrupt wake |
| Stop or standby | deep sleep, limited RAM or registers retained |
| Off | external load switch or regulator disabled |
The best state is the deepest one that still preserves required wake latency and data retention.
Average Current
Battery life depends on average current, not peak current alone.
$$
I_{avg} = \frac{\sum I_i t_i}{\sum t_i}
$$
If a node draws 18 mA for 20 ms and 12 uA for 9980 ms in a 10 s cycle:
$$
I_{avg} = \frac{18mA \times 0.02s + 12uA \times 9.98s}{10s} \approx 48uA
$$
Battery life estimate:
$$
Life\ hours \approx \frac{Capacity\ mAh \times usable\ factor}{I_{avg}\ mA}
$$
Use a conservative usable factor for temperature, aging, regulator loss, and battery cutoff voltage.
Firmware Controls
Common controls include clock prescalers, peripheral enable bits, GPIO state, sensor power switches, radio duty cycling, DMA instead of polling, and batching writes to flash.
Wake Sources
A wake source should be intentional and testable. Examples include RTC alarm, GPIO interrupt, watchdog, UART start bit, radio interrupt, comparator threshold, accelerometer motion, or external power restore.
Disable noisy or unused wake sources before sleeping. Clear pending interrupt flags before entering low power; otherwise the CPU may wake immediately.
GPIO and Peripheral Leakage
GPIO pins can dominate sleep current. Avoid leaving pins at mid-rail, back-powering unpowered sensors through signal pins, enabling pull resistors unnecessarily, or driving against an external circuit.
Before sleep, set every pin to a documented state: analog input, high impedance, pull-up, pull-down, driven low, driven high, or retained alternate function.
Worked Example: Sensor Node
A temperature logger wakes every minute. Firmware enables the sensor rail, waits 5 ms, starts I2C conversion, sleeps during conversion, reads the result, appends one record to RAM, writes flash every 32 records, then returns to stop mode. The radio only wakes once per hour.
This is better than keeping the sensor, I2C peripheral, flash, and radio ready all the time.
Common Mistakes
- Measuring current with a multimeter that misses short radio peaks.
- Forgetting debugger probes keep clocks or power domains active.
- Leaving UART, ADC, timers, or brownout options enabled unnecessarily.
- Letting an unpowered peripheral get back-powered through GPIO.
- Estimating battery life from ideal capacity at room temperature.
Practical Checks
Measure active, sleep, and transition currents. Verify wake latency. Log reset and wake reasons. Test with the debugger disconnected. Check every GPIO state in sleep. Confirm the watchdog still protects long active operations.
Summary
Low-power firmware is a state machine with evidence. Estimate average current, design explicit sleep states, configure wake sources carefully, shut down peripherals, and verify current with the real board.
Further Reading
- MCU vendor low-power application notes and reference manuals.
- Nordic, ST, Microchip, and TI guides on sleep current measurement.
- Memfault articles on firmware power optimization and field telemetry.