# A Simple Example of PWM

## Introduction

To understand the analysis of PWM (pulse width modulation) at a simple level consider the following input, a digital pulse train that is high 60% of the time, that goes into a system. The period of the function is "T". For this example we will take the high part of the signal to be 5, and the low part to be 0. Our goal is to find the output of the system.

First we note that the input to the system can be split into two parts, a constant part equal to a constant part (equal to the average) and a time varying part (with an average of zero), as shown.

Since the input is high (5) 60% of the time, the average is 0.6×5=0.3. The time varying part is equal to 2 for 60% of the time, and equal to -3 for 40% of the time, so its average is zero, as specified.

If the system is linear (we will only consider linear systems) we can say that the output of the system is equal to the sum of the response of the system to the constant (average) part, and the time varying (zero average) parts.

This has the advantage that the average system output is usually very easy (often trivial) to find, then we just have to make sure that the system is such that the time varying output is small (more on this later).

## A simple system with PWM input

We will consider simple RC circuit with a PWM output. In this case the PWM input (vin(t)) alternates between 0V and 5V with a frequency of 1Hz (or period of 1S).

The graph below shows the behavior of the system throughout one cycle of the PWM output. The duty cycle, D, can be varied from 0 to 1 and is the fraction of time that the output is high. The time constant (τ=R·C) can also be varied, but the period of the input is fixed at T seconds. The graph shows the input (black), the output (translucent magenta), the average value (horizontal magenta line, its calculation is described below), and a simple linear approximation (dotted red line, also described below). Also shown are the slopes of the approximate output when the input is high, and when it is low, as well as the exact and approximate amount of ripple (ripple is the peak to peak variation in the output).

Try these things to get a feel for how the PWM works.

• As the duty cycle is increased the average increases (as does the output of the low pass system). Note: the ripple also decreases and goes to zero as the duty cycle approaches 100%.
• As the duty cycle is decreased the average decreases (as does the output of the low pass system). The ripple also decreases and goes to zero as the duty cycle approaches 0%.
• As τ is decreased the ripple increases (because the low pass system responds quickly) and the deviation between the exact and approximat output increases..
• As τ is increased the ripple decreases (because the low pass system cannot respond as quickly).

## Analysis of a system with PWM

There will be two steps in the analysis.

1. First, we find the average output.
2. Second we find the amount of ripple (or variation) in the output.

### Step 1: Find the average output.

To find the average output, we assume the input is a constant, Vin,ave. Assuming the input is constant, there are many ways to find the output; three easy methods are given below.

