Designing for battery power

I recently made a gadget using an atmega328p which had to run on battery for as long as possible.
Lots of help from Nick Gammon's excellent page and many articles on measuring low currents.
However, there was very little to be found on measuring actual power consumption while the processor was doing things.
Further investigation located a paper outlining a very elegant device, accurate and affordable which should be on the top of any battery powered project wish list.

https://journals.sagepub.com/doi/10.1177/0020294018794350

Brilliant, isn't it....
They have even used it to measure the difference the compiler makes to power consumption!

Has anyone ever seen anything like it - or where you can get one?

I didn't read the whole thing, but do they ever mention how the calibrate the device?

Paul

Didn't really answer my question but to answer yours,

"To validate the microwatt-meter design, a known resistor,RLoad=218Ω, is connected as a load resistance to the microwatt-meter. The capacitor array, C=0.125F, is charged to a known voltage, then discharged through RLoad for a known period of time using the microwatt-meter which then measures the voltage across the capacitor array. This process is repeated for different time intervals."

It's sort of empirical. The circuit shows three trim pots, one for the divider for the analogue input and two for the comparator.
The results they achieved were within 1.2%.

Forkbeard:
Didn't really answer my question but to answer yours,

"To validate the microwatt-meter design, a known resistor,

Validate is not calibrate.

Paul

By the conservation of energy, known resistor, measure the voltage and time. Just hope your multimeter is reasonably accurate....

It's really quite an elegant solution if you read it

on measuring actual power consumption while the processor was doing things.

On AVR based Arduinos, the processor power consumption is constant while "doing things". For example, in a wait loop, the same amount of power is consumed as in doing a series of multiplications.

What do you really want to measure?

@jremington I want to measure the actual power the unit uses during an operation.
My question was essentially has anyone seen anything that will do that accurately?

Let me give you an example from my recent project. I needed to flash an LED once a second for a period of up to 30 mins. I was using an RTC (DS3231) waking the avr from sleep by interrupt.
Now how much power do I save by waking it, flashing the LED, switching power to the RTC, using I2C to reset the alarm flag, and putting it all back to sleep till the next second - by comparison with the many other methods?
And do I run at low clock speed or get it all done faster?
And how do I estimate the battery life of a setup that wakes up and does some measurements, records them and then sleeps again, without knowing the actual power used during each operation?
The answer is I needed to be able to measure power consumption and it is not easy.
If you scope a resistor in series with the power supply you will see the current is far from constant!

The processor is only part of the unit. And although it’s current is constant for a single type of operation, doing arithmetic with different variable types does not use the same power. So an average program is impossible to estimate. Even compiler optimisation affects the power used.

doing arithmetic with different variable types does not use the same power.

That is not true for the standard AVR-based Arduino. Drop your incorrect assumptions and move on with the project.

If you know the current used by the various LEDs, sensors, etc. during wake mode, and they are all off in sleep mode, then it is no problem to estimate the average current usage by ratioing the on and off times. Covered in great detail here.

Project is finished and in service but I am certain it is not optimised.
If one is being pedantic, energy is the correct term and not power. Just add time.

Maybe my question was wrong. I was hoping for someone to help with finding a tool to measure the energy used in battery powered designs. For a good design it would be a priceless tool to help decide if method a or b is a better solution at each part.
As credited in my first post, I read and took full notice of Nick Gammon’s page.

However the real answers are far more involved than you appear to intimate. And in battery use, every little counts. If you are not convinced, this paper actually quantifies some of the issues and produces some very interesting results.

Thanks anyway for your time.

https://www.researchgate.net/profile/Mohammad_Al-Shorman/publication/332539387_Toward_Energy_Efficient_Microcontrollers_and_IoT_Systems/links/5cbadf7c92851c8d22f7b76d/Toward-Energy-Efficient-Microcontrollers-and-IoT-Systems.pdf

However the real answers are far more involved than you appear to intimate.

How true! Just to pick two random examples, battery type and quality matter a great deal.

