Electronics & Circuits · Study deck

DAC and PWM: Loads, Filters, and Code

A PWM waveform may look smooth until the load draws current.

Voltage Vera is your guide for this deck.

analogdigitaloutput
Voltage Vera, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: An 8-bit DAC has 12.9 mV steps at 3.3V, but typical INL of +/-1 LSB means actual output can deviate by +/-12.9 mV from the ideal.
  • Explain: A common 0.22uF capacitor with 10k ohm resistance gives about 72 Hz cutoff, which is still low enough to smooth a 1 kHz PWM signal but responds more slowly.
  • Explain: the microcontroller had a new challenge. "I know the motor needs to spin at 50% speed, and I can think in numbers like 128 out of 255.
iotclass.org

Major section

Load Experience with PWM/DAC

Switch to PWM + RC filter, then increase capacitance; the output gets smoother but responds more slowly.

  • Lower PWM frequency below the filter cutoff; the ripple warning should appear.
Voltage waveform over ${maxT.toFixed(2)} ms ${simVhigh.toFixed(1)} V average ${simData.avgVoltage.toFixed(2)} V orange = PWM pulses; teal = RC filtered output; blue = true DAC level
Load Experience with PWM/DAC
iotclass.org

Major section

PWM to Analog Conversion (RC Filter)

Result:: The ideal 100 Hz design gives 0.159uF.

  • A common 0.22uF capacitor with 10k ohm resistance gives about 72 Hz cutoff, which is still low enough to smooth a 1 kHz PWM signal but responds more slowly.
  • f_cutoff should be 10-20x below PWM frequency.
  • Settling time = 5 x RC (to reach 99% of target).

Numbers to remember

100 HzResult:: The ideal 100 Hz design gives 0.159uF.
1 kHzwhich is still low enough to smooth a 1 kHz PWM signal
99%Settling time = 5 x RC (to reach 99% of target).
iotclass.org

Major section

DAC Resolution vs Accuracy

An 8-bit DAC has 12.9 mV steps at 3.3V, but typical INL of +/-1 LSB means actual output can deviate by +/-12.9 mV from the ideal.

  • For precision applications, use a higher-resolution DAC (12-bit or 16-bit) and calibrate against a known reference voltage.
  • ESP32 built-in DAC has approximately +/-1% accuracy without calibration.
  • Rule of Thumb: Usable accuracy is typically 2-3 bits fewer than advertised resolution once all error sources are combined.

Numbers to remember

12.9 mVAn 8-bit DAC has 12.9 mV steps at 3.3V
iotclass.org

Major section

For Kids: Meet the Sensor Squad!

I want to glow at half brightness, but I need a smooth amount of power, not a number!".

  • DACs are like translators who speak the language of motors and lights!
  • the battery was impressed. "So you are a reverse translator!".
  • Danny pointed to his friend PWM Pete. "Pete has a clever trick!
iotclass.org

Major section

For Kids: Meet the Sensor Squad! (continued)

the microcontroller had a new challenge. "I know the motor needs to spin at 50% speed, and I can think in numbers like 128 out of 255.

  • When Max says 128, I convert that into 1.65 volts -- just the right amount to make Lila glow at half brightness.".
  • But Temperature Terry noticed something. "Wait, Danny, you are not on every microcontroller.
  • Lila blinked. "I had no idea!
iotclass.org

Major section

DAC/PWM Actuator Control

DAC Resolution (8-bit) -> ADC Resolution: Both use the same $2^n$ idea.

  • An 8-bit DAC has 256 output levels, while a 12-bit ADC has 4,096 input levels.
  • PWM Duty Cycle -> Motor Speed Control: Average voltage is $V_{high} \times duty\_cycle$, so motors respond to the average energy delivered, not each individual pulse.
  • Cross-module connection: PWM Actuator Control: Explains how DC motors respond to PWM average voltage via back-EMF and inductance.
iotclass.org

Deck summary

Key takeaways

Switch to PWM + RC filter, then increase capacitance; the output gets smoother but responds more slowly.

  • Result:: The ideal 100 Hz design gives 0.159uF.
  • An 8-bit DAC has 12.9 mV steps at 3.3V, but typical INL of +/-1 LSB means actual output can deviate by +/-12.9 mV from the ideal.
  • I want to glow at half brightness, but I need a smooth amount of power, not a number!".
  • the microcontroller had a new challenge. "I know the motor needs to spin at 50% speed, and I can think in numbers like 128 out of 255.
iotclass.org

Retrieval practice

Recall check 1 of 2

Voltage Vera says: answer from memory, then check your reasoning.

Q1A PWM signal at 5V with a 75% duty cycle produces what average voltage?

A2.50 V
B3.75 V
C4.00 V
D5.00 V
Show answer

Answer: B

Q2An ESP32 DAC channel outputs a value of 200 with a 3.3V reference. What is the approximate output voltage?

A1.65 V
B2.00 V
C2.59 V
D3.30 V
Show answer

Answer: C V_out = V_ref x (Digital Input / (2^n - 1)) = 3.3V x (200 / 255) = 3.3V x 0.784 = 2.59V. The ESP32 has an 8-bit DAC, so the maximum digital input is 255.

iotclass.org

Retrieval practice

Recall check 2 of 2

Voltage Vera says: answer from memory, then check your reasoning.

Q3You're dimming 10 LEDs to 50% brightness. Your ESP32 has 2 DAC pins and 16 PWM-capable GPIOs. What's the best approach?

AUse 10 external MCP4725 DACs for smooth flicker-free dimming
BUse 10 PWM pins at 1kHz - human eye cannot detect flicker above 100Hz
CUse 2 DAC pins and switch between LEDs rapidly
DPWM cannot be used for LED control - only true DAC works
Show answer

Answer: B PWM at 1kHz is imperceptible to the human eye (critical flicker frequency ~60-100Hz).

iotclass.org

Print reference

Answers

Answer key.

  1. B
  2. C · V_out = V_ref x (Digital Input / (2^n - 1)) = 3.3V x (200 / 255) = 3.3V x 0.784 = 2.59V. The ESP32 has an 8-bit DAC, so the maximum digital input is 255.
  3. B · PWM at 1kHz is imperceptible to the human eye (critical flicker frequency ~60-100Hz).
iotclass.org