PWM - Pulse Width Modulation

Use Case

Pulse Width Modulation is often used for 2 uses:

  1. It is used to control the voltage across a specific node

  2. It is used as a digital communication interface between 2 different devices

    1. This article will not focus on how to do so, as it is a special case of using PWM to control the voltage across a specific node.

Timing Diagram of PWM

PWM Timing Diagram

Key Definitions

  • Period: The time taken for the pulse to repeat

  • Duty Cycle (i.e. ‘On time'): The percentage of the wave for which it is high compared to the total length of the wave.

Theory of Operation

Pulse Width Modulation works by modifying the duty cycle of the wave at a fixed frequency. An example of modifying duty cycles is shown below:

Duty cycle modification timing diagram, credit

Sample Scenario

Let is focus on application #1 (controlling the voltage at a specific node).

  • Say you have a 5V microcontroller that is intended to drive a DC motor on a car. A DC motor’s speed is directly controlled by the voltage applied to it (i.e. 5V = max speed, 2.5V = half of max speed, 0V = no movement from the motor).

  • Your microcontroller doesn’t have a digital-to-analog converter, and therefore can only supply 5V or 0V at a set point in time, meaning you can either go for max speed or no movement over a given period of time. This is undesirable as you want to control the exact speed of the motor

  • You think to yourself, “What if I turn the motor to max speed, and then turn the motor off off, and repeat this cycle”. You set it so that this happens at a frequency of 1Hz (i.e. the motor will turn on for 0.5 seconds, then the motor will turn off for 0.5 seconds).

  • For the first 0.5 seconds, the car is moving at full speed, and the next 0.5 seconds, the car stops. On the surface, this appears unsuccessful. But then you realize, if you looked at the distance the car travelled over the whole one second rather than the individual 0.5 second segments, the car only travelled half of the expected distance at max speed.

    • For those who would like a drawing, enjoy my crappy onenote drawing below:

  • However, when you look at the distance to time graph of the system, you notice that the car only travelled half of the distance within the one second period.

    • By extension, the average voltage over the one second period was 2.5V (0.5*5V + 0.5*0V)

  • Now, you think, what if we made that one second period shorter, so short in fact that you can’t tell when the switching between the half that is on and the half that is off. You decide to try a frequency of 1kHz (total period 1ms), with an on-time (high voltage time, in this example 5V) of 50% (1ms * 50% = 0.5ms), which leads to an off-time (low voltage time, in this example 0V) of 0.5ms. The average voltage is now still 2.5V, but since the switching is occurring so rapidly, you cannot tell the difference and the motor performs as though it was operated at 2.5V.

Mathematical Relationship

The following example allows us to deduce the following relationship:

  • Vout = Vin * (Duty Cycle)

    • Where Duty Cycle is between 0 and 1 (corresponding to 0 → 100%)

  • EXAMPLE: To simulate a voltage of 4V given an input voltage of 5V, the required duty cycle is 80%

Calculations

  • On-time = (DUTY_CYCLE) * period

  • Off-time = (1-DUTY_CYCLE) * period

  • Frequency = 1/period

Application Notes

  • It is important to pick the correct switching frequency. As observed in the sample scenario, the low switching frequency of 1Hz led to jittery results. However, a high switching frequency can also lead to higher switching losses as a result of the non-ideal properties of switching components. Consult with an EE about this topic if you’re in an application that does this. 1kHz is usually a safe bet.

  • A common application for PWM is with LED brightness, where your duty cycle is directly related to how bright the LED is without having to swap out resistors to adjust the forward current through the LED.