Charging and discharging through an R-C circuit