Power engineering: interview questions
6 Power engineering questions embedded interviewers ask, each with a model answer. How do you calculate the average current of a duty-cycled device? Which…
How do you calculate the average current of a duty-cycled device?
Divide its cycle into states (sleep, wake-up, measure, transmit, receive, retries), take each state's current and its duration per cycle, and sum current times duration, the charge, over the cycle; dividing by the cycle's length gives the average. A device that sleeps at 2 µA for 59.9 s and transmits at 20 mA for 100 ms every minute averages (2 × 59.9 + 20 000 × 0.1) / 60 ≈ 35 µA. Battery life is then the usable capacity divided by the average, so 2 000 mAh × 0.8 / 0.035 mA ≈ 45 700 hours, about five years, before self-discharge and temperature are considered.
Which figures in a datasheet do you need for a power budget, and what do they leave out?
The supply current tables: Run mode at each clock (often as µA/MHz), with peripherals on and off; Sleep; each Stop, Standby and Shutdown mode with the RTC and watchdog on or off; each peripheral's own consumption; and the wake-up times from each mode. They are typical values at 25 °C and one voltage, measured with a specific test program, so real code can differ by tens of percent, and the maximum values at high temperature are many times higher for the deep modes, where leakage dominates.
They leave out the rest of the board: the regulator's quiescent current, LEDs, pull-ups held against a low line, voltage dividers on the battery, sensors and radios, level shifters and leakage paths through unpowered parts. Those often decide the sleep current.
What is the difference between Sleep, Stop and Standby on an STM32?
- Sleep: the core's clock stops; peripherals and clocks run; any interrupt wakes it at once. Current is perhaps a third of Run.
- Stop: every high-speed clock and the PLL stop; RAM and all registers are kept; the core regulator may be in low-power mode. Wake-up sources are EXTI lines (pins, and peripherals with their own wake-up such as the RTC, LPUART or LPTIM) in microseconds, and the system then runs on the internal oscillator, so the clock tree must be set up again. A few µA.
- Standby: the core domain is powered off; RAM (except backup SRAM) and registers are lost; only the wake-up pins, the RTC, the IWDG and NRST can wake it, and waking is a reset (with
SBFset). Around 1 µA or less. Shutdown, on newer parts, also turns off the brown-out reset and the LSI, for tens of nA.
The mode is chosen with SCB->SCR SLEEPDEEP and the PWR registers, then entered with WFI or WFE.
Why can a debugger make a low-power design look broken?
Because the debug interface keeps parts of the chip awake. With a debugger attached, or with the DBGMCU bits that keep clocks running in Stop and Standby set (which IDEs often set to keep the connection), the core does not really enter the deep mode, so the current is milliamps instead of microamps. A debugger can also back-power the target through its signal lines. Measure low-power behaviour with the probe disconnected (and the chip reset since), and do not leave DBGMCU bits set in production code.
How do you measure a device's current when it ranges from microamps asleep to tens of milliamps transmitting?
With an instrument built for it: a power analyser or source-measure unit with automatic range switching (Nordic's Power Profiler Kit, Joulescope, Otii, a Keysight N6705 with its analyser) that samples fast enough to follow the bursts and integrates the charge. A multimeter in series reads only slow averages and its burden voltage can disturb the device; a shunt resistor with a scope shows the shape but has a narrow dynamic range. Mark the firmware's states with a GPIO that the analyser records, so each part of the trace is attributed to its code, and measure over many cycles to average out variation.
What does "race to sleep" mean, and when is it wrong?
Run the work at a high clock so it finishes quickly, and return to the deepest possible sleep. Because Run current has a fixed part (regulator, flash, oscillators) beside the part proportional to frequency, finishing sooner usually costs less charge than running slowly. It is wrong when the duration is set by something else, such as a sensor's conversion time, a radio's protocol timing or a slow bus, since the high clock then just burns current while waiting; when a higher clock needs a higher core voltage or extra flash wait states; and when starting the fast clock (a crystal, a PLL) takes longer than the work itself.