I am looking for a way to design something that can tell me the cumulative power draw of a circuit — the same concept as a Kill-a-Watt, but measuring mWh rather than KWh. An added bonus would be the capability of generating graphs to show usage over time.

I'm dealing with ~3.5 Volts, current in the low mW range. Time periods to be logged range from a few minutes to a few days.

## Best Answer

Assuming the supply voltage will be constant for this test, if you convert the current to a voltage, follow that with a low pass filter, then sample well above Nyquist for the filter, you need only perform numerical integration of the voltage samples (by summing, trapezoid, Simpson's Rule etc.). Easy-peasy. The faster you sample in relation to the LPF cutoff frequency the less sophisticated your integration algorithm need be for a given accuracy.

The LPF will smear out over time any sharp pulses of current, but as long as the DC gain is 1 it will not affect the average mAh calculation. So if you have a LPF cutoff of (say) 100Hz, you could sample at 1kHz, do simple trapezoidal integration and get a nice number ramping upward as the device runs.

The only gotcha I can think of is that the bit width of the integration number (or mantissa if it's a float or double) should be equal to the number of significant bits in the current measurement + log2(sample rate) + log2(seconds in your test).

So if you're measuring the current to 12 bits, and taking measurements at 1kHz for 1 hour, you'd need 12 + 10 + 12 = 34 bits, so a double precision float would be required or a 64-bit integer.