Charging discharging and energy storage of capacitors