C2 · Lesson 9 · Square waves and pulses
Rise time, ripple, tilt and averaging a PWM signal
Digital signals are square waves, and every wire and input they meet has some resistance and capacitance, so each edge becomes a little RC transient. Whether the result is a crisp square wave, a rounded one or a nearly flat average depends on one comparison: the time constant against the time between edges. The same comparison explains why a microcontroller's PWM pin can act as a cheap analog output, and why a coupling capacitor makes a long pulse sag.
- A square wave drives a high-pass RC circuit: in series, then to ground. The output spikes at each edge and decays with τ = RC.
- With τ much longer than the period, the output is the square wave with its average removed, and each flat top sags slightly: tilt.
- With τ much shorter, only the edges get through: the circuit differentiates the square wave into spikes.
Predict
A 5 V, 20 kHz PWM signal at 30% duty is smoothed by a 10 kΩ, 1 µF low-pass. About what voltage comes out?
1.5 V: the low-pass passes the average, . The time constant, 10 ms, is 200 periods long, so the capacitor barely moves within one: ripple about mV. That's how a PWM pin makes an analog voltage.
Name it
Edges and rise time
A step through an RC low-pass rises as . Its 10-90% rise time is
A square wave whose half-period is several τ long comes through with rounded but complete edges; one whose half-period is shorter never reaches the top before turning around.
The periodic steady state
After many cycles, a low-pass driven by a 0 to square wave at 50% duty swings around with a peak-to-peak ripple of
For duty , the average is and the ripple for is about . A PWM output plus a low-pass is a simple digital-to-analog converter, trading ripple against how quickly the output can change.
The high-pass side
Swap R and C and the circuit passes changes and blocks the average. For τ ≫ the pulse width , a flat pulse droops by a fraction
called tilt. For τ ≪ , the output is a spike at each edge: the circuit approximately differentiates its input, as the low-pass with τ ≫ approximately integrates it.
Rise time and bandwidth
The same RC that rounds edges limits frequency response: its bandwidth is , so , a rule used for scopes and amplifiers too (C4).
Worked example
A 0 to 5 V, 100 Hz square wave drives a 1 kΩ, 1 µF low-pass. Does the output reach the top, and what is its rise time?
Show the solution
- Time constant.
- How far each half gets. The half-period is 5 ms = 5τ, so each half reaches of the way: clean, rounded edges.
- Rise time.
Answer yes, each half reaches 99.3% of the way, and the rise time is 2.2 ms.
Worked example
The same filter at 1 kHz: what does the output look like?
Show the solution
- Compare the period with τ. Now = 1 ms equals τ, so the output never settles: it rises and falls exponentially around 2.5 V.
- Ripple. peak to peak.
Answer a rounded triangle wave around 2.5 V, with 1.22 V of ripple peak to peak.
Worked example
A microcontroller makes a voltage by filtering a 5 V PWM signal at 25% duty, 1 kHz, through an RC with τ = 100 ms. What's the output and how much does it ripple?
Show the solution
- Average output. With τ far longer than the 1 ms period, the capacitor settles to the average:
- Why it ripples. During each on-time it charges slightly and during each off-time it discharges.
- Ripple size. For τ ≫ T the peak-to-peak ripple is about
- Trade-offs. A longer τ cuts the ripple but slows the response to duty changes; a two-stage filter, or a faster PWM, does better on both.
Answer the output sits at 1.25 V with about 9.4 mV of ripple peak to peak.
Check
An RC low-pass has R = 10 kΩ and C = 1 nF. What is its 10-90% rise time?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A 0 to 3.3 V square wave at 10 kHz (50% duty) drives an RC low-pass with τ = 10 ms. What is the output ripple, peak to peak?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
A 0 to 5 V PWM signal at 10% duty is heavily low-pass filtered. What average comes out?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
Check
A 0 to 3.3 V PWM signal at 20 kHz and 20% duty is filtered with τ = 20 ms. Roughly what ripple remains?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
A pulse 10 µs long passes through a high-pass RC with τ = 1 ms. By what percentage does its flat top droop?
Check
An RC-limited system has a 10-90% rise time of 1 ns. What is its bandwidth?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
Check
A 3.3 V PWM signal at 0.25 duty is filtered by an RC whose time constant is 200 periods.
(a)
What's the output's average?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
(b)
About how much does it ripple, peak to peak?
Check
A PWM wave of amplitude V, duty D and period T is filtered by RC = t (t ≫ T).
Step 1
What's the average output?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What's the approximate peak-to-peak ripple?
Explain why
Why does a coupling capacitor make a long, flat pulse sag, but pass a short pulse almost unchanged?
A coupling capacitor and the resistance after it form a high-pass circuit: the output follows changes in the input, but any steady level makes current flow through the resistor, which slowly charges the capacitor and pulls the output back toward zero with time constant τ. During a short pulse there isn't time for much charge to build up, so the top stays nearly flat. During a pulse comparable to τ or longer, the capacitor charges substantially and the output sags visibly. Passing long pulses needs a much larger τ.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.