Actuators & Control · Study deck

PWM Control: Frequency and Driver Decisions

A PWM rate that is quiet for one motor may waste power in another driver.

Motor Max is your guide for this deck.

control
Motor Max, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: A linear regulator or series resistor would burn the unused energy as heat, while a MOSFET PWM driver spends most of its time either fully on with low resistance or fully off with almost no current.
  • Explain: Pulse height remains 12 V while high-time and the marked ideal average rise; the actuator's inductance and inertia smooth the physical response rather than turning the switch output into a literal intermediate supply voltage.
  • Explain: A brushed DC motor in a quiet room is often set near 20 kHz so the switching tone is above normal hearing.
iotclass.org

Major section

Choosing PWM Frequency: Decision Factors

The table turns those checks into actuator-specific starting ranges rather than universal limits.

  • The PWM frequency is not arbitrary -- it must match the actuator's physical characteristics and the application's requirements.

Key terms

Position
Position is encoded as pulse width (1-2 ms) within this period.
Fast switching
Fast switching is unnecessary because the element's temperature changes over seconds, not milliseconds.
iotclass.org

Major section

For Kids: Meet the Actuator Crew!

"I have a superpower," announced the microcontroller. "I can make things go fast or slow, bright or dim, even though I can only say ON or OFF!".

  • "That doesn't make sense," said Temperature Terry. "How can you make something half-bright if you can only turn it fully on or fully off?".
  • Max grinned. "Watch this!" He started flicking the LED on and off -- really, really fast. "Lila, how do you feel?".
  • If I keep you ON for 25% of the time, you glow at quarter brightness.
iotclass.org

Major section

For Kids: Meet the Actuator Crew! (continued)

"I feel. Kind of medium bright!" Lila said, glowing at about half her usual brightness. "But I can tell you're flickering me!".

  • And the best part is, I only use as much of Bella's energy as needed.
  • At 50% duty cycle, we use about half the power!".
  • "I like that," said Bella, smiling. "More power saved means I last longer!".
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode

PWM is not a middle voltage.

  • The switch still reaches the full supply; duty cycle changes how long that state lasts in each period.
  • At 20 kHz, one PWM period is 1 / 20000 = 50 microseconds.
  • The ideal average motor terminal voltage is 12 x 0.35 = 4.2 V.

Key terms

With 8-bit PWM there
With 8-bit PWM there are 256 codes, so one step is 1 / 255 = 0.392%.

Why it matters

The output still slams between 0 V and the full supply; the actuator responds to the time average because it cannot react to every fast pulse.

PWM changes average actuator output by changing the high-time inside each period; with a 12 V supply, 25%, 50%, and 75% duty cycles ideally average to 3 V, 6 V, and 9 V.
PWM changes average actuator output by changing the high-time inside each period; with a 12 V supply, 25%, 50%, and 75% duty cycles ideally average to 3 V, 6 V, and 9 V.
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode (continued)

An LED dimmer should avoid visible flicker, so 500 Hz to a few kHz is usually fine.

  • A 35% command keeps the switch on for 0.35 x 50 = 17.5 microseconds and off for 32.5 microseconds.
  • The same arithmetic explains why PWM is efficient.
  • Many drivers use mixed decay.
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode (continued)

If a small fan draws 0.5 A at full speed, full electrical input is about 12 V x 0.5 A = 6 W.

  • Pulse height remains 12 V while high-time and the marked ideal average rise; the actuator's inductance and inertia smooth the physical response rather than turning the switch output into a literal intermediate supply voltage.
  • On an 8-bit PWM channel the requested register value is round(0.35 x 255) = 89; on a 10-bit channel it is round(0.35 x 1023) = 358.
  • On a motor, the off-time is not empty.
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode (continued)

The winding is an inductor, and an inductor resists sudden current changes.

  • The motor still receives 12 V pulses, not a smooth 4.2 V source, but its winding inductance and rotor inertia make the shaft respond mostly to average torque.
  • A brushed DC motor in a quiet room is often set near 20 kHz so the switching tone is above normal hearing.
  • A quick ripple estimate shows why frequency matters.
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode (continued)

A linear regulator or series resistor would burn the unused energy as heat, while a MOSFET PWM driver spends most of its time either fully on with low resistance or fully off with almost no current.

  • At 50 Hz, a 1.5 ms center pulse is only 1.5 / 20 = 7.5% duty, but changing that duty changes the decoded angle rather than average motor voltage directly.
  • With 8-bit PWM there are 256 codes, so one step is 1 / 255 = 0.392%.
  • The current slope is di/dt = V/L = 8 / 0.001 = 8000 A/s.
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode (continued)

During each on-pulse current ramps up; during the off-time it keeps flowing through a freewheeling path.

  • On a 12 V motor that is about 12 x 0.00392 = 47 mV of ideal average-voltage change per step.
  • With 12-bit PWM there are 4096 codes, so one step is 1 / 4095 = 0.0244%, or about 2.9 mV on the same supply.
  • The power stage must also survive the switching.
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode (continued)