1. Replace the input by a DC source and solve (since the voltage is constant, there is no capacitor current (i=C·dv/dt=0).

In this case it is easy to see that Vout,ave=Vin,ave (since no current flows, and there is no voltage drop across the resistor).
2. Find the differential equation describing the circuit
${v_{out}}(t) = {v_{in}}(t) - i \cdot R = {v_{in}}(t) - C\frac{{d{v_{out}}(t)}}{{dt}} \cdot R$
then set all derivatives to zero.
${v_{out}}(t) = {v_{in}}(t)\quad {\rm{or}}\quad {V_{out,ave}} = {V_{in,ave}}$
Again we see that Vout,ave=Vin,ave.
3. Use the transfer function (if you don't know what this means, you can use one of the methods above). Note: in this case I found the transfer function using the voltage divider equation.
$H(s) = \frac{{{V_{out}}(s)}}{{{V_{in}}(s)}} = \frac{{{Z_c}(s)}}{{{Z_c}(z) + {Z_r}(s)}} = \frac{{\frac{1}{{sC}}}}{{\frac{1}{{sC}} + R}} = \frac{1}{{1 + sCR}}$
to find the average value, take the input to be constant, so s=0.
${V_{out}}(0) = H\left( 0 \right) \cdot {V_{in}}(0) = 1 \cdot {V_{in}}(0) = {V_{in}}(0)\quad {\rm{or}}\quad {V_{out,ave}} = {V_{in,ave}}$

Try this on the demo (above):

• vary the duty cycle, D. Since, in this case, the input is 5 for D seconds, and 0 for the rest of the time (1-D) the average is just 5·D. As you adjust D you can verify that the average output (on the graph) is equal to D.
• Set D=0.6, the average of the output is 5·D=3V.
• What happens if you set D=0.1?
• How can you set the average to 2.5V?

### Step 2: Find the ripple.

Finding the ripple is usually straightforward if the system in question is first order, and the time constant, τ, of the system is much longer thatn the period, T, of the input signal oscillations. In this case we can assume that the system is slow enough that the output doesn't change much during one cyle of the input. Therefore, to determine the amount of ripple, let us assume that the output voltage is consant (at the average value of the input).. Note: This may seem a bit strange — we are using the assumption that the output is constant to find the amount of variation in the output. If you are interested in a more thorough derivation, check out the next page in this series.

Let's find the ripple when the duty cycle is 0.6. For this circuit the output voltage is just the average of the input, or 5·D=3V.

If the input is high (i.e., vin(t)=5) and the output is the average (3V), the voltage across the resistor is 5-3=2V, and the current (from left to right) through the resistor is 2V/R. We can now find the slope of the output

$\begin{array}{l} {i_R} = {i_C} = C\frac{{d{v_{out}}(t)}}{{dt}}\\ with\quad {i_R} = \frac{{{v_{in}} - {v_{out}}}}{R} = \frac{{{v_{in}} - {v_{ave}}}}{R} = \frac{{5 - 5 \cdot D}}{R}{\rm{, so}}\\ \frac{{d{v_{out}}(t)}}{{dt}} = \frac{{{i_R}}}{C} = \frac{{5 - 5 \cdot D}}{{R \cdot C}} = \frac{{5 \cdot (1 - D)}}{\tau } \end{array}$

The total amount of ripple is just this slope multiplied by the amount of time that the output is high (in this case D·T seconds). Note: In this case the period, T, is 1 second. Since this is the ripple in the output voltage while vin is high, we will call this Δvout,vin=1.

$\Delta {v_{out,vin = 1}} = \frac{{5 \cdot (1 - D)}}{\tau } \cdot \Delta t = \frac{{5 \cdot (1 - D)}}{\tau } \cdot D \cdot T = 5 \cdot (1 - D) \cdot D \cdot \frac{T}{\tau }$

Likewise, if the input is low (i.e., vin(t)=0) and the output is 3V, the voltage across the resistor is 0−3=−3V, and the current (from left to right) through the resistor is -3V/R. We can now find the slope of the output

$\begin{array}{l} {\rm{ }}{i_R} = \frac{{{v_{in}} - {v_{out}}}}{R} = \frac{{{v_{in}} - {v_{ave}}}}{R} = \frac{{0 - 5 \cdot D}}{R}{\rm{ = }} - \frac{{5 \cdot D}}{R}{\rm{, so}}\\ \frac{{d{v_{out}}(t)}}{{dt}} = \frac{{{i_R}}}{C} = - \frac{{5 \cdot D}}{{R \cdot C}} = - \frac{{5 \cdot D}}{\tau } \end{array}$

The total amount of ripple is just this slope multiplied by the amount of time that the output is high (in this case (1-D)·T seconds). Note: In this case the period, T, is 1 seconds. Since this is the ripple in the output voltage while vin is low, we will call this Δvout,vin=0.

$\Delta {v_{out,vin = 0}} = - \frac{{5 \cdot D}}{\tau } \cdot \Delta t = - \frac{{5 \cdot D}}{\tau } \cdot \left( {1 - D} \right) \cdot T = - 5 \cdot D \cdot \left( {1 - D} \right) \cdot \frac{T}{\tau }$

Try this on the demo (above):

• Increase the time constant, τ. As τ increases the system is slower and there is less ripple (the Δvout terms we calculated decrease)
• Decrease the time constant, τ. As τ decreases the system can react faster and there is more ripple (the Δvout terms we calculated increase)
• As you change D, the ripple also varies, and is maximized when D=0.5. Note: You can show this by differentiating either expression for Δvout with respect to D and setting the result to 0 to find the maximum — also note that the ripple goes to zero when D=0 or D=1 (i.e., when the input is a constant).

## Take home lessons

As τ increases (so the ratio T/τ decreases), the ripple decreases. If we make τ large enough (compared to the period, T, of the PWM signal) the ripple goes to zero and the output is effectively constant.

Mathematical details are described in the next page in this series.

References

Replace