A method to compute an amount of energy taken from a battery coupled to a switching
power converter is disclosed. The switching power converter charges a capacitor
to a voltage and by the application of one or more control pulses to the switching
power converter the voltage on the capacitor is maintained within a predetermined
range having an upper voltage. The voltage on the capacitor is sampled and one
or more control pulses are applied to the switching power converter to raise the
voltage on the capacitor to the upper voltage. The amount of energy taken from
the battery is computed based on measurement of a change in voltage on the capacitor
over an elapsed time.