---
title: Square waves and pulses through RC circuits
heading: Rise time, ripple, tilt and averaging a PWM signal
eyebrow: C2 · Lesson 9 · Square waves and pulses
xp: 40
---

::: hook
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.
:::

::: play
- A square wave drives a high-pass RC circuit: $C$ in series, then $R$ 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.
:::
:::

```sim circuit
V1 in 0 square 0 5 1k Hz    @ 0,0 down
C1 in out 100n              @ 0,0 right
R1 out 0 10k                @ 2,0 down
slider: R1 100..1M log
slider: C1 1n..10u log
slider: V1.f 10..10k log
scope: v(in), v(out)
time: 0..5m s
meter: v(out)
```

::: 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?

- [ ] 5 V
- [ ] 3.5 V
- [x] 1.5 V, with a few millivolts of ripple
- [ ] 1.5 V, with about a volt of ripple

::: reveal
1.5 V: the low-pass passes the average, $DV = 0.3 \times 5$. The time constant, 10 ms, is 200 periods long, so the capacitor barely moves within one: ripple about $V D(1 - D)\frac{T}{\tau} = 5 \times 0.21 \times \frac{50\text{ µs}}{10\text{ ms}} = 5$ mV. That's how a PWM pin makes an analog voltage.
:::
:::

::: nameit
## Edges and rise time

A step through an RC low-pass rises as $1 - e^{-t/\tau}$. Its **10-90% rise time** is

$$t_r = \tau\ln 9 = 2.2\tau$$

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 $V$ square wave at 50% duty swings around $V/2$ with a peak-to-peak ripple of

$$V\tanh\frac{T}{4\tau} \approx \frac{VT}{4\tau}\quad(\tau \gg T)$$

For duty $D$, the average is $DV$ and the ripple for $\tau \gg T$ is about $VD(1 - D)\frac{T}{\tau}$. 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 $t_p$, a flat pulse droops by a fraction

$$1 - e^{-t_p/\tau} \approx \frac{t_p}{\tau}$$

called **tilt**. For τ ≪ $t_p$, the output is a spike at each edge: the circuit approximately differentiates its input, as the low-pass with τ ≫ $T$ approximately integrates it.

## Rise time and bandwidth

The same RC that rounds edges limits frequency response: its bandwidth is $f_\text{3dB} = \frac{1}{2\pi\tau}$, so $t_r = \frac{0.35}{f_\text{3dB}}$, a rule used for scopes and amplifiers too (C4).
:::

::: 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?

::: solution
1. **Time constant.**
   $$\begin{aligned} \tau &= RC \\ &= 1\ \text{k}\Omega \times 1\ \mu\text{F} \\ &= 1\ \text{ms} \end{aligned}$$
2. **How far each half gets.** The half-period is 5 ms = 5τ, so each half reaches
   $$1 - e^{-5} = 99.3\%$$
   of the way: clean, rounded edges.
3. **Rise time.**
   $$\begin{aligned} t_r &= 2.2 \times 1\ \text{ms} \\ &= 2.2\ \text{ms} \end{aligned}$$

**Answer:** yes, each half reaches 99.3% of the way, and the rise time is 2.2 ms.
:::
:::

::: example
## The same filter at 1 kHz: what does the output look like?

::: solution
1. **Compare the period with τ.** Now $T$ = 1 ms equals τ, so the output never settles: it rises and falls exponentially around 2.5 V.
2. **Ripple.**
   $$\begin{aligned} \Delta v &= 5\tanh\frac14 \\ &= 1.22\ \text{V} \end{aligned}$$
   peak to peak.

**Answer:** a rounded triangle wave around 2.5 V, with 1.22 V of ripple peak to peak.
:::
:::

::: 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?

::: solution
1. **Average output.** With τ far longer than the 1 ms period, the capacitor settles to the average:
   $$5 \times 0.25 = 1.25\ \text{V}$$
2. **Why it ripples.** During each on-time it charges slightly and during each off-time it discharges.
3. **Ripple size.** For τ ≫ T the peak-to-peak ripple is about
   $$\begin{aligned} \Delta v &\approx V\frac{D(1 - D)T}{\tau} \\ &= 5\ \text{V} \times \frac{0.25 \times 0.75 \times 1}{100} \\ &= 9.4\ \text{mV} \end{aligned}$$
4. **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
given: R = 1 | 10 | 100; C = 1 | 10
answer: 2.2*R*C
unit: µs
tolerance: 0.5%

## An RC low-pass has R = {R} kΩ and C = {C} nF. What is its 10-90% rise time?

::: right
Right. $2.2\tau$ = {answer}.
:::

::: misses
- [R*C] That's τ; the 10-90% rise takes $\ln 9 \approx 2.2$ time constants.
- [any] Not yet. $t_r = 2.2RC$.
:::
:::

