It turns out that there’s a nice way to measure current consumption with a commercial board by ST Microelectronics. It’s called the 32L0538-DISCOVERY, but for brevity and consistency I’m going to call it the “Disco-L053” from now on:
This is one of a long range of “Discovery” evaluation boards by STM, and as you can see it even has a touch slider and 172x72 pixel ePaper display. But the main feature for our purposes is that it includes a very nice current measuring circuit, which is used by some demo software to demonstrate that the main L053 µC on the board draws 42 µA in low-power run mode at 131 KHz and that it has a “stop” mode which draws a mere 400 nA.
Which is nice, but what I find most intriguing are the specs of this current measurement circuitry: it claims to measure currents between 100 nA and 50 mA, i.e. nearly six decades of current range. And it’s also auto-ranging, but more on that later …
The current is measured using a set of shunt resistors, which are switched in or out via MOSFETs, and a couple of op-amps with very high impedance inputs and minimal bias voltage, to avoid introducing measurement errors in the ultra-low current range (note that 100 nA is the equivalent of a 33 MΩ resistor across 3.3V).
Here is the analog side of the circuit (this is actually a slightly different one used by the L476DISCOVERY, which has a schematic diagram layout that’s easier to understand):
In essence, the circuit measures the voltage difference across a shunt resistor of 1Ω, 24Ω, 620Ω, or 10kΩ, and then amplifies that value by a factor 50. This translates to (approximate) full-scale current ranges of 50 mA, 2 mA, 80 µA, and 5 µA, respectively.
The actual measurements are taken by a dedicated “MFX” chip on board, which is an STM32L152 connected to the main µC as I2C slave. I suppose that when you’re STM, then throwing in an extra µC (or two, for the ST-LINK) is no big deal w.r.t. BOM costs …
The software for the L152 is not available, unfortunately. But the I2C commands needed to init the L152 and have it take an auto-ranging current reading are easily understood from the demo code for the main L053 µC. In fact, Matt Mielke from DigiKey has written an elaborate article describing this entire setup, and how he adapted the code to allow checking the current consumption of all the L053’s low-power modes via the serial port.
So, ignoring all the other features of the Disco-L053, this €20 board can in fact be used as a simple 3.3V power supply with up to 50 mA for your own projects, with the ability to report actual current consumption over an extremely useful range of 0.1 µA to 50 mA.
But… there is one drawback: it turns out that the L152 takes 100..300 ms per current reading. For higher currents, it’s usually ≈ 100 ms, but for the lower ranges this drops to one reading every 300 ms, due to the way L152 does auto-ranging.
This makes such Disco-L053 measurements very useful for static current consumption measurements, but it won’t be of much use to track and see rapid current changes, e.g. when including an RF module with its (typically bursty) power consumption profile.