LearnViz CompSci
Home / Learn / Mobile, Embedded & IoT / PWM

Intermediate Topic 20 of 50 Mobile, Embedded & IoT

PWM

Pulse patterns controlling power or brightness.

How it works

Pulse-width modulation encodes an analog level in a digital signal by switching a pin on and off rapidly and varying the duty cycle, the fraction of each period the signal is high. The average voltage seen by a slow load is proportional to the duty cycle, so a 25 percent duty cycle on a 5 volt signal averages 1.25 volts. Frequency determines the period, and hardware timers generate PWM without CPU involvement. Filtering PWM with an RC circuit yields a simple DAC.

Where it is used

Dimming LEDs, controlling DC motor speed, positioning hobby servos with pulse widths of 1 to 2 milliseconds, switching power supplies, audio tones and class-D amplifiers use PWM.

Common pitfall

Too low a frequency causes visible flicker or audible whine, and too high wastes switching losses or exceeds the driver's capability. Driving motors directly from pins can damage the controller; use transistors or H-bridges. PWM on mechanical relays is inappropriate. LED perceived brightness is nonlinear, so apply gamma correction. Match the frequency to the load.

Where it fits in the course

PWM is topic 20 of 50 in Mobile, Embedded & IoT, rated Intermediate. It follows ADC and DAC. The next topic is Serial Communication.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Mobile, Embedded & IoT quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is PWM?
Pulse patterns controlling power or brightness. It belongs to Mobile, Embedded & IoT and is an intermediate-level topic.
Where do people use PWM?
Dimming LEDs, controlling DC motor speed, positioning hobby servos with pulse widths of 1 to 2 milliseconds, switching power supplies, audio tones and class-D amplifiers use PWM.
What is the most common mistake with PWM?
Too low a frequency causes visible flicker or audible whine, and too high wastes switching losses or exceeds the driver's capability.
What should I learn before this topic?
Start with ADC and DAC, the topic just before it in Mobile, Embedded & IoT.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Mobile, Embedded & IoT quiz.
Is PWM hard to learn?
It is an Intermediate topic. Be comfortable with the Beginner topics in this area first, then read the common pitfall carefully, since it is where most mistakes happen.
How long does it take to learn PWM?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to PWM?
ADC and DAC, Serial Communication, Analog vs Digital Signals are closely connected. The full list is in the related topics section of this page.
What should I study after PWM?
Continue with Serial Communication, the next topic in Mobile, Embedded & IoT.

Related topics