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.
Embedded Systems Fundamentals · Interview question
What is PWM and how does it produce an "analog" output from a digital pin?
A strong answer
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
How is PWM generated using a timer?What's the tradeoff between PWM frequency and duty-cycle resolution?Why can't you drive a motor directly from a PWM-capable GPIO pin?How does PWM control a hobby servo, and how is that different from LED dimming?What is dead-time in a complementary PWM pair, and why does an H-bridge need it?Your PWM-controlled LED looks steady to the eye but flickers badly on camera video. What's going on and how do you fix it?
Browse all 472 interview questions