RC Charging
The RC Circuit: Charging
An RC circuit (resistor + capacitor in series) is the simplest circuit with memory — its behavior depends on history, not just the current input.
Vs ---[R]---+---[C]--- GND
|
V(t)
When a voltage Vs is applied, the capacitor charges exponentially:
V(t) = Vs · (1 − e^(−t / τ))
Where τ = R · C is the time constant (seconds).
The Time Constant
At t = τ: V = Vs · (1 − 1/e) ≈ 0.632 · Vs (63.2% of final voltage)
| t | V(t)/Vs |
|---|---|
| 0 | 0% |
| 1τ | 63.2% |
| 2τ | 86.5% |
| 3τ | 95.0% |
| 5τ | 99.3% (considered "fully charged") |
Physical Intuition
Initially, the capacitor is empty — all voltage drops across R and current flows freely. As the cap charges, its voltage rises, reducing the driving voltage (Vs − V_cap), which slows the current. The charging slows exponentially.
General Form (arbitrary initial voltage V₀)
V(t) = Vs + (V₀ − Vs) · e^(−t / τ)
This covers both charging (V₀ < Vs) and partial charging (V₀ > 0).
Applications
- Timing circuits (555 timer)
- Debouncing switches
- Power supply filtering
- Analog delays and integrators
Your Task
Implement double rc_charge(double vs, double v0, double r, double c, double t) that returns the capacitor voltage at time t.
Use #include <math.h> for exp.