Measuring average MCU current (uAs to tens of mAs) - Page 1
Forum section: electronics / testgear

author: swineone
author_rank: Contributor
timestamp: November 09, 2019, 12:47:34 pm
content: Hi,I’m teaching low power MCU techniques to undergraduate EE students.I proposed a challenge to write firmware for an application which reads a sensor and writes the output to an external memory every 3 seconds, and then try to make it use as little current as possible by using my MCU’s low power features (lowering clock and bus speeds, using low power sleep/stop/standby modes), etc. The hardware is an STM32F4DISCOVERY development kit, which has a jumper at the power supply so I can insert a (high-side) ammeter/shunt resistor for current measurement.Because the MCUs will be going into deep sleep modes, current consumption may range from 1 uA up to 100 mA (but 10-20 mA would probably do). Once the firmware is fully optimized, I expect a typical current profile will be a few uAs during a 2,999 ms interval and a few mAs for 1 ms while actually reading the sensor and writing to memory. Do note that, since it’ll spend most of the time using up just a few uAs (1.7 to 4.0 according to the MCU data sheet), it’s important to have a fairly good resolution at this current (I’m thinking at least 100 nA) to avoid a considerable error while integrating this current for the averaging process.I need to measure average current consumption of each firmware and rank students according to how low they are able to take it. Ideally, if I could also get fast, instant readings at a high enough rate (say, every few us to at most 1 ms), that would be very useful during firmware development. For this I don’t really need a high precision; I just need to distinguish between the different sleep modes, whose current consumptions are on the order of mA to tens of mAs; hundreds of uA; uA.I understand tools like the uCurrent Gold or Current Ranger would be best to perform this kind of measurement, but I really need to stick to the hardware the university has at hand, and I can also lend my own personal hardware if it is useful. Unfortunately there’s no budget for new hardware at the moment.Here’s a listing of what stuff I could use:Keysight U1252B;Keysight U1271A;Old HP 34401A;HP 3458A (although I’d like to avoid using it if possible);Keysight DSOX2004A, upgraded to MSOX2024A with all options enabled, but only the stock 10x passive voltage probes (no current or differential probes.)So, can anyone help me concoct a measurement setup for average current consumption measurement in this scenario, and ideally, something that can measure a current consumption waveform that can be viewed on the oscilloscope to aid firmware development?My thinking right now is to use the HP 34401A on the 10 mA or 100 mA range, in which it uses a 5 ohm shunt resistor according to its data sheet. Then I could integrate over 180 PLCs (the line frequency here is 60 Hz) which should give me on the order of 26-bit resolution according to this Keysight document:https://www.keysight.com/main/editorial.jspx%3Fcc%3DUS%26lc%3Deng%26ckey%3D710001-1-eng%26nid%3D-33254.0.00%26id%3D710001-1-eng] https://www.keysight.com/main/editorial.jspx%3Fcc%3DUS%26lc%3Deng%26ckey%3D710001-1-eng%26nid%3D-33254.0.00%26id%3D710001-1-eng.As for measuring a waveform on an oscilloscope, I’m thinking of leaving the multimeter there just to use its shunt resistance, and then to hook up two oscilloscope probes, one at each end of the shunt resistor, to simulate a poor man’s differential probe by using the subtract function on the oscilloscope in math mode. I could probably use the averaging acquisition mode to coax out a few extra bits out of the oscilloscope’s 8-bit ADC.Any other suggestions? Thanks in advance.

author: nctnico
author_rank: Super Contributor
timestamp: November 09, 2019, 01:24:44 pm
content: A DMM won't do you any good. You need an IoT power analyser. This question pops up every week nowadays so please scroll down for hints on what kind of equipment to get. There are actually several forum members which sell IoT power analysers designed by themselves.

author: thinkfat
author_rank: Unknown
timestamp: November 09, 2019, 01:46:35 pm
content: How about the "µCurrent"?https://www.eevblog.com/product/ucurrentgold/EDIT: sorry, just saw you mentioned buying new equipment is not possible now.

author: swineone
author_rank: Contributor
timestamp: November 09, 2019, 02:28:15 pm
content: I appreciate the suggestion. I did have my eyes set on ST’s X-NUCLEO-LPM01A board which appears to be a low cost solution to the problem (my personal budget won’t allow for the $600+ prices I’m seeing for the IoT power analyzers you mentioned, especially with the import taxes on top, and at the university we have no cash and have much bigger priorities if cash were to magically appear). I’m even thinking of buying one of these boards on AliExpress’s 11/11 sale, but they’ll probably arrive next year only, and I need a solution for the next few weeks.I understand a regular DMM like my U1252B won’t be very useful for this. However, my understanding is that a benchtop DMM like the 34401A and 3458A I have access to could integrate the readings over a suitable number of power line cycles to give me an average reading (which, while not ideal for development, would work for the measurements at the end of the contest, whose rules specify that the lowest average consumption wins). I’m just looking for validation of this method, or a suggestion of something better with the equipment I have listed. At the 10 mA range (I assume most designs won’t exceed this peak current) it should be possible to achieve the specified 100 nA resolution with these 6.5 and 8.5 digit DMMs.

author: Fungus
author_rank: Super Contributor
timestamp: November 09, 2019, 02:29:41 pm
content: Quote from: nctnico on November 09, 2019, 01:24:44 pmYep, and nobody's come up with a definitive answer yet.Me? I don't think it's necessary to do it. You can measure the sleep currentonceand after that you only need to see if it's going to sleep or not.ie. You don't actually need tomeasurethat part of the cycle. If your DMM has 0.1mA resolution and it's showing a zero then you know it's sleeping (and you already know the sleep current...)WRT a competition: The sleep current is usually so low compared to the waking current that it's background noise. One extra millisecond of "awake" is going to completely swamp an extra 1uA saving in sleep mode.

