Written by elecia.
On episode 104, we talked to Andreas Eieland of Atmel about choosing low power processors, comparing them with EEMBC’s benchmark ULPBench, and tips for achieving low power. If you are making a low power device (like a wearable), you need to understand how to minimize current draw to maximize battery life. However, even before that you have to know how to measure current. After all, why optimize something that takes a microsecond when you draw a lot more total power in another area that goes on for seconds?
I recently acquired a . I’ve hooked it up to a sensor board (, naturally). You’ll see this whole thing as a project in a later post but right now I only want to look at how much current the board is consuming. Actual functionality and decreasing consumption can come later.
The easiest way to measure current is with my power supply.
Well, that seems to be drawing no current but the LED is on. I suspect a granularity issue. So I take that back: the easiest way to measure current is with Chris’ power supply.
My current consumption would flip around between 0.030-0.039 A (30-39 mA).
If we want to talk about power (Watts), then I need to multiply current by voltage (5V), so I get 180-195mW.
If you don’t have a fancy power supply or yours (as mine) doesn’t provide the granularity you need, you can hook your DMM in circuit (note: not all DMM have current monitoring). Every time I do this, I have to look it up in the manual and squint several times to see if I’m doing it right. Here is a drawing of how it should look, at least in theory. (Note: this is case b in figure 10-1, and it isn’t stealing if it is from your own book, right?)
Note that the negative cable on your power DMM goes to the system and the positive cable goes to your power supply. I sort of hate connecting black cables to pins marked Vin. It gives me the “oh no! I’m doing this wrong!” heebie jeebies. In this case, it is ok.
Using the DMM gives me more detail than my power supply but it doesn’t tell me which part of my code to optimize. For that I need to use an oscilloscope and a resistor, utilizing the voltage drop method shown in the c portion of 10-1. Though, it can’t be any resistor.
With my DMM, I had to give the meter an expected range: I can choose up to 10A, in the mA range, or in the uA range. Since my power supply told me I was in the 30-40mA range, I was confident using the mA range. If I hadn’t been sure, I would have switched the probes around and used 10A because that’s safe. If I measure 30mA while in uA mode, I may blow a fuse on my DMM, so it is better to start high and go down as needed.
In precisely the same manner, the size of my resistor must correspond to the amount of current I expect and getting it wrong can have smoky results. (Speaking of smoky results and blown fuses, it is poor etiquette to leave a DMM in current mode. Turn it off or switch to voltage so the next person doesn’t hurt it.)
So now you have to choose a value for the resistor. It is better to choose too small a resistor than too large, you can increase the size as needed. You’ll have to balance the granularity you can see with the maximum current you expect. If your system is usually in the uA range with an occasional peak in the tens of mA, plan for something the 1.5-2x the expected peak to avoid damaging the scope (and resistor).
Power(at 5V input)
|40 mA||1 Ω||0.040 V||= 5V * (5V / 1 Ω) = 25W|
|40 mA||10 Ω||0.40 V||2.5W|
|40 mA||100 Ω||4.0 V **||0.25W|
|40 mA||1 kΩ||40 V **||0.025W|
|I||R||V = I * R||P = Vin * I|
** Note that the last two rows won't work at all. You can't read 40V out if you are only putting 5V in (1kΩ). And if you are dropping 4V across the 100Ω resistor, your circuit is probably not running. Be sensible about your resistor values. On the other hand, if we were expecting 40 uA, and using those resistor values, that table looks ok again. Ranges are important!
That last column is critical too: you’ll also need a resistor that is rated to withstand the power you are going to put through it. It is easy to find ¼ W and ½ W resistors but higher than that, you are looking at something large and strange looking. Note that the power rating is based on the power dissipated by the resistor Vin divided by your resistor value).
Note that higher voltage means higher power. If I was using 3V on this system instead of 5V, my resistor wouldn’t need to dissipate as much heat so I could choose one with a lower watt rating. This is a good note when thinking about power consumption: lower voltages mean lower power (this is why 1.8V processors are nifty). And looking a back at the equations above, energy depends on time. Less time on means less energy consumed.
As with our DMM, the resistor goes in series with the system. I’m using a 10 Ω resistor so 100 mV read on the output is equivalent to 10 mA.
Make sure your connections are really solid. I appreciate the desire to bend the resistor legs into a hook and use those to connect to the system’s power pin. However, solder is better. (Or at least wrap it around multiple times for a good connection.)
The drawing above (10-1) shows the resistor in series between the system and V+. However, it can easily go between the system and V-. Since I wrote Making Embedded Systems, I’ve switched to using V- as my USB oscilloscope shares a ground with my power supply.
I had some interesting results until I switched to V-. Though, that may also have been due to my debug serial port being connected (limit the number of ground connections to your system or risk strange behaviors due to ground loops). If you have disconnected your serial port, then putting your resistor to V- or V+ doesn’t matter.
Finally, here is my current reading for my freedom board.
Zooming in, I can see a lot more information.
My LED is changing color at 5 Hz (every 0.2s) and polling the sensors then. It looks like there is some correlation between current consumed and LED color but a lot more than that is going on. Looking at another part of the signal, I’m not sure why I have a 50Hz timer in here or why it stays awake for so long each time. If I can increase the amount of time spent in that lower state, I can significantly reduce the power consumption.
One thing to remember: measuring the signal changes it. Dave Jones of eevblog had a good description of how the monitor can affect the signal. For the most part I don’t mind those inaccuracies, I need to know ranges: am I seeing what the chip vendor promised? And what parts of my code are taking the most power?
I’m running the Freedom board and sensor board at full tilt. I do not intentionally put the processor to sleep or standby, using the standard wait from mbed. (Oh yeah, also, I’m using the mbed compiler which makes getting started quite easy but I can’t change the optimization level.)
To get lower power, I probably have to read the manual to figure out how to put the system into the correct sleep state. I may have to switch to a compiler with more options. I can use interrupts from the sensors to wake the processor instead of polling, letting me sleep more often. I can slow down my clock. There are many, many options from here. Andreas sent over Atmel’s handy application note on coding tips and tricks to lower power. It has excellent things to try and most of those techniques are cross platform, useful in many contexts.
I suspect in the future, I’ll write more about specific power reduction techniques in software. For today, though, I needed a baseline so I could start keeping score, figuring out which techniques work best on this system.