Measuring power usage over time? What kit is that?

Posted on
  • Hi,

    I have a simple project in which my Espruino wakes up every 2 seconds and takes a reading from a magnetometer, if the conditions are right, it wakes up an nfr2401 radio and sends a signal.

    All OK and is very good, but I am trying to estimate how long a LIPO battery will last.

    I put my multimeter into the correct mode, and put it in-line (?) (measure current ftw) between the LIPO and the Espruino, and fair enough I can see the numbers change as the current surges when the reading is taken and the radio is required to TX, i.e. from almost nothing to a jump then back down again in a blur.

    What is the name of the equipment I would need to monitor and log this usage properly, say over a 5 minute period? (some expensive piece of kit no doubt)

    What is the poor man's version of that?

    I imagine this must be a common practice, how do you set up your workbench to monitor current use as you work?


  • I think in general people would say to use an Oscilloscope. Take a 1 Ohm resistor and connect it in series with the power, then put the oscilloscope across that.

    If you have an oscilloscope that can log, you could export that log and then add up all the values.

    I guess an easier method is to get a big capacitor (supercapacitor) and to charge it up to a known voltage. Power Espruino off that, and you should be able to see the voltage lowering over time. The discharge should be more or less linear, so working out the average power draw from that would be pretty easy.

  • In fact to make it easier, you could go to this page

    Say you take a capacitor of a known size, charge it up to 5v, then time how long it takes to discharge to 4v. You'll get a mAh figure from that website, so then you're just dividing it by how many hours it took to discharge (I think?).

  • Quick example that I just tried here... Put a 0.33uF supercapacitor between Gnd and 5v on the Espruino, and measure the voltage across it.

    When charged up and after I unplug USB power, I get 4.35v, so I put 0.33F, 4.35v and discharge to 4v in here and get 32.083 µAh. I then figure out how long it took to get to 4v, which looks like around 7 minutes in my case.

    32.083 uAh / (7/60) = 275 uA

    So on a 700mAh battery that's 700 / 0.275 = 2545 hours = 100 days. ish. The battery can self-discharge, and the voltage may drop to a level that's too low before its full capacity has been used.

  • 5V supercaps have significant internal resistance, IIRC in the 10-100Ω range. Radio transmission would most likely cause a brown out. Don't know if espruino and the radio runs at 2.5V...

    Actually a couple of uC vendors have tools for power measurements, just for inspiration:
    STM has ammeter in some newer Discovery boards: Cortex L4, Cortex L0
    Ti has Energy trace in the MSP432 Launchpad.
    Atmel has Power Debugger as a standalone tool with jtag and other debug stuff.

  • Yes, the internal resistance is pretty nasty - I guess you could stick a more sensible capacitor across it as well.

    I wonder whether you could just use one of those other boards as an Ammeter for the Pico? Might be worth a look - but if they don't do average consumption they're not going to be much use.

  • Thanks for the ideas and discussion. I am certainly no electronics engineer but it gives me an idea.

    Maybe I could just find the smallest LIPO possible (like this 20mah, retired) and see how long before it gives up.

    Neither appreciating, nor understanding how the different battery types discharge, I could at least compare LIPO to LIPO, and as a bonus I could stick it in the freezer to see how it copes in low temperatures. I'd be opening and closing the fridge door every hour to check it.

    I say this mindful that if I am going to get serious about this iot stuff, an Oscilloscope will be the right way to go.

  • Yes - it's not going to be very accurate, but it'll give you a rough idea how long you might expect it to last.

  • Honestly, no idea. Theoretically you can remove the IDD measurement jumper, and connect to a different board.
    Both STM's and TI's board have an additional uC for power measurement, and maybe the protocol maybe not that well known...
    Ti's solution looks like heavily tied to their IDE (measuring function level power consumption sounds nice tho). Couldn't find more info about STM ones.

  • I have a similar application where I was looking at using a Pico as a remote temperature node. It needs to wake up every 30s, take a measurement from 2x DS18b20 temp sensors then transmit the values using a nrf2401. I was looking to run it off a single 18650 battery - but my theoretical calcs say it wont last the 18months I would like it too.

    I am making the assumption that the full Pico run current is used while waiting for the DS18b20 to convert and return - or is that not the case ?

    Gordon - I saw in another post you mentioned it could be possible to slow the STM clock to save power in run mode - is that something that is implemented/quantified as to the savings ?

    I know I should probably also do some practical measurements here, but dont want to spend that time if this is never going to fly.

    I have found another little Arduino board setup for this kind of thing which has a 5mA run current - but would prefer to use a Pico as the other half of the project is also Pico based.

  • If Espruino is in the middle of a function then it'll be using the full 'run' power, but if it's waiting on a high-res timer it'll be using the non-deep-sleep power (10mA?).

    The current DS18B20 module actually cheats - it returns the last sensor reading and kicks off new one, so as a result the Pico won't actually be awake for very long at all.

    I'm afraid there's no clock slowing implemented at the moment. You could probably do it with poke if you needed to (but there might be issues with USB dropping out if you're not careful). You could also compile your own version of Espruino quite easily I think that just ran at a lower clock speed.

    I'm actually be quite careful with 18650s - they'd be normal Lithium Ion? I'm not sure what the self-discharge would be like over 18 months. You can get non-rechargeable Lithium cells that are rated for 10 years though, and they could be a good bet?

  • Good point re 18650, I had not considered the self discharge rate so will cross them off the list !

  • Well, don't take my word for it - look them up and see what it is :) It might be ok if you get decent ones.

    Something like this could be good though. 9000mAh, and <1%/year self discharge!

    I could be wrong, but that'd handle Espruino being on for 18 months, 2% of the time. So that's if it were awake for 0.5 sec, every 30 seconds - which seems like serious overkill.

    I'd prototype something and do some power consumption tests though :)

    non-rechargeable, but hey - £5 every 18 months isn't a disaster

  • Yes I was having a look at those type of cells last night. In my application the sensor/pico/nrf are going to be located inside a fridge and at those temperatures the voltage drops to around 3.2V, so I would probably need to use a couple of smaller cells. The DS18b20 have a min of 3V and the NRF a max of 3.6V hence probably need to use the regulator, unless I protected the NRF at room temperature.

    But in principle these look like the right kind of battery to be using.

  • Good quality 18650 battery will have 2000-3000mAh and should have similar discharge to that larger cell. But you need to get good ones, not the cheap crappy ones - there are a lot of very cheap, super crappy, 18650's on the market - the usual tell is a blatantly inaccurate capacity claim).

  • **This is a strange way to measure Coulombs **
    Some history:­he-electricity-meter/­y_meter

    A bit more modern.­

    and what I had in mind if you can find the gadget on the surplus market. The last time I saw some was in the late 1980's. They were a couple of dollars each.­X1M

  • A practical solution
    ACS712 with op-amp such as this one
    Add a low pass filter on the output of the op-amp with a long time constant.­Articles/Low-pass-filter-calculator.php
    I figure 10k resistor and 100uF capacitor would do the trick.

  • Looks good - I wonder how accurate it is though - it goes up to 5A, but you'll be measuring almost 1 million times less than that when the Espruino is asleep.

  • Accuracy?
    You are correct. This kit would most likely measure the on current pulse after it is stretched over the time constant of the RC filter. Likely the low power current would be down in the noise.
    For estimating total Amp-hours, add the low power current times time to the measured on current.
    Setting the gain on the op-amp figures into the setup and calibration.

    My experience tells me that trying it in a freezer is prudent. The cold can affect the battery.
    The measurement method is based on linear assumptions. Batteries have some non-linear characteristics, especially with regards to temperature.

  • Another method
    We can measure current when the device is asleep and when it is awake.
    It's a question of duty cycle.
    Use a solid state switch to control an analog electric clock and change the code to turn the clock on at wakeup and off just before going asleep, with your application code in the middle. Run it for a period of time (24 hrs.). Then the analog clock elapsed time divided by the total elapsed time gives the duty cycle fraction.

  • More ideas
    Measuring the awake duty cycle of a sleepy Espruino board.
    Using an analog clock would work if the sleepy Espruino on time is longer that one cycle of the clock mains 60 Hz. Or 50 Hz.
    If the sleepy Espruino on time is shorter then this would be better.
    Given a sleepy Espruino board that wakes up periodically to perform the user’s task, it would be useful to measure that percentage time in a period (24 hrs.) it is awake.
    Take a watch crystal oscillator output (32.76803 kHz) as one input to a two input NAND gate.
    Use a pull-down resistor on a pin on the sleepy device so that when it’s asleep the pin is low and when awake the pin is high. Tie this pin to the 2nd input of the gate.
    Tie the output of the gate to a divide by 256 and follow that by another divide by 128 chip.
    If the gate is “on” the output of the 2nd divider would be 1 Hz.
    Tie the output of the 2nd divider to a pin on a 2nd Espruino board, programmed to count the pulses on the pin. Then 100* pulse_count / elapsed_time is the percent on duty cycle.
    Of course an even faster clock and divisor chain could be used.
    Is there some way to use a pin on the measurement Espruino board to gate the watch crystal oscillator and eliminate the extra hardware?
    Is there a way to use the counters on the ARM chip to implement this?

    Another method if E.getTemperature() is available.
    In a room with relatively constant temperature, load the Espruino with code to sleep for an hour, wake up, measure and report the chip temperature T1.
    Then load your program to sleep, wakeup, do your job and sleep again. Add code to read and report the chip temperature after an hour T2.
    And finally run code fully awake for an hour, then read and report the chip temperature T3.
    Duty cycle % = 100*T2/(T3-T1).

  • Correction
    Duty cycle % = 100*(T2-T1)/(T3-T1)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Measuring power usage over time? What kit is that?

Posted by Avatar for CoffeeCups @CoffeeCups