UNIT 14 · LESSON 2 OF 6

Measuring Power and Energy

Is the meter wrong, is the datasheet wrong, or is something on the board awake that nobody asked to be?

INTERACTIVEAverage current decides battery life
A duty-cycled current profile, the charge of each phase and the resulting battery lifeone period (time not to scale)awakeradioasleep 60 ssleep600 µC 67%awake100 µC 11%radio200 µC 22%Iavg = Σ(I·t) / T = 900 µC / 60 s = 15 µA1000 mAh / 15 µA ≈ 66 689 h ≈ 7.61 years (ideal; real cells deliver less)The sleep phase uses the most charge (66.7 %): that is the one to reduce first.
A duty-cycled current profile, the charge of each phase and the resulting battery lifeone period (time not to scale)awakeradioasleep 60 ssleep600 µC 67%awake100 µC 11%radio200 µC 22%Iavg = Σ(I·t) / T = 900 µC / 60 s = 15 µA1000 mAh / 15 µA ≈ 66 689 h ≈ 7.61 years (ideal;real cells deliver less)The sleep phase uses the most charge (66.7 %): thatis the one to reduce first.

Try this

Wake up every
Awake time per wake-up (5 mA)
Average 15 µA: 7.61 years from 1000 mAh (ideal). Largest share: sleep.

A battery-powered device spends most of its life asleep and wakes briefly to measure and transmit. What drains the battery is the charge per period, the sum of current × time for each phase, divided by the period: the average current. The bars show each phase’s share of that charge. Currents and the 1000 mAh capacity are illustrative, and the life shown ignores self-discharge, temperature and the cut-off voltage, all of which shorten it.

What you will be able to do
  • Distinguish power, energy and charge, and convert a battery’s mAh rating to coulombs and, with a voltage, to energy.
  • Compute the average current of a duty-cycled profile as Σ(I·t)/T and estimate battery life from it, stating what the estimate ignores.
  • Choose a shunt resistor from the burden voltage it may drop and the smallest voltage the instrument can resolve, and explain why one shunt rarely covers both sleep and active currents.
  • Explain how a meter’s averaging and burden voltage can distort a measurement of a pulsed load.
  • Track down unexpected sleep current by measuring one phase at a time and eliminating suspects.
Before you start
  • Current, voltage, Ohm’s law and pull-up currents (unit 1, lessons 1 and 3).
  • Sleep states and what they switch off (lesson 1).
Steps in this lesson
  1. Power, energy and charge
  2. Average current from a profile
  3. Measuring the current
  4. Finding the current nobody meant to draw
  5. Worked example: where does the charge go?
  6. Common misconceptions

The puzzle

The datasheet promises a sleep current of a few microamps. Your meter, in series with the board, reads 400 µA, and the battery that should last years is flat in months. Is the meter wrong, is the datasheet wrong, or is something on the board awake that nobody asked to be? Before you can reduce power you have to measure it, and measuring a current that swings from microamps to tens of milliamps a thousand times a day is harder than it looks.

STEP 1

Power, energy and charge

Three quantities get mixed up. Power is the rate of using energy, P=V×IP = V \times I, in watts. Energy is power over time, E=∫P dtE = \int P\,dt, in joules or watt-hours. Charge is current over time, Q=∫I dtQ = \int I\,dt, in coulombs, and it is what a battery’s capacity rating counts: one milliamp-hour is 10−3 A×3600 s=3.610^{-3}\ \text{A} \times 3600\ \text{s} = 3.6 C. A 1000 mAh cell holds 3600 C; its energy depends on the voltage at which that charge is delivered, roughly capacity times nominal voltage.

For a device fed from a regulator whose input current tracks its output current, charge is the natural bookkeeping unit, and battery life is simply capacity divided by the average current.

STEP 2

Average current from a profile

A battery-powered device spends almost all of its time in one state and briefly visits others. Over one repeating period TT, each phase kk draws a current IkI_k for a time tkt_k, and the average is

Iavg=∑kIk tkT,I_{\text{avg}} = \frac{\sum_k I_k\, t_k}{T}, tlife≈CbatteryIavgt_{\text{life}} \approx \frac{C_{\text{battery}}}{I_{\text{avg}}}

The numerator is the charge per period. Written this way it shows which phase to attack: the one with the largest IktkI_k t_k, which is often the long, quiet sleep rather than the dramatic radio burst.

↑ This step uses the figure at the top of the page.

The life estimate is an upper bound. The charge a cell delivers depends on the current drawn and the temperature, the device stops when the voltage falls below what its regulator needs rather than when the cell is empty, and cells lose charge on the shelf. The datasheet of the cell gives those effects; the formula tells you where the device’s own charge goes.