Higher resolution helps slow LED fades and low-speed motor tuning, but timer hardware usually trades frequency against resolution.

  • In slow decay, the H-bridge shorts the motor terminals so current recirculates and decays gently, which improves low-speed smoothness.
  • In fast decay, the driver applies reverse voltage or returns energy toward the supply, so current drops quickly; this tracks commands better but increases ripple.
  • If the shaft is already spinning so back-EMF is 4 V, the on-pulse applies roughly 12: 4 = 8 V across the winding.
iotclass.org

Major section

Deep Dive: Duty Cycle, Ripple Current, and Decay Mode (continued)

At 20 kHz and 35% duty, on-time is 17.5 microseconds, so the current rises by about 8000 x 17.5e-6 = 0.14 A during the on-pulse.

  • That larger ripple can produce audible vibration, rough torque, and extra heating even though the average duty cycle is unchanged.
  • The waveform is digital at the pin, but the motor current, heat, and electromagnetic noise are analog consequences.
  • The output still slams between 0 V and the full supply; the actuator responds to the time average because it cannot react to every fast pulse.
iotclass.org

Deck summary

Key takeaways

The table turns those checks into actuator-specific starting ranges rather than universal limits.

  • "I have a superpower," announced the microcontroller. "I can make things go fast or slow, bright or dim, even though I can only say ON or OFF!".
  • "I feel. Kind of medium bright!" Lila said, glowing at about half her usual brightness. "But I can tell you're flickering me!".
  • PWM is not a middle voltage.
  • An LED dimmer should avoid visible flicker, so 500 Hz to a few kHz is usually fine.
iotclass.org

Retrieval practice

Recall check 1 of 4

Motor Max says: answer from memory, then check your reasoning.

Q1A DC motor driven by PWM runs at the right speed but emits an annoying high-pitched whine, and you want smoother low-speed current. Which two changes address these, and why?

ARaise frequency above ~20 kHz and use slow decay
BLower the duty cycle to remove the whine, since duty cycle sets the switching frequency.
CRemove the H-bridge so the motor sees a pure DC average with no switching noise.
DAdd a series resistor to drop the average voltage instead of using PWM.
Show answer

Answer: A Duty cycle sets the average level while frequency sets smoothness/audibility (raise above ~20 kHz to silence whine); the winding's inductance averages the current, and slow (recirculating) decay reduces ripple for smoother low-speed control.

iotclass.org

Retrieval practice

Recall check 2 of 4

Motor Max says: answer from memory, then check your reasoning.

Q2An ESP32 is using 8-bit PWM resolution to control an LED. What PWM value should you write to achieve approximately 75% brightness?

A75
B128
C191
D255
Show answer

Answer: C Answer: C) 191.

Q3Why must servo motors use exactly 50 Hz PWM frequency rather than the 5 kHz or 20 kHz used for DC motors?

AServos need higher frequency so the motor can reach each angle
BServo electronics decode pulse width within each 20ms frame
CHigher motor PWM always damages servo control electronics
DFifty hertz reduces battery drain compared with 20 kHz
Show answer

Answer: B Answer: B) The servo's internal control circuit interprets pulse width within a 20ms period to determine angle position.

iotclass.org

Retrieval practice

Recall check 3 of 4

Motor Max says: answer from memory, then check your reasoning.

Q4An ESP32 controls an LED brightness using PWM at 1 kHz with 50% duty cycle. The LED appears at roughly half brightness. If the PWM frequency is lowered to 30 Hz (still 50% duty cycle), what will the user notice?

AThe LED will appear brighter because lower frequencies deliver more power
BThe LED will appear dimmer because the lower frequency reduces average current
CNo visible difference since the duty cycle remains the same
DThe LED will visibly flicker because 30 Hz is below flicker fusion
Show answer

Answer: D PWM works for dimming because the human eye perceives the time-averaged brightness when switching is faster than the flicker fusion threshold (~60-70 Hz).

iotclass.org

Retrieval practice

Recall check 4 of 4

Motor Max says: answer from memory, then check your reasoning.

Q5Place each PWM responsibility where it lives so you can tune average drive without mistaking a command waveform for measured actuator motion.

AFrequency and Duty Command
BTimer PWM Waveform
CPower Driver and Load
DMeasured Actuator Response
Show answer

Answer: A tune average drive without mistaking a command waveform for measured actuator motion.

Q6Complete the PWM configuration to fade an LED:

Aled_pwm = PWM(Pin(2), freq=5000)
Bled_pwm = Pin(2, Pin.OUT)
Cled_pwm = PWM(2, mode=OUTPUT)
Dled_pwm = Pin.PWM(2, 5000)
Show answer

Answer: A PWM is initialized with a pin and frequency.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. A · Duty cycle sets the average level while frequency sets smoothness/audibility (raise above ~20 kHz to silence whine); the winding's inductance averages the current, and slow (recirculating) decay reduces ripple for smoother low-speed control.
  2. C · Answer: C) 191.
  3. B · Answer: B) The servo's internal control circuit interprets pulse width within a 20ms period to determine angle position.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. D · PWM works for dimming because the human eye perceives the time-averaged brightness when switching is faster than the flicker fusion threshold (~60-70 Hz).
  2. A · tune average drive without mistaking a command waveform for measured actuator motion.
  3. A · PWM is initialized with a pin and frequency.
iotclass.org