Embedded Systems Fundamentals · Interview question

What is PWM and how does it produce an "analog" output from a digital pin?

A strong answer

PWM (Pulse Width Modulation) outputs a square wave at a fixed frequency and varies the duty cycle, the fraction of each period the signal is high. A digital pin is only ever at 0 V or VDD, but if you switch it fast enough, a load that responds to the average rather than the instantaneous level effectively sees V_avg = duty_cycle × VDD: an LED at 25% duty looks dimmer because your eye integrates the flicker, a motor at 50% duty runs slower because its inertia averages the pulses, and an RC low-pass filter literally averages the waveform into a smooth voltage. So PWM doesn't make a true analog voltage at the pin, it makes a pulse train whose average is analog, and you rely on the load (or a filter) to do the averaging. The frequency stays constant; only the high-time varies.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

PWM

Fake an analog level with a digital pin: a fixed-frequency square wave whose duty cycle sets the average voltage, built on a timer and used for LEDs, motors, and servos.

More PWM questions

Browse all 472 interview questions
What is PWM and how does it produce an "analog" output from a digital pin? | EmbeddedPrep.io