::: check
given: V = 3.3 | 5; f = 10 | 50; tau = 1 | 10
answer: V*tanh(1/(f*1000)/(4*tau/1000))*1000
unit: mV
tolerance: 0.5%

## A 0 to {V} V square wave at {f} kHz (50% duty) drives an RC low-pass with τ = {tau} ms. What is the output ripple, peak to peak?

::: right
Right. $V\tanh\frac{T}{4\tau}$ = {answer}.
:::

::: misses
- [V*1/(f*1000)/(tau/1000)*1000] The ripple is about $\frac{VT}{4\tau}$ for a 50% square wave.
- [any] Not yet. $V\tanh(T/4\tau)$.
:::
:::

::: check
given: V = 3.3 | 5 | 12; D = 10 | 25 | 60
answer: V*D/100
unit: V
tolerance: 0.5%

## A 0 to {V} V PWM signal at {D}% duty is heavily low-pass filtered. What average comes out?

::: right
Right. $DV$ = {answer}.
:::

::: misses
- [V*(1 - D/100)] The output is high for the fraction $D$ of each period.
- [any] Not yet. The average of the waveform.
:::
:::

::: check
given: V = 3.3 | 5; D = 20 | 50; f = 1 | 20; tau = 5 | 20
answer: V*(D/100)*(1 - D/100)/(f*1000)/(tau/1000)*1000
unit: mV
tolerance: 0.5%

## A 0 to {V} V PWM signal at {f} kHz and {D}% duty is filtered with τ = {tau} ms. Roughly what ripple remains?

::: right
Right. $VD(1 - D)\frac{T}{\tau}$ = {answer}.
:::

::: misses
- [any] Not yet. The capacitor ramps at about $V(1 - D)/\tau$ for the on-time $DT$.
:::
:::

::: check
given: tp = 10 | 100; tau = 1 | 10
answer: 100*(1 - exp(-tp/1000/tau))
tolerance: 0.5%

## A pulse {tp} µs long passes through a high-pass RC with τ = {tau} ms. By what percentage does its flat top droop?

::: right
Right. $1 - e^{-t_p/\tau}$ = {answer}%.
:::

::: misses
- [any] Not yet. Tilt is $1 - e^{-t_p/\tau} \approx t_p/\tau$.
:::
:::

::: check
given: tr = 0.35 | 1 | 7
answer: 0.35/tr*1000
unit: MHz
tolerance: 0.5%

## An RC-limited system has a 10-90% rise time of {tr} ns. What is its bandwidth?

::: right
Right. $0.35/t_r$ = {answer}.
:::

::: misses
- [1/tr*1000] For a single RC, $f_\text{3dB}t_r = 0.35$.
- [any] Not yet. $f_\text{3dB} = 0.35/t_r$.
:::
:::

::: check
kind: parts
given: V = 3.3 | 5; D = 0.25 | 0.5 | 0.8; r = 50 | 200

## A {V} V PWM signal at {D} duty is filtered by an RC whose time constant is {r} periods.

::: part
answer: V*D
unit: V
tolerance: 0.5%

### What's the output's average?

::: misses
- [any] $DV$.
:::
:::

::: part
answer: V*D*(1 - D)/r*1000
unit: mV
tolerance: 1%

### About how much does it ripple, peak to peak?

::: misses
- [any] $V\frac{D(1 - D)T}{\tau}$.
:::
:::
:::

::: check
kind: derivation
vars: V = 1..12, D = 0.01..0.99, T = 0.00001..0.01, t = 0.001..1

## A PWM wave of amplitude V, duty D and period T is filtered by RC = t (t ≫ T).

::: step
answer: D*V

### What's the average output?
:::

::: step
answer: V*D*(1 - D)*T/t

### What's the approximate peak-to-peak ripple?
:::

::: right
Right. The ripple is worst at 50% duty.
:::
:::

::: explain
## Why does a coupling capacitor make a long, flat pulse sag, but pass a short pulse almost unchanged?

::: model
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

::: check
given: R = 1 | 10; C = 0.1 | 1
answer: R*C
unit: ms
tolerance: 0.5%

## What is the time constant of {R} kΩ and {C} µF?

::: misses
- [any] $\tau = RC$.
:::
:::

::: check
given: f = 100 | 1000; tau = 0.1 | 1
answer: 1/(2*f)/(tau/1000)
tolerance: 0.5%

## A square wave at {f} Hz meets τ = {tau} ms. How many time constants long is each half-period?

::: misses
- [any] $T/2$ divided by τ.
:::
:::

::: check
given: n = 1 | 3 | 5
answer: 100*(1 - exp(-n))
tolerance: 0.5%

## What percentage of a step has an RC output completed after {n} time constants?

::: misses
- [any] $1 - e^{-n}$.
:::
:::
:::
