How to measure small, spiky amounts of current?
Well, there's certainly specific current-sensing ICs. In your case, I'd "simply" go with something like:
- Use a small (e.g. 0.5 Ω) series resistor between battery and your electronics.
- Amplify the voltage across that resistor with an instrumentation amplifier
- Log that voltage, e.g. using an ADC
Problems:
- low currents · low resistance = low voltage: Your measurement accuracy will be bad due to noise
- since microcontrollers wake up very fast and go to sleep equally fast, your ADC sampling rate necessarily needs to be very high.
But as a principle, that works, and is certainly viable (although designing a stable, low-noise, high-amplification instrumentation amplifier might be nontrivial; but: there's existing instr.amp ICs that make that a lot easier).
Luckily, your problem is rather common. So: Many, including Texas Instruments, have a portfolio of current sensing amplifiers, some of which integrate both aforementioned shunt resistor AND a digital interface. See TI's product listing.
In fact, these ICs are capable of measuring current and supply voltage at the same time – and that's great to actually measure drawn power, a measure far more relevant to battery life than raw drawn current, if there's nonlinear elements (that is, for example, MCUs).
The INA233, for example, can be connected to an external shunt (let's say, 0.3 Ω) and has a resolution of 2.5 µV per ADC step. That means, a single ADC step is I = U/R = 2.5 µV / 0.3 Ω = 8.333 µA in current.
I think that device also has an automatic sampling & averaging mode, so that you can easily get good approximations even under rapidly changing load.
Also, as I just found out: the thing has an "alert" level, so that you can wake up your measurement system whenever the current rises above a configurable threshold. Nice! That way, you only need to sample occasionally.
Quick and dirty: SUPERCAPACITORS! (Also search ultracapacitor.) They'll power your system, and display the integrated current as a voltage-sag with time.
What processor Vdd, and/or battery volts were you contemplating? A capacitor naturally integrates current of course, and if you use a few-farads supercapacitor instead of a battery supply, you can measure the voltage falling over time, and precisely determine the longterm average microamps.
If your design needs a constant Vdd, choose a supercap value large enough that the voltage only sags XX percent while your test is running. Depending on average current, you might be able to get away with a few-dollars capacitor. For example, 4.7 farads at a few volts is a common supercap in surplus catalogs. (Sparkfun has some ten farad, and maximum size is Electronic Goldmine's 3000-farad boostcaps at 2.7V.) Stack 'em in series to get higher voltage limit.
Is there some device that integrates current over time at very small amounts
Yes, there are several; the oldest is an electroplating cell (the mass of plated metal represents the amp-hours)Edison patent, and electrolysis cells (gas accumulation into a capillary tube) have been used more recently. These are exactly equivalent to analyzing the battery after a long use period.
Nowadays, use digitization.
If you expect fluctuations faster than a digital sampling rate, that's fixable. A two-branch current path can be arranged, with high frequency conductance (a capacitor) that bypasses the current sensor, and a parallel low-frequency conductance (inductor and current sense element).
If you expect long-duration small current (that defeats digital sampling granularity), that's fixable, too. Add a small DC-plus-white-noise source to the DC current signal, and a fractional-bit amount of current will cause (statistically) a correct digital accumulation over large times. ADC with dither fig. 5a The DC part of the added signal must be calibrated away, though. Pseudorandom noise sources are useful for this kind of 'dither'.
Digitization and accumulation into a register (just like the Kill-a-watt) can work with easily available components, and some trickery tames its potential for mismeasurement.