microCurrent: Don't guess, measure your consumption
Having gotten years worth of data from Wirelessthings XRF-based sensors from a single CR2032 coin cell, I was quite keen to get some of my own RFu328-based sensors ready for battery power. I’ve had previously researched the different power saving modes Arduino-compatible microcontrollers provide and especially the deep sleep mode “ATSM3” offered by the RFu328 seemed like a great opportunity to build a long-lasting sensor.
As Nick Gammon writes on his excellent forum post about power saving techniques, very often we spend a lot of time optimising software logic and consumption by the CPU itself, but voltage regulators and any devices attached to the circuit may draw orders of magnitudes more current than our carefully designed code. I was bitten by this myself more often than not, so I thought I’d share a few of my obvious cock-ups as they may serve especially beginners with their own experiments.
Choosing the right battery and voltage regulation. The top three parameters you have to specify is output voltage, capacity and form factor. That isn’t trivial. While a controller like the RFu328 requires 3.3V, it’s not uncommon that your actual sensor to need 5V to deliver reliable data. So what to do? You could start from a 9V block and via voltage regulators step these down to 5V and 3.3V. Unfortunately, down-stepping doesn’t come cheap in terms of current consumption. Also, while 9V blocks look juicy, their capacity is usually around one third of a AA battery. In one of my first experiments, I used a standard 9V block and two voltage regulators on the basis of the AP1117 chip (the PowerPOD1117 3V/5V variants). My joy didn’t last long. According to this discussion the voltage regulators have a joint quiescent draw of 12mA. That is in a day we’re looking at 24h x 12mA = 288 mAh. According to specs from Wikipedia, that alone would drain your battery in two days. Step-up regulators seem to have a significantly lower quiescent draw. Although going from a lower to a higher voltage comes at an energetic cost, the quiescent draw of the PowerPOD1402 step-up regulator is indicated with 13uA. That is, as long as your battery delivers a voltage in excess of the output of the step-up regulator, in a day we’re rather looking at 24h x 13uA = 0.312 mAh.
Thus, in a second experiment, I decided to power my project from a 3.6V AA battery. That voltage is still acceptable for the RFu328, whilst a PowerPOD1402 5V took care of providing 5V to a peripheral component. There are very powerful Li-SOCl2 batteries e.g. from companies Tadiran and Saft, with 2400-2600mAh. However, as I said, there’s a cost for stepping 3.6V to 5V, and even with a small quiescent draw of less than 3mA for a particular 5V sensor, I was still looking at ~10mA even when the RFu328 was in deep sleep. Pop that sleep current into a battery calculator, assume the sensor to wake every minute for about a second at 50mA, and the sensor device you hoped to run for months dies after about a week. Not good.
My standard setup now combines a 3.6V AA battery with a PowerPOD1402 3V3. While the battery is new there’s only a few uA of overhead, but the regulator ensures a stable 3V3 supply once the battery is drained - batteries drop significantly in voltage after they’ve been used for a while. The biggest improvement was to find sensor periphery that can run at 3V3, obliterating the expensive conversion to 5V.
Weekend project: dissecting current consumption of my favourite voltage regulator, sensor and radio with custom PCB. pic.twitter.com/fCrPuPYH5E
— Boris Adryan (@BorisAdryan) November 7, 2015
Don’t guess, measure! My code wakes the RFu328 about once a minute, takes the measurement, sends a brief message over the radio. And blinks. While the first steps take mere milliseconds, I made sure that my shiny LED was to be seen, for one second. Eventually I took Nick Gammon’s warning into account and started experimenting with shorter times. Turns out that a 20ms blink is clearly detectable, allowing me to cut down the wake time from 1000ms to 20ms. As the entire RFu328 was awake during the blink, that cuts down my current consumption from 24h x 60 wakes/h x 1000ms/wake x 50mA = 20mAh per day to 0.4mAh per day.
In theory the current consumption of the RFu328 is about 0.6uA in deep sleep. This is what I used as basis for many life time calculations, which I’ve not even nearly achieved. In the end I invested into a microCurrent ampere meter for very small currents. I was stunned. Rather than 0.6uA I was looking at more than 160uA, or 0.16mA, - every hour - that’s 3.84mAh per day! It took me a while to realise that connecting one of the pins to ground alone was responsible for that issue. There are always-on pull-up resistors that draw current if these pins are connected to anything. Fortunately, one four of the digital pins of the RFu328 show this (for me unexpected) behaviour, connecting periphery to other pins circumvents the problem. I conclude that it’s always worth to actually measure things rather than relying on data sheets alone!
In the meantime I’ve heard from Toby Jaffey that he’s had a good discussion about energy consumption on StackExchange. Worth having a look, too.