Recipe
Size an RC filter for PWM
Use when: a PWM pin must give a nearly steady voltage, for a reference, a slow analog input, or a sensor test
Goal: a filter whose ripple is small enough and whose response is fast enough, at the highest PWM frequency available
Taught in From PWM to analog
Quick recipe
-
1
Decide the largest ripple you can accept and the slowest response you can tolerate.
Example
Ripple under 50 mV; settle within 100 ms.
Why: the filter is a trade, and you need both ends before you can choose.
-
2
Response ≈ 5τ, so τ ≤ response / 5.
Example
τ ≤ 100/5 = 20 ms.
Why: a filter slower than this misses the deadline whatever its ripple.
-
3
Use V_H \times 0.25 \times T/\tau, the worst case.
Example
At 490 Hz: 5 \times 0.25 \times 2.04/20 \approx 0.13 V, too much. At 5 kHz: 5 \times 0.25 \times 0.2/20 = 12.5 mV. Done.
- under the limit — done; choose R and C for that τ.
- over it — raise the PWM frequency, then recheck.
Why: raising the frequency is the only change that cuts ripple without slowing the response.
-
4
Pick R of a few kΩ to tens of kΩ and the C that gives τ; make sure whatever reads the output has a resistance far above R.
Example
τ = 20 ms: 20 kΩ and 1 μF.
Why: a load comparable to R divides the output down.
Common mistakes
- Making τ huge "to be safe" and wondering why the output takes seconds to move.
- Estimating ripple at a low duty cycle and missing the 50% worst case.
- Reading the filtered output with a load that drags it down.