C2 · Lesson 13 · Measurements lab
Fitting time constants, the energy lost in charge sharing, impedance sweeps, PWM ripple and an inductor's saturation, in Python
Lessons 1 to 11 gave capacitors and inductors simple laws and then complicated them: real parts have ESR and ESL, energy goes missing when capacitors share charge, a PWM filter never quite settles, and inductors saturate. On the bench these show up as data: a decaying trace, an impedance curve, a current ramp that steepens. In this lab you'll turn such data into numbers, and check the formulas from the lessons against simulations that don't assume them.
- The curve is a real capacitor's impedance against frequency: its capacitance dominates at low frequency, its ESR at the bottom of the dip, and its ESL above.
- The dip, at , is the self-resonant frequency, and its depth is the ESR.
- Change the ESL, as a different package or longer leads would, and watch the useful range shrink. Step 3 finds the dip by a sweep.
Predict
A 10 µF capacitor at 10 V is connected to an empty 10 µF capacitor through a resistor. Does the energy lost depend on the resistor?
Half is lost for any resistance. A small resistor carries a huge current briefly; a large one a small current for a long time; and comes out the same, . Step 2 integrates the current numerically for very different resistors to show it.
Name it
Fitting an exponential
A decay becomes a straight line in : slope . Fitting a line to against t uses every sample, not just two, so noise averages down. Points near zero, where noise dominates the logarithm, should be left out.
Charge sharing
When a capacitor at V charges another through R, the current is with , and the energy dissipated is , independent of R.
Impedance of a real capacitor
A capacitor with ESR R and ESL L has . A logarithmic sweep finds the minimum at , with = R there.
PWM ripple exactly
A PWM wave of amplitude V, duty D and period T through an RC settles into a sawtooth whose exact peak-to-peak value is
which tends to when τ ≫ T.
Inductance from a current ramp
With a known voltage across an inductor, its current ramps at . Differencing a measured ramp gives L at each current, and where the slope steepens, the core is saturating.
Worked example
A capacitor discharges through a resistor; samples of its voltage, with noise, fall from 5 V. How do you get τ from them?
Show the solution
- Keep the clean samples. Use the samples above about 10% of the start, where noise is small compared with the signal.
- Fit a line to their logarithms. Take the logarithm of each sample and fit a straight line against time: The slope is and the intercept .
- How close it gets. With 100 samples over two time constants and 10 mV of noise, the fit lands within about 1% of the true τ.
- Compare with one point. Reading τ from a single point, the time to fall to 37%, uses one noisy sample and an eyeballed crossing.
- Where it's used. The fit is how an automated tester measures a capacitor's value through a known resistor.
Answer fit a straight line to the logarithm of the samples above about 10% of the start; its slope is , which gives τ within about 1% here.
Worked example
Integrate the loss when 10 µF at 10 V charges an empty 10 µF through 10 Ω, and through 1 kΩ.
Show the solution
- With 10 Ω. τ = 50 µs and the current starts at 1 A.
- With 1 kΩ. τ = 5 ms and the current starts at 10 mA.
- Integrate the loss. Integrating numerically over ten time constants gives 250 µJ in both cases, matching
- Compare with the stored energy. That's half of the 500 µJ stored at the start.
- How to avoid it. Only adding an inductor, as switched-mode converters do, avoids the loss, by moving charge without a large voltage across a resistance.
Answer 250 µJ is lost with either resistor, half of the 500 µJ stored at the start.
Worked example
How exact is the ripple estimate for a 5 V, 25% PWM wave with τ = 100T, 10T and 3T?
Show the solution
- Exact ripple. The exact formula gives 9.375 mV, 93.7 mV and 312 mV.
- Estimated ripple. The estimate gives 9.375, 93.75 and 312.5 mV.
- Compare. Even at τ = 3T the estimate is only 0.2% high.
- Why it works. The estimate assumes the capacitor's voltage barely changes during a period, so its current stays nearly constant through each phase.
- Why it works so well. The errors in the on and off phases nearly cancel, so the approximation holds surprisingly well and is good enough for design work.
Answer very close: the estimate is at most 0.2% high, even at τ = 3T.
Check
Step 1. Write fit_tau(t, v, floor) returning τ from a least-squares line through against t, using only samples with v > floor.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write share_loss(C1, C2, V, R) returning the energy dissipated in R when C1 at V charges an empty C2, by integrating numerically (trapezoid rule, 100 000 points over ten time constants).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write impedance(f, C, L, R) returning |Z| of a capacitor with ESL L and ESR R, and srf(C, L, R) returning the frequency of minimum |Z| from a sweep of 20 001 log-spaced points between 1 kHz and 10 GHz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 4. Write pwm_ripple(V, D, T, tau) returning the exact steady-state peak-to-peak ripple of an RC-filtered PWM wave, by iterating the on and off exponentials for many periods until it settles.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 5. Write inductance_curve(t, i, V) returning (i_mid, L): the inductance at each step of a measured current ramp, from , at the midpoint currents.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor's voltage falls from 3 V to 1 V in 2 ms.
(a)
What's its time constant?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How long from the start until it reaches 50 mV?
Check
A 1 µF capacitor at 12 V charges an empty 1 µF one through a resistor. How much energy does the resistor dissipate?
Write units the way you normally would: 1.5 µJ, 1500 nJ and 0.0015 mJ are the same answer.
Check
A 3.3 V PWM wave at 0.2 duty passes through an RC with τ = 5 periods. What's its exact peak-to-peak ripple?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
A 22 µH inductor has 5 V across it. How long does its current take to rise by 0.2 A?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Explain why
Why does fitting a straight line to the logarithm of a decay give τ more reliably than timing when the voltage reaches 37%?
The 37% point uses one sample and an estimate of exactly where the trace crosses a level, so any noise on that sample, or on the starting value it's referred to, goes straight into τ. Taking the logarithm turns the whole exponential into a straight line, and a least-squares fit uses every sample along it; random errors partly cancel, so the slope, and τ, come out far more precisely. The fit also shows whether the decay really is a single exponential: if the logarithm curves, there's a second time constant, such as dielectric absorption in the capacitor, which a single crossing would miss.
Practice
Keep practicing
6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.