Will Do Math For Free Lunch

Introduction

Engineers and managers at manufacturing companies frequently have sales folks come by who want to take you out for a "free" lunch. There is no such thing as a free lunch. They want to sell you something. Except the other day ...

I had a salesman call me and say that he wanted to go out for lunch with me. I assumed he wanted to sell me something. I had failed to prepare a bag lunch for that day, so I decided to take him up on his offer. He stopped by the office and picked me up to go to a local restaurant. Our conversation started with the usual chit-chat about the weather and family, but the salesman soon changed the discussion to the topic of pulse-width modulation. A number of his customers were asking for symmetric pulse width modulation (PWM) and he was wondering what was symmetric pulse-width modulation and why would anyone care. Now I knew why he wanted to go to lunch -- he wanted PWM training. As engineers have done since Imhotep designed the pyramids, I pulled out a pen, grabbed a napkin, and the lesson on PWM started.

Background

My history with PWM goes way back to my days as a sonar systems engineer. We used PWM to drive acoustic amplifiers. It was as sonar systems engineer that I learned the hard way about the difference between symmetric and asymmetric PWM. I will explain how I learned the hard way later. In my current position, we use PWM to set voltage thresholds that need to vary under computer control. These voltages are really quasi-DC levels and the symmetry of the PWM drive does not matter. This shows you that the type of PWM you require depends on your application.

PWM Basics

The Wikipedia has a good discussion of the basics of PWM. PWM is often used with power amplifiers whose output level is determined by the pulse width of its input drive. The output amplifiers or the loads they drive often have bandpass frequency characteristics that filter out any high and low frequency distortions introduced by the amplifier, but will not filter out frequency distortions near the PWM carrier frequency. This is the case with sonar systems. It also is the case with many motion control systems.

Symmetric PWM

People care about PWM symmetry when they care about the frequencies coming out of the output amplifiers. In a nutshell, a symmetric PWM drive will not produce frequency components other than the fundamental frequency of the PWM pulse train. Figure 1 illustrates the ideal situation.

Figure 1: Example of an Ideal Symmetric PWM Situation.

Figure 1: Example of an Ideal Symmetric PWM Situation.


Observe how the pulse train input drive is filtered by by the frequency characteristic of the power amplifier and load to put out a pure sinusoid. Figure 1 also shows that the centers of the PWM pulses align with one another, hence the term symmetric PWM. Unfortunately, generating a symmetric PWM pulse stream is more work than for an asymmetric stream. This was a bigger deal with the FPGAs of the Late Stone Age that I had to work with. Modern FPGAs laugh at circuits like this.

Asymmetric PWM

The easiest form of PWM to implement is asymmetric. All you need is a simple loadable counter that restarts counting at a regular interval. Figure 2 shows an example of an asymmetric pulse stream and the sinusoidal output it produces. Notice how the sinusoids are phased shifted with respect to one another. The phase of the output sinusoid varies with the PWM pulse width. This means that our output has a time-varying phase. A time-varying phase is the equivalent of a frequency shift (see Equation 2).

Figure 2: Example of an Asymmetric PWM Situation.

Figure 2: Example of an Asymmetric PWM Situation.

A Simple Example

To illustrate the issues associated with asymmetric PWM, consider the case of an application requiring a sinusoid modulated with a sawtooth output amplitude (Figure 3). A modulated carrier is the norm in sonar and radar systems. Typically, they generate pulses with complex shapes with names like Kaiser-Bessel and Dolph-Chebyshev. However, a simple sawtooth waveform will illustrate the signal distortion issue just fine.

Figure 3: Desired Sinusoidal Output Envelope Variation with Time.

Figure 3: Desired Sinusoidal Output Envelope Variation with Time.


Equation 1 describes the signal that we really want.

Eq. 1 f(t)=A(t)\cdot \sin (\omega \cdot t)

where A(t) is the envelope function.

Equation 2 describes the signal that we really get on the rising edge of the sawtooth. The phase of the sinusoid changes with time. Equation 2 also shows that a linear phase shift with time looks to the outside world like a shift in carrier frequency (\omega \to \omega +k).

Eq. 2 f(t)=A(t)\cdot \sin \left( \omega \cdot t+\phi \left( t \right) \right)
The sawtooth implies a linear variation of phase with time, which we model as k \cdot t during the sawtooth's rising edge.
f(t)=A(t)\cdot \sin (\omega \cdot t+k\cdot t)
f(t)=A(t)\cdot \sin (\left( \omega +k \right)\cdot t)

A similar thing happens when the negative edge of the sawtooth. This introduces a negative frequency offset to the carrier. Both positive and negative frequencies will appear in the output (see Figure 4). Note that the carrier is not present in the output.

Figure 4: Spectrum of Asymmetric-PWM Driven Amplifier.

Figure 4: Spectrum of Asymmetric-PWM Driven Amplifier.

What we really want is what I show in Figure 5, which is a envelope modulated with a single-frequency carrier. You get this with a symmetric PWM drive for the power amplifier.

Figure 5: Time and Frequency Domain Views of a Modulated Sawtooth.

Figure 5: Time and Frequency Domain Views of a Modulated Sawtooth.


Figure 5 shows that the unmodulated sinusoid has a sharp spectral peak and the modulated sinusoid has a slightly broadened peak. Theory predicts the broadening of the spectral peak and the envelope shapes are usually chosen to minimize the broadening.

Conclusion

You care about a PWM signal being symmetric when you care about the frequency content of the output. A symmetric output does not produce the harmonic distortions created by the time-varying phase variation introduced by an asymmetric PWM signal.

I will never forget this lesson. On my first sonar transmitter design, I inadvertently implemented an asymmetric PWM sequence. Since this sonar system was trying to detect faint target echoes, the extra spurs that my asymmetry introduced looked like targets. Fortunately, my implementation used programmable logic and I was able to correct the error quickly once I figured out what was going on. However, the lesson was burned into my brain cells. I shudder just thinking about it even now. It was unnerving looking at a range-Doppler map and seeing false targets appearing where there weren't any. Kind of like looking for a cloaked Klingon Bird-of-Prey. 🙂

This entry was posted in Electronics. Bookmark the permalink.

3 Responses to Will Do Math For Free Lunch

  1. Joel says:

    Now how do you implement this?

    If you use a simple timer based PWM in a microcontroller, you can't do it. You could use two PWM outputs and AND them together (after inverting one). You can also run them with a half the period (twice the frequency).

    For a single output you would probably have to have use the timer timer to interrupt at different times.

    The Atmel AVR has a mode on their PWMs called Phase correct. They have their counter count up and then back down. Each time it crosses your threshold it toggles the output bit. This does it for you automatically.

Comments are closed.