STEP 3

Measuring the current

The standard method puts a small shunt resistor in the supply line and measures the voltage across it: I=Vshunt/RI = V_{\text{shunt}} / R. An ammeter does the same internally, so everything below applies to it too. Two limits pull the resistor in opposite directions. The sleep current must produce a voltage the instrument can resolve, so RR must be large enough; the active current must not drop so much voltage (the burden voltage) that the device misbehaves, so RR must be small enough:

R≥VfloorIsleep,R \ge \frac{V_{\text{floor}}}{I_{\text{sleep}}}, R≤ΔVallowedIactive⇒IactiveIsleep≤ΔVallowedVfloorR \le \frac{\Delta V_{\text{allowed}}}{I_{\text{active}}} \quad\Rightarrow\quad \frac{I_{\text{active}}}{I_{\text{sleep}}} \le \frac{\Delta V_{\text{allowed}}}{V_{\text{floor}}}

A device that sleeps at 10 µA and transmits at 50 mA spans a ratio of 5000; many span far more.

INTERACTIVEOne shunt resistor for microamps and milliamps
The range of shunt resistances that read the sleep current without starving the active deviceshunt resistance (log scale)0.1 Ω1 Ω10 Ω100 Ω1 kΩsleep: 10 µA × 5.5 Ω = 55 µV (needs ≥ 50 µV, so R ≥ 5 Ω)active: 50 mA × 5.5 Ω = 275 mV; the device sees 3.02 V (needs ≥ 3.0 V, so R ≤ 6 Ω)This resistor reads both states within the limits.
The range of shunt resistances that read the sleep current without starving the active deviceshunt resistance (log scale)0.1 Ω1 Ω10 Ω100 Ω1 kΩsleep: 10 µA × 5.5 Ω = 55 µV (needs ≥ 50 µV, so R ≥5 Ω)active: 50 mA × 5.5 Ω = 275 mV; the device sees 3.02V (needs ≥ 3.0 V, so R ≤ 6 Ω)This resistor reads both states within the limits.
Sleep current
Active current
Usable shunts 5 Ω to 6 Ω; 5.5 Ω works.

The simplest current measurement puts a small resistor in the supply line and measures the voltage across it. The same resistor must give a readable voltage at a few microamps in sleep and must not drop so much voltage at tens of milliamps that the device browns out. The instrument floor (50 µV) and the allowed drop (3.3 V down to 3.0 V) are illustrative. When no resistor satisfies both, use range switching, two measurements, or an instrument built for the job.

Dedicated current-shunt monitors make the arithmetic concrete. Linux’s driver for the INA226 converts its signed 16-bit shunt-voltage register at 400 counts per millivolt, so one count is 2.5 µV and the register tops out at 32 767 × 2.5 µV ≈ 81.9 mV. That is a resolution, not an accuracy: offset and noise, which the chip’s datasheet specifies, are larger than one count. Tools built for profiling low-power devices switch ranges automatically or use several shunts; with ordinary instruments the practical answer is to measure the sleep and active phases separately.

Averaging is the other trap. A handheld meter typically updates a few times a second and produces some kind of average over its sampling window; a 10 ms, 20 mA burst once a minute may be missed entirely, or smeared in a way that depends on the meter. To see a pulsed profile, put an oscilloscope across the shunt (with a differential probe or a current probe), mark the firmware phases with a GPIO toggle as in unit 6, and integrate the current over a period to get the charge.

STEP 4

Finding the current nobody meant to draw

When sleep current is too high, measure it with the firmware held in its sleep state (a test build that sleeps and never wakes), then eliminate suspects one at a time:

  • Pull-ups and pull-downs held against their input. A 10 kΩ pull-up with the switch closed draws 330 µA (unit 1, lesson 3); an internal pull-up held low costs tens of microamps (unit 7, lesson 3).
  • Floating inputs. A CMOS input left between the logic levels has both input transistors partly on and draws current (unit 7, lesson 3).
  • Outputs driving loads. An LED, a sensor’s supply pin or a pin driving against an external pull stays on in Sleep and Stop, where the STM32F4 keeps every pin in its run-mode state.
  • Clocks and blocks left on. On the RP2040, the CLOCKS_ENABLED0/1 registers report the state of each clock enable; on the STM32F4 the flash can be powered down during Stop with HAL_PWREx_EnableFlashPowerDown().
  • Other chips. Regulators, sensors and radios on the same rail have their own quiescent currents, often larger than the microcontroller’s.

STEP 5

Worked example: where does the charge go?

A node sleeps at 10 µA, wakes every 60 s to measure for 20 ms at 5 mA, and sends a 10 ms radio burst at 20 mA (illustrative numbers, the figure’s defaults). Per period:

phasecurrenttimecharge
sleep10 µA59.97 s599.7 µC
measure5 mA20 ms100 µC
radio20 mA10 ms200 µC
total60 s899.7 µC
Iavg=899.7 μC60 s≈15.0 μA,I_{\text{avg}} = \frac{899.7\ \mu\text{C}}{60\ \text{s}} \approx 15.0\ \mu\text{A}, tlife≈1000 mAh0.015 mA≈66 700 h≈7.6 yearst_{\text{life}} \approx \frac{1000\ \text{mAh}}{0.015\ \text{mA}} \approx 66\,700\ \text{h} \approx 7.6\ \text{years}

This ignores the battery’s self-discharge and the loss of capacity at pulse loads; over years, self-discharge (expressed as an equivalent current, it can match or exceed 15 µA for some chemistries) decides whether 7.6 years is achievable at all. Sleep takes two-thirds of the charge even though it draws 2000 times less current than the radio. Now suppose the board really sleeps at the 400 µA from the opening: sleep charge becomes 23 988 µC per period, the average 404.8 µA, and the life about 2470 h, or 103 days. Halving the radio burst would change almost nothing; finding the 390 µA leak changes everything. Waking every 10 s instead of every 60 s with the original 10 µA sleep gives 399.7 µC per 10 s, 40.0 µA and about 2.9 years: there, the wake-ups dominate.

MYTHS AND FACTS

Common misconceptions

Battery life is capacity divided by the sleep current

It is capacity divided by the average current, which includes every wake-up.

The meter shows the average current

It shows what its own sampling and filtering make of a pulsed current, which can miss short bursts entirely.

Measuring does not change the circuit

The shunt or ammeter drops a burden voltage; at high currents that can brown out the device and change what you measure.

mAh is a measure of energy

It is charge. Energy needs the voltage as well.

Check yourself

Answer in your head, then open the card.

A device draws 2 mA for 50 ms every 5 s and 5 µA the rest of the time. What is the average current?

Charge per period: 2 mA × 0.05 s = 100 µC, plus 5 µA × 4.95 s = 24.75 µC, total 124.75 µC. Divided by 5 s: about 25 µA.

With a shunt monitor that resolves 2.5 µV per count and reads at most 81.9 mV, what shunt gives 10 counts at a 10 µA sleep current, and can it also measure 50 mA?

10 counts is 25 µV, so R = 25 µV / 10 µA = 2.5 Ω. At 50 mA that shunt drops 125 mV, beyond the 81.9 mV range; the largest shunt that keeps 50 mA in range is 81.9 mV / 50 mA ≈ 1.6 Ω. One shunt cannot do both: use two ranges or measure the phases separately.

Why can a board’s sleep current rise when a debug probe or a USB-to-serial adapter is connected?

Their signal lines can drive the microcontroller’s pins, or hold pulled-up lines low, so current flows through pins and pull resistors that would otherwise carry none. Measure with them disconnected, or at least account for them.

The radio burst takes 22 % of the charge per period and sleep 67 %. Which should you optimise first, and by how much can halving the radio burst improve battery life at most?

Sleep. Halving the radio’s charge removes 11 % of the total, so life improves by at most 1/0.89 ≈ 12 %; halving the sleep current would remove about a third of the charge.

Sources (4)
  1. Linux kernel, Documentation/hwmon/ina2xx.rst — “The INA226 is a current shunt and power monitor with an I2C interface. The INA226 monitors both a shunt voltage drop and bus supply voltage”; the shunt value is set in micro-ohms; sysfs channels for shunt voltage, bus voltage, current and power; the update interval is the conversion times “multiplied by the averaging rate”
  2. Linux kernel, drivers/hwmon/ina2xx.c — the shunt-voltage register is read as a signed 16-bit value and divided by shunt_div to give millivolts: shunt_div = 100 for the INA219 (10 µV per count) and 400 for the INA226 (2.5 µV per count); current_lsb = shunt_voltage_lsb / R_shunt
  3. Raspberry Pi Ltd, pico-sdk 1.5.1, rp2040/hardware_regs/include/hardware/regs/clocks.h — CLOCKS_ENABLED0/ENABLED1 “indicates the state of the clock enable” for each clock destination; SLEEP_EN0/1 and WAKE_EN0/1 reset to all enabled
  4. STMicroelectronics, stm32f4xx-hal-driver, Src/stm32f4xx_hal_pwr.c — “To minimize the consumption In Stop mode, FLASH can be powered off before entering the Stop mode using the HAL_PWREx_EnableFlashPowerDown() function”; in Sleep and Stop “all I/O pins keep the same state as in Run mode”