author: swineone
author_rank: Contributor
timestamp: November 09, 2019, 02:37:16 pm
content: By the way, I was just experimenting with my personal equipment (U1252B, U1271A and DSOX2004A).I took out the jumper I mentioned for MCU current measurement and plugged the U1252B in its place. A test firmware is showing a steady ~40 mA reading with the ammeter function. Replacing the U1252B by the U1271A shows the same reading.However, at these ranges, the shunt resistor on both DMMs is supposed to be 1 Ω, so the voltage drop should be 40 mV. When measuring the voltage drop of one multimeter (in voltage mode) while the other is used as the ammeter, however, I get higher readings (about 70 mV when the ammeter is the U1252B and the voltmeter is the U1271A, and about 88 mV when the ammeter is the U1271A and the voltmeter is the U1252B).When using the oscilloscope as suggested in the initial post (measuring with two probes across the shunt resistor, and subtracting one from the other using the oscilloscope’s math function), the readings are off by an even larger value — 93 mA when the ammeter is the U1252B.I’m unable to explain this — isn’t the voltage drop supposed to be only that due to the 1 Ω shunt resistor? Can anyone chime in?

author: nctnico
author_rank: Super Contributor
timestamp: November 09, 2019, 02:41:32 pm
content: Quote from: Fungus on November 09, 2019, 02:29:41 pmThe average current may be low but what you are interested in are the peaks and things like the time it takes for the microcontroller to actually wake up. Non-rechargeable batteries have a high internal resistance so large current peaks cause a lot of losses inside the battery.Quote from: swineone on November 09, 2019, 02:37:16 pmYou are measuring wrong. Even with a 1 Ohm shunt the drop over the connectors and wires will give a significant error. You need a seperate shunt and use 4 wire measurements.

author: Fungus
author_rank: Super Contributor
timestamp: November 09, 2019, 02:44:27 pm
content: Quote from: nctnico on November 09, 2019, 02:41:32 pm"wake up time" I can agree with - every extra millisecond on full power is important."Peaks" are mostly solved with capacitors:http://www.ti.com/lit/wp/swra349/swra349.pdf

author: swineone
author_rank: Contributor
timestamp: November 09, 2019, 02:45:31 pm
content: This is another good suggestion which I’ve also thought of — do this in two steps: measure the deep sleep current and the active current, then do a weighted average (where the weights are the duration of time the MCU spends in each mode).It should be easy enough to figure out the time durations using the oscilloscope and a GPIO to indicate when entering and exiting deep sleep mode. Also, the deep sleep current can be easily read off the DMM since it spans a few seconds.However, there’s an issue with measuring active current, especially since the MCU can enter a light-sleep mode for a few us/tens of us, where it consumes about 1/3 to 1/2 of the run mode current, while waiting for a reply from the sensor or external memory.If I could get a reliable reading from the oscilloscope, then I could perform this measurement using the averaging/integration functions available. However, I’m facing another issue related to the shunt resistor inside the DMM which I mentioned in a previous post. If I could fix this, then maybe this method would be an alternative.

author: swineone
author_rank: Contributor
timestamp: November 09, 2019, 03:25:23 pm
content: Quote from: nctnico on November 09, 2019, 02:41:32 pmI believe I may have an explanation for the errors I’m seeing.I measured each ammeter’s shunt resistance using the other DMM in resistance mode. I shorted the probes in the resistance DMM and nulled then, and then stuck the probes into the uA/mA connector and the common connector. The result is 1.70 Ω on the U1252B and 2.12 Ω on the U1271A. I always thought these shunt resistances were fairly precise, or maybe there’s extra resistance in the connectors/PCB until reaching the shunt resistor? Either way, I can manually adjust for this by dividing the voltage results by 1.7 if the ammeter used is the U1252B, or 2.12 if the ammeter used is the U1271A. Unfortunately, these DMM models don’t offer a 4-wire mode, but I believe the benchtop ones do.Regarding the oscilloscope, the probes show a measurable offset even when connected directly to the grounding terminal in the oscilloscope. It’s not pure noise (which I can anyway filter out by the using the averaging acquisition mode); there is a definite DC bias.I believe that, between correcting for the actual shunt resistances and the scope offsets, I may be able to achieve good enough precision to do a little testing.

author: swineone
author_rank: Contributor
timestamp: November 09, 2019, 03:56:20 pm
content: Quote from: swineone on November 09, 2019, 03:25:23 pmAnd the last piece of the puzzle is solved: the extra 0.7 to 1.12Ω of shunt resistance is due to the ammeter's fuses! I opened up the U1252B and measured the 440 mA fuse with the U1271A and it's very close to 0.7 Ω.

author: swineone
author_rank: Contributor
timestamp: November 10, 2019, 02:16:00 am
content: So now that I have a proper setup for measuring low-mAs to tens-of-mAs at high speed, here's a picture of what it looks like while going out of sleep mode and into active mode. The green signal is an LED that is only on while the code is in active mode, and the pink signal is the math signal with the proper corrections for offset and scale factor (it's at 10 mA/div).It's kinda hopeless to make a poor man's differential probe by using two channels and math mode -- the noise is just excessive. I decided to attach the oscilloscope probe ground to one side of the jumper and measuring the other one. There's no risk since my laptop is not grounded.Here's also 10 different readings of the same period superimposed.