How to compute capacitor charge/discharge time through a resistor using Python

You can easily compute the time it takes to charge or discharge a capacitor through a resistor using the UliEngineering Python library:

capacitor_resistor_charge_discharge_time.py
from UliEngineering.Electronics.Capacitors import *
from UliEngineering.EngineerIO import *

# Compute the charge time of a 100uF capacitor through 10k from a 5V source
# through a Schottky diode with 0.3V forward voltage, up to 3.0V
charge_time = capacitor_resistor_charge_time(
    capacitance="100uF", resistance="10kΩ", source_voltage="5V",
    initial_voltage="0V", target_voltage="3.0V", diode_voltage="300mV"
)

# Compute the discharge time of the same capacitor through 10k to 1.0V
# through a silicon diode with 0.7V forward voltage
discharge_time = capacitor_resistor_discharge_time(
    capacitance="100uF", resistance="10kΩ", initial_voltage="5.0V",
    target_voltage="1.0V", diode_voltage="700mV"
)

# Auto-format & print the results
print(f"Charge time: {format_value(charge_time, 's')}")
print(f"Discharge time: {format_value(discharge_time, 's')}")

Example output

capacitor_resistor_charge_discharge_time_output.txt
Charge time: 1.02 s
Discharge time: 2.66 s

Check out similar posts by category: Electronics, Python