Well, if you are looking for a tool, the quoted Nick Gammon page has an example of a meter which can measure down to picoamps. https://simonselectronics.co.uk/product/ucurrent-gold/
Integrate current with respect to time ( picoamp hours) and multiply by voltage to get energy over the measurement period.

There is a limit to the benefits of optimization. For one of my atmega328p projects with a transmitter and IR leds, I am likely to have to replace the batteries ( 2 AA cells) , not because of the current consumption of the circuit, but because of the age of the battery, it’s internal discharge rate and the risk of chemical leakage.

Integrate current with respect to time

Indeed.
I couldn't find a simple way.
My digital scope gives a lovely trace, sampled at tiny intervals but the data isn't available to do the calculation. And it's quite a complex waveform if you're waking up, doing some I2C etc.
Measuring the area under the curve (also integration) is pretty tricky.
I thought of building something to sample the output of a current to voltage converter (like the one you mention) but to get anything like an accurate answer, you need some serious electronics.
There's a nice box at Optimize Your Development with Qoitech's Otii Solutions but it's about $600

Using a big capacitor E=1/2C(V2 - V1)² seems a much simpler method and you don't have to measure microamps.

Maybe that has to be the next project....

This method relies on measuring the voltage of a capacitor to estimate the power used. Therefore, to work, there must be a significant change in the voltage of the capacitor.

That is a problem as the power consumption of microcontrollers and even the I2C bus depends on the supply voltage (lower current through the pull-up resistors as the voltage drops).

Now if you really want to optimise power consumption in I2C communication, make sure all unused bits in your data are 1s, not 0s. Transmitting a 1 takes less power than a 0. Of course minimising the amount of data transmitted helps as well, probably even more.

That is a problem as the power consumption of microcontrollers and even the I2C bus depends on the supply voltage

The Jordanian solution was quite elegant in this respect as they topped up a secondary capacitor from the primary one to provide a fairly constant voltage supply. This is what the comparator is doing.

Thanks for the challenge on the I2C bus!!
The time the system is awake for is a big factor too. So tight coding, good compilers, variable types, good use of registers and timers are all relevant. Reducing the awake time from 10ms to 9ms is a 10% improvement - one could get obsessive...

There are so many things that can affect the energy used in small periods of activity with external sensors, data transmission and storage etc. that it will be great to have a box with a display that tells you whether your 'improvement' really was or not. I long to get rid of the 'probably' factor!

I'm working on it....

Forkbeard:
Maybe my question was wrong. I was hoping for someone to help with finding a tool to measure the energy used in battery powered designs. For a good design it would be a priceless tool to help decide if method a or b is a better solution at each part.

A compare and contrast method of working out the amount of power different project setups use is fairly trivial.

See this report on how much power various combinations of GPS and antenna use;

GPS Performance

Note that the amount of mAhr a particular GPS uses is a real world value, not calculated or extrapolated from restricted measurements.

Here is an example of a microcontroller development system (for the TI MSP‑EXP432P401R) which dose include does include an energy usage monitor in its debug package.

http://www.ti.com/lit/ug/slau597f/slau597f.pdf

The document is a simple introduction but pages 11 and 12 give some flavour of it.

@srnet. The “ far more flexible” option that is mentioned in the last paragraph of that article uses an avr with a DS3231 RTC which was where I started. “To be continued “ I look forward to it.
As he surmised, the sleep current is the easy bit. The activity while awake is the principle actor. And if one is trying to squeeze the best life out of AA batteries, it’s certainly nice to know what is happening.

@6v6gt. The TI approach looks remarkably familiar.
“In debuggers that support EnergyTrace™ technology, a software-controlled DC-DC converter generates the target power supply. The time density of the DC-DC converter charge pulses equals the energy consumption of the target microcontroller.”
This is more or less the approach I have adopted but using the Jordanian method of using the charge on the capacitor as the energy measurement.
Looks like I’m on the right path and thanks for the link. It’s nice to see they have identified the issue. Now for a simple box to feed your Arduino and give the same measurements...