Apr 17, 2011

Pulse-Width Modulation

Ok, I know it has been a while since I have posted anything but I doubt my two readers are losing any sleep over it. This post will finally discuss the long-awaited topic of pulse-width modulation (PWM).

PWM is a highly efficient control scheme used to manipulate the flow of power through various electronic devices. I have seen it most commonly used in switched-mode power supplies, LED dimming circuits, and variable speed motor controls, but there are several more applications. The concept of PWM draws from the most basic elements of a binary system: on (1) or off (0). At any given moment, switches are turned on or off depending on the feedback signal from the load receiving power. This process allows power to be taken from the source in doses and supplied to the output such that the output remains relatively constant. Exactly how much power is supplied to the load depends on the duty cycle of the switching system.

The duty cycle of a PWM waveform refers to the amount of time relative to an entire switching period that the pulse stays high. It is usually expressed as a percentage or decimal and can vary anywhere between 0% (completely off) to 100% (completely on). Figures 1-3 show some examples of various duty cycles used for voltage regulation and the math explaining how the load sees an average voltage depending on the switching conditions. The figures assume the switches are operating at 50 kHz (being turned on and off 50,000 times/second). 

Figure 1. PWM pulse train at a 20% duty cycle


Figure 2. PWM pulse train at a 50% duty cycle
 

Figure 3. PWM pulse train at a 80% duty cycle


In practice, PWM can be implemented in power supplies if the source power is switched at a sufficiently high frequency such that the output inductor can supply current without letting it fall to zero. Current passing through an inductor cannot change instantaneously which means even if the switch from the source is turned off the inductor current will drop steadily instead of falling to zero immediately. As long as the switch comes back on before the inductor current falls too low to be useful, the load sees a continuous flow of current.

Similarly, LEDs can be dimmed using PWM. By turning the LEDs on and off at a higher frequency than the human eye can detect, and varying the duty cycle, you can control the brightness level. A pulse train with a higher duty cycle will increase the brightness and vice versa. There is still some debate among the experts in the field of LEDs on what the minimum switching frequency should be but in general it can be as low as a few hundred hertz.

Lastly, PWM schemes are utilized with motors to regulate the speed of rotation. As long as the switch is turned on before the motor has a chance to decrease appreciably in speed, the motor will continue to perform its intended function.

So why is this scheme better than, say, adding a resistor to drop the voltage before it gets to the external load? The answer is efficiency. In any power transfer system, resistive elements are the enemy because they constantly create voltage drops and power loss. The beauty of including switching elements into a power transfer circuit is that the instantaneous losses are significantly reduced. When the switch (transistor) is open, no current is passing through the device so the power dissipation is zero (P=IV or I2R). When the switch is closed, the switch acts like a short between the two contacts so the voltage drop is zero and therefore the power dissipation in the switch is again zero. What this all really amounts to is that in both the high and low states the switching element itself dissipates no power meaning the load receives nearly everything drawn from the source.

Unfortunately, we don’t live in a perfect world and even cool schemes like PWM have drawbacks. First and foremost, nothing can switch instantaneously. Every time a transistor is switched there is a transition time in between the states which causes the PWM waveform to look more trapezoidal than square under high enough resolution. During these transition periods both voltage and current are active across and through the transistor creating power loss in the form of heat. The more times this process is executed (aka the higher the switching frequency) the higher the “switching losses” become. In addition, transistors are not immune to small currents passing through the transistor when it is not conducting, also called leakage currents. These leakage currents can cause power dissipation when the transistor is off making the component non-ideal.

The same is true for a transistor in the on mode. Everything has resistance and transistors are no exception. The resistance between two of the contacts in a switching transistor is low but still relevant when considering efficiency. Its presence means that the transistor is dissipating power when conducting so it does not act as a perfect short.

Lastly, it is important to note that PWM is a control scheme for delivering power. A controller drives transistors to switch and control the flow of power through other passive and/or active elements, which all have resistive losses and hence all dissipate power. Therefore, while PWM schemes can produce high efficiency, they are not without certain unavoidable losses.

To really drive this point home, I put together a PWM circuit based on two reference signals and a comparator (see my blogs on oscillators and comparators for more information). The first signal is a 1 kHz sine wave for use as a reference. This sine wave simulates the feedback signal from an external load and is used to generate the switching PWM signal. The second signal is a 2.5 kHz sawtooth waveform generated from an oscillator circuit. In voltage-mode control schemes, it is very common to see a sawtooth or “ramp” signal used for comparison purposes. Figure 4 shows the schematic. It may look intimidating to anyone unfamiliar with circuit design, but it really breaks down to the sawtooth oscillator and comparator functional blocks. One note to anyone who may be actually be interested in the circuit details, I added some DC offsets (3.5V source in series with the oscillator output) to the signals to keep all the voltages positive for illustration purposes, but it should work just fine with them removed. 

 Figure 4. PWM Circuit schematic


I ran a simulation on this circuit and included the results of three different signals: the non-inverting (+) input signal of the comparator, the inverting (-) input signal of the comparator, and the PWM output signal. Figure 5 shows all the waveforms of interest.
  
 Figure 5. Feedback signal (red), Sawtooth reference (green), and PWM output (blue) waveforms


Hopefully, you can see by the picture that the PWM waveform generated by the circuit (in blue) turns the switches on when the sawtooth waveform (green) falls below the feedback from the output load (red). The sawtooth oscillator is running at a higher frequency than the feedback from the output, which means that the comparator will not generate a uniform square wave because the two input signals change voltage magnitudes out of sync. The result is a pulse train where the width of each block is modulated (varied) over time.

My goal was to make this post PWM in a nutshell. As with everything I write in this blog there are subtle details to using this scheme that I have left out and design pitfalls I have ignored because I would rather demonstrate the concept. For instance, using PWM can often times be more expensive for designers because the transistors need to be able to tolerate higher voltages than the voltage supplied to the load as the voltage is averaged over one switching period where the transistor is off for a period of (1-D)*T. Hopefully, anyone reading this now has a solid understanding of pulse-width modulation and how it can be used to efficiently regulate voltage and deliver power to a load.

 

3 comments:

Anonymous said...

Could you do some posts about the theory behind some of this stuff? I have a pretty poor mental model of electronics (I think its magic) and it would help to see it in a more abstract setting.

Chris said...

Any stuff in particular? I realized while I was writing this I may have been too ambitious introducing PWM so early. Let me know.

Noah Ryan said...

I would like to see something about how we can reason about circuits- what attributes do they have? Which are static and which change over time and location in the circuit? Do you reason about them locally, or do you have to look at the whole picture to understand any part? I had some basic electronics education and some physics stuff on circuits, but there is a lot of context I'm missing.

Post a Comment