Calculation of the charge and discharge amount of a capacitor