Circuits with memory
Every circuit so far has been memoryless: change a source, and every voltage and current jumps at once to its new value. Resistors respond to the present and nothing else. But real circuits take time. A microcontroller holds itself in reset for a few milliseconds after power is applied, until its supply has settled. A push-button's contacts bounce for a millisecond, and a small circuit smooths the bounces away. A relay clicks off a little after its driver lets go, and if nobody has thought about it, the transistor driving it dies.
All of these involve the two components that store energy: the capacitor, which stores it in an electric field, and the inductor, which stores it in a magnetic field. Their behaviour depends on how fast things change, so describing them needs derivatives. This level assumes you have met derivatives; if not, Lumenary Math's Introductory calculus covers what you need, and the key results below are also checked numerically.
This lesson covers circuits with one storage element, called first-order circuits because they lead to first-order differential equations. Their behaviour is always an exponential curve with a single time constant, and once you know how to find that time constant, you can sketch the response of any of them in seconds.
What capacitors and inductors are
A capacitor is two conductors separated by an insulator, the dielectric. Push current into one conductor and charge builds up there, while an equal charge builds up on the other (the current flowing out of it). No charge crosses the insulator: the current "through" a capacitor is charge piling up on one side and leaving the other. The voltage between the conductors is proportional to the charge:
where the capacitance is measured in farads (F), coulombs per volt. For two parallel plates of area a distance apart, , where is the permittivity of the dielectric. Two plates of 1 cm² separated by 0.1 mm of air give pF. A farad is enormous. Real parts range from picofarads (ceramic capacitors in radio circuits) through microfarads (ceramic and film capacitors on every board, aluminium electrolytic capacitors in power supplies) to whole farads (supercapacitors, which store energy in a layer of ions only nanometres thick).
An inductor is a coil of wire, often wound on a magnetic core. Current through it creates a magnetic field, and the field's flux linkage (the magnetic flux through the coil, counted once for every turn it threads) is proportional to the current: . The inductance is measured in henries (H). By Faraday's law, a changing flux linkage induces a voltage, . Inductors range from nanohenries (a few millimetres of circuit-board trace) through microhenries (the coils in switching power supplies) to the hundreds of millihenries of a relay coil.
Definition— The capacitor and inductor laws
With the passive sign convention (current entering the terminal):
The two laws are mirror images: swap with and with and one becomes the other. A capacitor's current depends on how fast its voltage changes; an inductor's voltage depends on how fast its current changes. Two consequences follow at once:
- At DC steady state, nothing changes, so a capacitor carries no current (it behaves as an open circuit) and an inductor has no voltage (it behaves as a short circuit).
- Combining. Capacitors in parallel add (, since their charges add at a shared voltage) and in series combine like resistors in parallel. Inductors combine like resistors: in series they add.
Theorem— Stored energy
A capacitor at voltage stores energy . An inductor carrying current stores .
Proof
The power absorbed by the capacitor is . Integrating from a moment when the capacitor was uncharged, the total energy absorbed is . None of it has been turned into heat (an ideal capacitor has no resistance), so all of it is stored and can be recovered. For the inductor, , and the same argument applies.
∎
A 100 µF capacitor at 9 V holds mJ. That is not much energy, but it can be released very quickly, and a large capacitor charged to a high voltage can hold a dangerous charge for a long time after its circuit is switched off. That is one reason never to open a camera flash, a microwave oven or a mains power supply, even when it is unplugged.
What cannot jump
Theorem— Continuity
If the current through a capacitor stays finite, its voltage is a continuous function of time. If the voltage across an inductor stays finite, its current is continuous.
Proof
Integrating the capacitor law, . If , the integral over an interval of length is at most , which goes to zero with ; so cannot change by a finite amount in zero time. The inductor's current is the integral of , and the same argument applies.
∎
This is the most useful fact for solving switching problems. At the instant a switch moves (call it ), the capacitor voltages and inductor currents just after, at , equal their values just before, at . Everything else, including capacitor currents, inductor voltages and every resistor's voltage and current, may jump, and usually does.
RC and RL transients
Charging a capacitor. In the figure, the switch closes at with the capacitor empty. For , KVL round the loop gives , and the capacitor law gives , so
Its solution with is
as you can check by differentiating: , and times that plus is . The quantity has units of seconds (ohms times farads) and is the time constant.
| Time | |||||
|---|---|---|---|---|---|
| Fraction of the way | 63.2 % | 86.5 % | 95.0 % | 98.2 % | 99.3 % |
RL circuits are the mirror image. A voltage switched across a resistor in series with an inductor gives , so the current rises as with . A 12 V supply switched across a 120 mH coil with 24 Ω of winding resistance has ms, and its current rises towards A, reaching A after 5 ms.
Both are cases of one result. A first-order circuit is one storage element connected to a linear network of resistors and constant sources, and by Thévenin's theorem that network looks, from the storage element, like in series with .
Theorem— The general first-order solution
In a circuit of resistors, constant sources and a single capacitor (or inductor ), after a switching event at , every voltage and current satisfies, for ,
where is the Thévenin resistance seen by the storage element after the switch has moved, is the value just after switching, and the final DC value.
Proof
Replace everything except the capacitor by its Thévenin equivalent. As in the charging example, , whose solutions are exactly for a constant (substitute to check; a first-order linear equation has one solution for each starting value). Setting fixes , and . Every other voltage or current is, by superposition, a constant combination of the sources and , so it has the same form with the same . The inductor case is the same with in series and the current as the variable.
∎
So a first-order transient needs only three numbers: where it starts, where it ends, and how fast. The start comes from continuity, the end from the DC steady state (capacitor open, inductor short), and from the Thévenin resistance with the sources killed.
Example— A capacitor behind a divider
A 12 V supply feeds a divider of kΩ (top) and kΩ (bottom), and a 10 µF capacitor sits across , initially empty. The supply is switched on at .
- Start: V, by continuity.
- End: with the capacitor open, the divider gives V.
- Speed: killing the supply, the capacitor sees kΩ, so ms.
So V. A common mistake is ms; but the capacitor does not charge through both resistors in series, it charges from the divider's Thévenin equivalent, 4 V behind 2 kΩ.
Example— A power-on reset delay
Many microcontrollers have a reset pin that holds the chip in reset while the pin is low. A 10 kΩ resistor from a 3.3 V supply and a 1 µF capacitor to ground ( ms) hold the pin low briefly after power-up. If a chip leaves reset when the pin rises past 70 % of the supply, the delay is the that solves :
The general rule: the time to go from to a target is . (Real chips specify their own thresholds and often include a reset circuit inside; always read the datasheet.)
Simulating a transient: forward Euler
The exponential solution exists because the circuit is so simple. A circuit with many capacitors, inductors and transistors has no formula, and a simulator must step its equations through time. The simplest scheme is forward Euler: from the present value, take a small step along the present slope,
The script charges a 100 µF capacitor from 9 V through 10 kΩ ( s) with steps of 0.1 s and compares the result with the exact curve.
import math
# RC charging: Vs = 9 V through R = 10 kΩ into C = 100 µF, starting empty.
Vs, R, C = 9.0, 10e3, 100e-6
tau = R * C # 1 second
def exact(t):
return Vs * (1 - math.exp(-t / tau))
def euler(h, t_end):
"""Forward Euler on C dv/dt = (Vs - v) / R: step along the tangent line."""
v, t, out = 0.0, 0.0, {0.0: 0.0}
for _ in range(round(t_end / h)):
v += h * (Vs - v) / (R * C) # the slope at the START of the step
t += h
out[round(t, 9)] = v
return out
h = 0.1
sim = euler(h, 5.0)
print(f"tau = {tau:.3f} s, step h = {h} s")
print(f"{'t (s)':>6} {'Euler (V)':>10} {'exact (V)':>10} {'error (mV)':>11}")
for t in [0.0, 0.5, 1.0, 2.0, 3.0, 5.0]:
print(f"{t:6.1f} {sim[t]:10.4f} {exact(t):10.4f} {(sim[t] - exact(t)) * 1e3:11.2f}")
# The exact curve, one row per 0.5 s and one # per 0.25 V.
print()
for k in range(11):
t = k * 0.5
print(f"{t:4.1f} s |" + "#" * round(exact(t) / 0.25))Forward Euler runs ahead of the true curve, by 173 mV at s: it uses the slope at the start of each step, which on a charging curve is the steepest slope in that step. How does the error shrink as the steps get smaller, and what happens when they get larger?
import math
# How the error of forward Euler depends on the step size, for dv/dt = (Vs - v) / tau.
Vs, tau = 9.0, 1.0
exact_at_1 = Vs * (1 - math.exp(-1.0))
def forward(h, steps, v=0.0):
for _ in range(steps):
v = v + h * (Vs - v) / tau
return v
print(f"{'h (s)':>8} {'v(1 s)':>9} {'error (mV)':>11} {'ratio':>6}")
prev = None
for n in [5, 10, 20, 40, 80, 160]:
h = 1.0 / n
err = forward(h, n) - exact_at_1
ratio = "" if prev is None else f"{prev / err:6.2f}"
print(f"{h:8.4f} {forward(h, n):9.5f} {err * 1e3:11.3f} {ratio}")
prev = err
# Too big a step: each step multiplies the distance from Vs by (1 - h/tau).
print()
for h in [0.5, 1.5, 2.5]:
v, trace = 0.0, []
for _ in range(8):
v = v + h * (Vs - v) / tau
trace.append(f"{v:7.2f}")
print(f"forward Euler, h = {h} tau:", " ".join(trace))
# Backward Euler uses the slope at the END of the step: v_new = v + h (Vs - v_new) / tau.
v, trace = 0.0, []
for _ in range(8):
v = (v + 2.5 * Vs / tau) / (1 + 2.5 / tau)
trace.append(f"{v:7.2f}")
print("backward Euler, h = 2.5 tau:", " ".join(trace))The cure is in the last line. Backward Euler evaluates the slope at the end of each step, which means solving a small equation per step, and it heads steadily for 9 V even with steps 2.5 times the time constant. Circuit simulators use implicit methods of this kind (backward Euler, the trapezoidal rule and Gear's methods) with automatically adjusted step sizes. They have to: a circuit can contain time constants from picoseconds to seconds, and an explicit method would need steps small enough for the fastest, everywhere. In each step, the implicit method turns every capacitor into a conductance in parallel with a current source, the companion model, and the whole circuit becomes a linear resistive network solved by the modified nodal analysis of Nodal and mesh analysis.
Here is the same RC circuit in SPICE, with a .tran (transient) analysis. The source steps from 0 to 9 V at , and meas statements read values off the simulated curve.
RC charging: 9 V through 10k into 100u
* the source steps from 0 to 9 V at t = 0 (1 us rise)
Vs in 0 PULSE(0 9 0 1u 1u 100 200)
R1 in out 10k
C1 out 0 100u IC=0
.control
tran 1m 5 uic
meas tran v_at_tau find v(out) at=1
meas tran t_63 when v(out)=5.689
meas tran t_5v when v(out)=5
meas tran v_at_5tau find v(out) at=5
.endc
.endngspice reports v_at_tau = 5.689084e+00 (the exact value is 5.6891 V), t_63 = 9.999748e-01 (the curve passes 63.2 % at one time constant), t_5v = 8.109307e-01 (the formula gives 0.8109 s) and v_at_5tau = 8.939358e+00, 99.3 % of 9 V.
The inductive kick and the flyback diode
A relay is a switch worked by an electromagnet: current through its coil pulls a contact over. A microcontroller cannot supply the coil's current, so a transistor switches it, as in the figure. When the transistor turns on, the coil current rises with . The danger is at turn-off.
Take a coil of 200 mH with 400 Ω of winding resistance (illustrative values for a small 12 V relay). While the transistor is on, the coil carries mA and stores µJ. Now the transistor turns off in, say, a microsecond. The inductor law insists:
The coil's current cannot stop instantly (continuity), so its voltage rises until something conducts. Without help, that something is the transistor, driven into breakdown, or the small stray capacitance of the wiring, which charges to a high voltage and rings. Either way the transistor is stressed or destroyed, and the spike radiates interference into nearby circuits. This is the inductive kick, and it is the same effect that the ignition coil of a petrol engine exploits on purpose to fire its spark plugs.
The fix is a flyback diode (also called a freewheeling or snubber diode) across the coil, pointing towards the supply. While the transistor is on, the diode is reverse-biased and does nothing. At turn-off, the coil's current, still flowing downwards through the coil, switches into the diode and circulates round the loop of coil and diode, decaying with ms as the coil's resistance dissipates the stored 90 µJ. The switch node rises only to 12 V plus the diode's forward voltage. Diodes are the subject of Semiconductors and diodes; here we only need that a diode conducts in the direction of its arrow once it has about 0.7 V across it, and blocks the other way.
Simulation shows both cases side by side. The netlist below has two identical drivers sharing one control signal, each coil with 100 pF of stray capacitance across its switch, and only the second with a flyback diode. The transistor is modelled as an ideal voltage-controlled switch, and the diode by a generic model, not a particular part.
Relay coil switched off, with and without a flyback diode
* Two identical drivers share one control signal. Each coil is 200 mH with 400 ohm
* of winding resistance, and 100 pF of stray capacitance sits across each switch.
* Only driver 2 has a flyback diode, from the switch node back to the supply.
Vcc vcc 0 DC 12
Vctl ctl 0 PULSE(5 0 1m 100n 100n 10 20)
L1 vcc a1 200m
R1 a1 sw1 400
C1 sw1 0 100p
S1 sw1 0 ctl 0 SWMOD
L2 vcc a2 200m
R2 a2 sw2 400
C2 sw2 0 100p
S2 sw2 0 ctl 0 SWMOD
D2 sw2 vcc DFLY
.model SWMOD SW(Vt=2.5 Vh=0.1 Ron=1 Roff=100Meg)
.model DFLY D(Is=1n N=1.8 Rs=0.5)
.control
tran 50n 3m
meas tran coil_current find i(L2) at=0.9m
meas tran peak_without_diode max v(sw1) from=1m to=1.2m
meas tran peak_with_diode max v(sw2) from=1m to=3m
meas tran half_current_at when i(L2)=15m fall=1
.endc
.endThe switches open at 1 ms. ngspice reports coil_current = 2.992519e-02 (30 mA, less a little for the switch's 1 Ω), peak_without_diode = 1.340427e+03 at 1.007 ms, and peak_with_diode = 1.283507e+01. Without the diode, the coil's energy sloshes into the 100 pF stray capacitance and the switch node rings up to 1340 V, a quarter-cycle (7 µs) after turn-off; no small transistor survives that. With the diode, the switch node peaks at 12.84 V. The coil current, now circulating through the diode, falls to half at half_current_at = 1.315361e-03, 0.315 ms after turn-off, a little sooner than the ms of a pure RL decay because the diode's forward voltage helps the resistance oppose the current.
Note
The trade-off. The diode makes the coil current decay slowly, so the relay releases later. Where fast release matters, engineers put a Zener diode in series with the flyback diode, which lets the switch node rise to a chosen higher voltage (still within the transistor's rating) and dissipates the energy faster. The same problem appears wherever inductors are switched: motors, solenoids, loudspeakers, and the inductors of every switching power supply, where Power electronics puts the stored energy to use instead of throwing it away.
Note
Safety. The kick from a small relay is enough to destroy transistors; the kick from large inductors, such as motors, big solenoids and ignition coils, can injure people. Explore these effects in simulation, or with small relays on a current-limited supply, and never break the current of a large inductive load by hand.
The professional view
Decoupling. Every digital chip has small ceramic capacitors (often around 100 nF) placed as close as possible to its supply pins. When billions of transistors switch together, the chip's current changes in nanoseconds, and the inductance of even a few centimetres of supply wiring would turn that into a large voltage dip. The nearby capacitor supplies the sudden current from its stored charge, and the supply refills it more slowly. Power supplies and noise and Printed circuit boards return to this.
Real components are not ideal. A real capacitor has an equivalent series resistance (ESR), a series inductance, leakage, and a voltage rating. The high-capacitance ceramics on most boards (class II dielectrics such as X7R) lose a large part of their capacitance as the DC voltage across them rises, and with temperature; aluminium electrolytic capacitors slowly dry out, especially when hot, and are polarised: connected backwards or above their rated voltage, they can overheat and burst, so respect the markings. A real inductor has winding resistance, capacitance between its turns, and a core that saturates: above a certain current its inductance collapses. Manufacturers in many countries, among them Murata and TDK in Japan, Samsung Electro-Mechanics in South Korea, Yageo in Taiwan, Vishay in the United States and Würth Elektronik in Germany, publish measured models of their parts, such as capacitance against bias voltage and impedance against frequency, so that designers can simulate the real component rather than the ideal one.
Time constants are design parameters. Debouncing a button, timing a reset, filtering a sensor, setting how fast a supply ramps up: each is a choice of , usually with a margin for component tolerances of 5 to 20 %. In the frequency domain, the same RC becomes a filter with a corner at , which Frequency response and filters develops. With both an inductor and a capacitor, a circuit has two storage elements and can oscillate; that is the next lesson, RLC circuits, and the 35.6 kHz ringing hidden in the relay simulation above is a preview of it.
Common misconceptions
Misconception
"A capacitor lets current through." No charge crosses the dielectric. Current flows into one plate and out of the other only while the voltage is changing. In DC steady state a capacitor carries no current: it blocks DC.
Misconception
"After five time constants, the capacitor is fully charged." An exponential never quite arrives. After it is 99.3 % of the way, which is close enough for most purposes; a 16-bit measurement, which resolves about 0.0015 %, needs more than .
Misconception
"A bigger capacitor charges to a higher voltage." The final voltage is set by the circuit's Thévenin voltage. A bigger capacitor stores more charge at that voltage and takes proportionally longer to get there.
Misconception
"Opening a switch stops an inductor's current." The current continues, at least for an instant, wherever it can: through a diode if there is one, through stray capacitance, through the switch as it breaks down, or as a spark across opening contacts.
Misconception
"Any simulation method works if the step is small enough." Small steps buy accuracy, but forward Euler is also unstable for steps larger than , and circuits mix very fast and very slow time constants. Simulators use implicit methods so that the step size is set by accuracy, not by stability.
Exercises
1. Capacitors, inductors and first-order circuits
Warm-upHumanA 4.7 kΩ resistor charges a 220 µF capacitor from a fixed supply. What is the time constant, in milliseconds?
2. Capacitors, inductors and first-order circuits
CoreHumanAn empty capacitor is charged through a resistor from a 10 V supply switched on at . What is its voltage at , to the nearest millivolt?
3. Capacitors, inductors and first-order circuits
CoreHumanA circuit contains resistors, a DC source, one capacitor and one inductor. A switch moves at . Which quantities must have the same value at as at ? Select all that apply.
4. Capacitors, inductors and first-order circuits
CoreHumanA 9 V supply feeds a divider: kΩ from the supply to node x, and kΩ from node x to ground. A 4.7 µF capacitor is connected from node x to ground. What is the time constant of the circuit, in milliseconds?
5. Capacitors, inductors and first-order circuits
CoreHumanA transistor switches a relay coil to ground from a 12 V supply, with a flyback diode across the coil (cathode at the 12 V supply, anode at the transistor). What happens at the instant the transistor turns off?
6. Capacitors, inductors and first-order circuits
CoreComputationalA first-order response is . Write crossing_time(x0, x_inf, tau, x_target) returning the time at which first equals x_target.
- Return
0.0ifx_target == x0. - Return
math.infif the response never reaches the target: if the target equalsx_inf(approached but never reached), lies beyondx_inf, or lies on the other side ofx0.
The tests include the lesson's power-on reset delay and charging examples, and a discharge.
7. Capacitors, inductors and first-order circuits
StretchComputationalSimulate an RL circuit with backward Euler. A voltage is switched across in series with , so . Backward Euler evaluates the right-hand side at the end of each step:
Write backward_euler_rl(V, R, L, h, steps, i0=0.0) returning the list . The tests check accuracy with small steps, that halving the step roughly halves the error, and that the method stays stable and never overshoots even with a step ten times the time constant.
Further reading and resources
- MIT OpenCourseWare 6.002: Circuits and ElectronicsFree lectures and notes covering capacitors, inductors and first-order transients.
- ngspice documentationThe manual describes the transient analysis, the measure command and the switch and diode models used below.
- SPICE2: A Computer Program to Simulate Semiconductor Circuits · Laurence W. Nagel · 1975Explains how a simulator integrates circuit equations through time with implicit methods and companion models.