How do devices which measure energy consumed work? For example the ones in solar regulators/chargers which display how many Ah went into the battery and how many went out?

Do they just measure the current for example every second and a microprocessor constantly adds up the measurements, assuming that the current 0.5s before and after each measurement is the same as while they take the current measurement, or do they have a way of really measuring how much energy went through, without referring to such, possibly inaccurate approximation?

## Best Answer

An MCU is not required to perform this sort of measurement. The STC3100 is a simple I2C interfaced coulomb counter that measures the charge state of a battery. It works by integrating the measured current into/out of the battery over time and providing the result in a form that can be read by the processor.

I have used this device on a couple of products and find the results better than I would have thought bearing in mind the large variations in the load current that can be seen, in my case the load current varies over at least 4 orders of magnitude. The errors due to the sampling of the varying current seem to cancel out over time.