C730 of 57
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C7 · Lesson 30 · PWM and sigma-delta outputs

Making an analog level from a counter, a comparator or an accumulator, and how fast its ripple dies

Digital chips have plenty of pins that can only be 0 or 1, yet they dim LEDs smoothly, set motor speeds and even play audio. The trick is to switch fast and let something slow average it: an RC filter, a motor's inductance, an eye. A counter and a comparator from lesson 29 make pulse-width modulation, whose average is the fraction of each period spent high. An adder and a register make a sigma-delta bitstream with the same average but its 1s spread out as evenly as possible, which pushes the ripple to much higher frequencies where a filter removes it easily.

  • A first-order sigma-delta modulator built from a 3-bit accumulator. On each clock it adds the input X (0 to 7) to the accumulator, and the carry out of that addition is the output bit.
  • With X = 2 (binary 010), the output is 1 on one clock in every four: an average of 2/8. Change X and watch the density of 1s follow it, always as evenly spread as the clock allows.

Predict

An 8-bit PWM and an 8-bit sigma-delta modulator both run from a 16 MHz clock with an input of 64 (a quarter of full scale), and both feed the same RC filter. How do their ripples compare?

Name it

Pulse-width modulation

An N-bit counter counts from 0 to 2N−1 and wraps; a comparator sets the output high while the count is below the input code k. The duty cycle is D=k/2N, the frequency is

fPWM=fclk2N

and the average output is DVDD, with steps of VDD/2N. Resolution and frequency trade off: each extra bit halves the PWM frequency.

Filtering and ripple

An RC low-pass with RC≫T passes the average and shrinks the ripple. During the high time DT, the capacitor charges with current about (V−DV)/R, so the peak-to-peak ripple is

ΔV≈VD(1−D)TRC

largest at 50% duty. Higher frequency or a slower filter reduces it; a slower filter also slows the response to a new code, with time constant RC.

First-order sigma-delta

Replace the counter with an accumulator: every clock, add k to an N-bit register and output the carry. The carries come at an average rate k/2N, the same as the PWM's duty, but spread as evenly as possible: the 1s and 0s alternate as often as the code allows. For k=2N/m, the pattern repeats every m clocks, so the ripple is m/2N times the PWM's. This is the same idea as the delta-sigma converters of signal processing, here in its simplest form: the accumulator keeps the running error, and the output corrects it on every clock.

The catch: many more edges per second, which cost switching power and, on a long trace or a driver with slow edges, add error from unequal rise and fall times. PWM is usually preferred for power stages, sigma-delta for references and audio.

Worked example

A 16 MHz microcontroller makes PWM with an 8-bit and a 10-bit counter. What are the PWM frequency and voltage step for each on 3.3 V?

Show the solution
  1. 8-bit counter. The PWM frequency and the voltage step are 16MHz256=62.5kHz3.3V256=12.9mV
  2. 10-bit counter. 16MHz1024=15.6kHz3.3V1024=3.2mV
  3. The trade-off. Four times the resolution costs four times the period, and so, for the same filter, four times the ripple.

Answer 62.5 kHz with 12.9 mV steps for 8 bits, and 15.6 kHz with 3.2 mV steps for 10 bits.

Worked example

The 8-bit PWM (3.3 V, 62.5 kHz) feeds an RC filter with RC = 1 ms. Find the worst-case ripple, and the time constant needed to bring it under one LSB.

Show the solution
  1. Worst-case ripple. At D = 0.5, with T = 16 µs: ΔV≈3.3×0.25×16μs1ms=13.2mV about one LSB (12.9 mV) already.
  2. A quarter LSB. Getting comfortably below, say to a quarter LSB, needs RC of about 4 ms.
  3. The cost. That makes the output take about 5RC = 20 ms to settle after a change, the PWM digital-to-analog converter's basic trade-off.

Answer about 13.2 mV, one LSB; a quarter LSB needs RC of about 4 ms, which takes about 20 ms to settle.

Worked example

An 8-bit sigma-delta modulator at 16 MHz is given k = 64 and feeds the same 1 ms filter. What pattern does it produce, and what ripple?

Show the solution
  1. The pattern. Adding 64 each clock to an 8-bit accumulator carries every fourth clock: 0001 repeating, a 4 MHz pattern whose high time is one clock, 62.5 ns.
  2. Its ripple. ΔV≈3.3×0.25×0.75×4×62.5ns1ms=0.155mV
  3. The PWM at the same code. ΔV≈3.3×0.1875×16μs1ms=9.9mV
  4. Compare. The sigma-delta ripple is 64 times less, so the filter could be 64 times faster for the same ripple.

Answer 0001 repeating at 4 MHz, with about 0.155 mV of ripple, 64 times less than the PWM's 9.9 mV.

Check

A PWM generator runs its 8-bit counter from a 16 MHz clock. What is the PWM frequency, in kHz?

Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.

Check

A 3.3 V PWM at 62.5 kHz and duty 0.2 drives an RC filter with RC = 10 ms. What's the peak-to-peak ripple, in mV?

Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.

Check

A 3.3 V, 8-bit PWM from a 64 MHz clock must have at most 1 LSB of ripple at its worst duty. What filter time constant does it need?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Check

A 10-bit first-order sigma-delta should output a 1 once every 4 clocks. What input code does that?

Check

For an 8-bit code k=28/4, by what factor is the sigma-delta's ripple smaller than the PWM's through the same slow filter? (Give the ratio of sigma-delta to PWM.)

Check

A designer uses a sigma-delta output to drive the gate of a large power MOSFET switching a motor. Why might PWM be the better choice there?

Check

Derive the PWM ripple through an RC filter with RC≫T.

Step 1

The capacitor sits near the average DV. What current flows into it while the output is high?

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°.

Check

Simulate both modulators through an RC filter. With an N-bit counter (6) and code k = 5, build 64 periods' worth of bits (64⋅2N clocks) for PWM (1 while count < k) and for the sigma-delta (carry of an N-bit accumulator starting at 0). Filter each with the exact one-pole update v = v + (b - v)*a per clock, a = 1 - exp(-1/50) (RC = 50 clocks), starting from v = k/2**N. Over the last two PWM periods, set pwm_pp and sd_pp to the peak-to-peak values, and ratio = sd_pp/pwm_pp.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a sigma-delta bitstream have less ripple after a filter than PWM at the same average and clock rate, even though both contain the same number of 1s per 2N clocks?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.