PULSE WIDTH MODULATION (PWM) FINAL REPORT Class: ENEE 417 Professor: Dr. Yang Copyright © 2007 By: Long Pham Khoa Nguyen Travis Paul All Rights Reserved Table of Contents OBJECTIVE ................................................................................................................................................................2 STAGES NEEDED ......................................................................................................................................................2 DIAGRAM OF THE ALL THE STAGES INCLUDING THE OPTICAL GROUP/LEDS ............................................................2 BACKGROUND RESEARCH ...................................................................................................................................3 WHAT IS PWM (PULSE WIDTH MODULATION METHOD) ...........................................................................................3 HOW TO GENERATE A CARRIER SIGNAL (TRIANGLE WAVEFORM) ............................................................................3 HOW A COMPARATOR WORKS ....................................................................................................................................3 HOW TO DEMODULATE A PWM SIGNAL ...................................................................................................................4 PARTS SPECIFICATION RESEARCH ..................................................................................................................4 PARTS NEEDED TO BUILD THE CIRCUIT.........................................................................................................6 QUICK ANALYSIS OF THE PROJECT AND HOURS SPEND ..........................................................................6 PSPICE OF CIRCUIT AND SIMULATIONS .........................................................................................................7 CIRCUIT THAT REPRESENTS THE ACTUAL CIRCUIT....................................................................................................7 SIMULATE THE CIRCUIT WITH SINE AT 100HZ ...........................................................................................................8 SIMULATE THE CIRCUIT WITH SINE AT 1KHZ ............................................................................................................9 SIMULATE THE CIRCUIT WITH SINE AT 10KHZ ........................................................................................................ 10 SIMULATE THE CIRCUIT WITH SINE AT 20KHZ ........................................................................................................ 11 SIMULATE THE CIRCUIT WITH SQUARE AT 20KHZ ................................................................................................... 12 CIRCUIT BUILD ON PC BOARD .......................................................................................................................... 13 TRANSMITTING SIDE ................................................................................................................................................ 13 RECEIVING SIDE ...................................................................................................................................................... 15 TEST RESULTS ........................................................................................................................................................ 17 TEST THE CIRCUIT WITH SINE WAVE AT 100HZ ...................................................................................................... 19 TEST THE CIRCUIT WITH SINE WAVE AT 1KHZ ........................................................................................................ 22 TEST THE CIRCUIT WITH SINE WAVE AT 10KHZ ...................................................................................................... 25 TEST THE CIRCUIT WITH SINE WAVE AT 20KHZ ...................................................................................................... 28 FREQUENCY RESPOND OF THE CIRCUIT BUILD ........................................................................................ 32 TRANSMITTING SIDE OF THE CIRCUIT ...................................................................................................................... 32 RECEIVING SIDE OF THE CIRCUIT (2ND ORDER LPF) ................................................................................................. 33 CONCLUSION .......................................................................................................................................................... 34 REFERENCES .......................................................................................................................................................... 35 APPENDIX A – CMX309 ......................................................................................................................................... 36 APPENDIX B – OP-AMP LM7171 .......................................................................................................................... 37 APPENDIX C – OP-AMP TLV2362 ........................................................................................................................ 42 1 Objective To modulate an audio signal by using the method of pulse width modulation, then demodulate the signal to recover the audio signal. The final goal for the team is to transmit the modulated signal optically, thus an optical group is in charge of transmitting the PWM signal by an LED and use a photo-detector to receive the signal. Finally, there is a power amplifier to amplify the received signal before inputting it to a speaker. Stages Needed 1. 2. 3. 4. To generate a carrier signal (triangle wave at 1MHz) Use a microphone and input an audio signal Use a comparator to produce a PWM signal Use a low pass filter to demodulate the PWM signal into an audio signal Diagram of the All the Stages Including the Optical Group/LEDs Transmitting Side: To PhotoDetector Figure 1a Receiving Side: Figure 1b 2 Background Research What is PWM (Pulse Width Modulation method) PWM of a signal or power source involves the modulation of its duty cycle, to either convey information over a communications channel or control the amount of power sent to the load. PWM uses a square wave whose duty cycle is modulated resulting in the variation of the average value of the waveform. How to Generate a Carrier Signal (Triangle Waveform) A method of generating a triangle waveform is to first use a clock oscillator to produce a square wave and then use an integrator (low pass filter) to integrate the square wave into a triangle wave. Using a Passive LPF to Integrate the Square Wave at 1Mhz: Since the crystal oscillator is producing a 1Mhz square wave, thus using the following calculation we can choose which RC values to use: Calculation: fc = 1/ (2πτ) = 1/ (2πRC) (Low Pass Filter – Wikipedia) Comment: In this case, our cutoff frequency is 1Mhz, thus we can choose one capacitor value that we have and solve for the resistor value. Keep in mind that in actual circuit design the values might need to vary in order to integrate better. One method that we did was fix the capacitor at 240pF and vary the resistor until we see a triangle wave on the oscilloscope that is constant and stable in order for the comparator to behave properly. In order to get a PWM signal output, the comparator needs a constant stable signal; in this case, the triangle wave has to be constant and stable. How a comparator works A comparator receives two input signal and compares the signal. If the positive input voltage is greater than the negative input voltage, then the comparator produce an output signal to its highest rail voltage. In this case, the comparator will output the signal to 9V because we are using +/- 9V to drive the comparator. If the negative input voltage is greater than the positive input voltage, then the comparator will output a signal to its lowest rail voltage. In this case, the comparator will output the signal to -9V. (Refer to figure 2 on next page) (Pulse Width Modulation – Wikipedia) 3 Figure 2 How to Demodulate a PWM Signal One method to demodulate a PWM signal is to use a 2nd order low pass filter (LPF). The LPF acts as an integrator which integrates the PWM. Since a PWM is a square wave like form, then the LPF would integrate the PWM into a sinusoidal waveform/audio signal. Thus, the audio signal being transmitted will be recovered by using this convention. Parts Specification Research Clock Oscillator (CMX 309 Series) – see Appendix A for specifications Reasons for choosing this part: o Clock oscillator produces 1Mhz square wave which is one of our requirement o It is low power consumption and produces a stable waveform at room temperature o Desired low voltage value: 1.0 - 3.3V o Embedded with heat resistant cylinder type crystal bring highly stable characteristics o It is suitable for various applications such as communication devices o Price: $2.63/chip o Amount of chips recommended: 5 (units) to test around with Comparator (used Fast Op-Amp LM7171) – see Appendix B for specifications Reasons for choosing this part: o It is a fast op-amp used in replacement of Comparator IC at frequency of 1Mhz o Can support up to +/- 15 volts as supply voltage Thus, the transmitting signal will have a large voltage swing that are set by the rail voltage If we use a higher voltage to transmit, the that will increase the signal to noise ratio 4 o Its Gain Bandwidth Product is 170 MHz at operating voltage +/-9V at room temperature o Low offset voltage typically 0.2mV o Price: $2.88/chip o Amount of chips recommended: 5 (units) to test with Op-Amp (not used in final design) Texas Instrument TLV2362- see Appendix C for specifications Reasons for not using this part in final circuit design: o Due to lacking of understanding about op-amp specification, many features from this op-amp is not suitable in our design o It has a much smaller Gain Bandwidth Product than the above op-amp (6MHz compare to 170MHz) o High input offset voltage 6mV o Maximum supply-voltage limits at +/- 3.50V, which will give a small output swing that are set by the rails in comparison to the LM7171 o Price: $.57/chip o Amount of chips recommended: 5 (units) to test with 5 Parts Needed to Build the Circuit Data Table 1: Components CMX – 309 Series- Mouser.com LM-7171- Digikey.com Resistor – 1kΩ - School Supplies Resistor – 680Ω - School Supplies Resistor – 2kΩ - School Supplies Capacitor – 10μF(Larger electrolytic)- School Supplies Capacitor – 22μF(Larger electrolytic)- School Supplies Capacitor – 4.7μF(Larger electrolytic)- School Supplies Capacitor – 4.7nF(Ceramic)- School Supplies Capacitor – 963pF- School Supplies Energizer 9V Batteries – Home Depot Battery – 1.5V (AA)- CVS Price($)/Unit Quantity 2.63 1 2.88 1 .01 1 .01 1 .01 3 .20 1 .20 1 .20 1 .10 1 .10 1 .97 2 .524 1 Total Cost of Circuit Total Cost 2.63 2.88 .01 .01 .03 .20 .20 .20 .10 .10 1.94 .52 8.83 Quick Analysis of the Project and Hours Spend Starting from scratch, the total amount of time to assemble this circuit together took approximately 1 semester of school hours. Each week we spend approximately 6 hours of lab time to discuss and assemble our information, such as background research, parts research, PSPICE simulations and etc. We spend roughly 2 months of about 8 to 10 hours a week building the circuit on breadboard, testing it, gather data and trouble shoot any problems that we had encounter. The reason why this project took such a long time to accomplish was because we had to change our circuit design due to parts constraint, meaning the parts did not work the way we had expect it to due to poor parts research and lack of understanding about the datasheet. Another, was troubleshooting where errors had occur within the circuit such as not measuring the DC voltages at all nodes. This was a problem because there was a DC voltage input into the comparator that was caused from the output of the clock oscillator, thus the comparator did not function as we expect it to. So, the waveform did not look like a PWM. Therefore, we had to add in a coupling capacitor to ensure that only AC signals are input into the comparator. Another approach that we had in the beginning was to use an active LPF in order to control the voltage swing at the output, but after many tests, we decided to have a simple passive LPF to reduce the circuit components and that made things less complex. As a whole, it took many hours to research, understand and assemble the project into one final circuit. But, with proper instructions this circuit could be assembled within 10 hours for two people to build using breadboard given all the parts are supplied. To implement the circuit on PC board will take an extra 10 hours. So roughly 20 hours to rebuild the PWM transmitting and receiving circuits excluding the optical parts. 6 PSPICE of Circuit and Simulations Conditions: Used Vpulse at 1.6VPP as a square wave generator Used Vsin at 200mVPP to represent a test input to the comparator (LM7171) Used 2nd order LPF to demodulate the PWM signal and recover the sine wave All signals are AC signal with no bias DC voltage Used the measured voltage of the battery to simulate the circuit. In this case it is +/9.4Vdc to drive the LM7171 Circuit that Represents the Actual Circuit Comparator Passive Low Pass Filter (Demodulator) 0 V3 9.4V R2 4 1970 V- LM7171AIN 3 + VOFF = 0 VAMPL = 100mV FREQ = 10000 V Input OUT PWM Signal R6 U1 V+ - R3 C4 2020 963p V 7 1990 2 0 6 C3 4.7n V2 9.4V 0 R1 0 V V1 = .8V V2 = -.8V TD = .1f s TR = .1f s TF = .1f s PW = .5us PER = 1us 663 V C1 240p Square 0 0 Figure 3a 1.0V 0V -1.0V V(Square:+) 1.0V 0V SEL>> -1.0V 10.0us V(R1:2) 12.5us 15.0us 17.5us 20.0us Time Figure 3b (Blue – Square Yellow - Triangle) 7 Simulate the Circuit with Sine at 100Hz Sine Input to Comparator with 200mVPP: 100mV 0V -100mV V(INPUT:+) 1.0V 0V SEL>> -1.5V 0s 2ms 4ms 6ms 8ms 10ms V(R2:2) Time Figure 4a (Green – Input Sine to Comparator Red – Output of 2nd Order LPF) 10V 0V -10V 100us V(R6:1) 110us 120us 130us 140us 150us Time Figure 4b (Output PWM Signal of Comparator at 100Hz Sine Input) 8 Simulate the Circuit with Sine at 1kHz Sine Input to Comparator with 200mVPP: 100mV 0V -100mV V(Input:+) 1.0V 0V SEL>> -1.5V 0s 0.2ms 0.4ms 0.6ms 0.8ms 1.0ms V(C4:2) Time Figure 5a (Red – Input Sine to Comparator Blue – Output of 2nd Order LPF) 10V 0V -10V 100us V(R6:1) 110us 120us 130us 140us 150us Time Figure 5b (Output PWM Signal of Comparator at 1kHz Sine Input) 9 Simulate the Circuit with Sine at 10kHz Sine Input to Comparator with 200mVPP: 100mV 0V -100mV V(Input:+) 1.0V 0V SEL>> -1.0V 100us V(C4:2) 125us 150us 175us 200us Time Figure 6a (Green – Input Sine to Comparator Red – Output of 2nd Order LPF) 10V 5V 0V -5V -10V 80us V(R6:1) 100us 120us Time Figure 6b (Output PWM Signal of Comparator at 10kHz Sine Input) 10 Simulate the Circuit with Sine at 20kHz Sine Input to Comparator with 200mVPP: 100mV 0V SEL>> -100mV V(Input:+) 1.0V 0V -1.0V 50us V(C4:2) 75us 100us 125us Time Figure 7a (Green – Input Sine to Comparator Red – Output of 2nd Order LPF) 10V 5V 0V -5V -10V 40us V(R6:1) 50us 60us 70us 80us Time Figure 7b (Output PWM Signal of Comparator at 20kHz Sine Input) 11 Simulate the Circuit with Square at 20kHz Square Input to Comparator with 200mVPP: 100mV 0V SEL>> -120mV V(U1:+) 1.0V 0V -1.0V 0s 100us 200us 300us V(C4:2) Time Figure 8a (Blue – Input Square to Comparator Red – Output of 2nd Order LPF) 10V 0V -10V 50us V(R6:1) 60us 70us 80us 90us Time Figure 8b (Output PWM Signal of Comparator at 20kHz Square Input) 12 Circuit Build on PC Board Transmitting Side Front View: With Batteries Figure 9a Front View: Closer Look at the PC Board and Circuit Coupling Capacitor to get rid of DC voltage Capacitor to get rid of ripple of square wave Integrator Pin 4 Pin 3 Pin 5 Pin 2 Pin 6 Clock Oscillator CMX309 Pin 1 LM7171 Comparator Figure 9b 13 Back View: +9 Volt Supply into LM7171 AA Battery Supply into CMX309 Input audio into this wire -9 Volt Supply into LM7171 Output of Comparator (PWM signal) Figure 9c 14 Receiving Side Front View: Pin 1 - Input to 2nd order LPF Pin 2 - Output of 2nd order LPF Figure 10a 15 Back View: Pin 2 - Output of 2nd order LPF Pin 1 - Input to 2nd order LPF Figure 10b 16 Test Results Conditions: One AA battery (1.63Vdc) supply to the clock oscillator One +9Vdc battery supply to Pin 7 of the LM7171 chip (refer to appendix B) One -9Vdc battery supply to Pin 4 of the LM7171 chip (refer to appendix B) Used 1x probes to measure ac signal on the oscilloscope Measured DC Voltages: Output of clock oscillator dc voltage (Refer to Figure 9b – Pin 2) Clock oscillator dc voltage after coupling capacitor (Refer to Figure 9b – Pin 4) Triangle wave dc voltage after integrator (Refer to Figure 9b – Pin 5) PWM output dc voltage of LM7171 (Refer to Figure 9b – Pin 6) 0.750Vdc 0.004Vdc 0.004Vdc 0.005Vdc Output of the Clock Oscillator after coupling capacitor: Refer to Figure 4b – Pin 4 Figure 11a 17 Triangle Wave After the Square Wave Has Been Integrated: Refer to figure 9b – Pin 5 This is a constant carrier signal input into the comparator (LM7171) while the sine input signal is varied at different frequencies and the sine wave voltage peak to peak has to be less than the triangle wave. Figure 11b 18 Test the Circuit with Sine Wave at 100Hz Input Signal to Comparator with Sine Wave at 100Hz: Refer to figure 9c – orange wire Figure 12a PWM Output Signal of the Comparator/Input Signal to the LED: Refer to figure 9b – Pin 6 - Input: Triangle Wave at 1MHz + Input: Sine Wave at 100Hz Figure 12b 19 PWM Output Signal of the LED/Input Signal to the Photo-Detector: Figure 12c Output Signal of the Photo-Detector/Input Signal to the 2nd Order LPF: Refer to figure 10a – Pin 1(use 10X probe to measure)-Note (1) Figure 12d 20 Output Signal of the 2nd Order LPF/Input Signal to the Power Amp: Refer to figure 10a – Pin 2 Figure 12e Output Signal of the Power Amp/Input Signal to the Speaker: Figure 12f 21 Test the Circuit with Sine Wave at 1kHz Input Signal to Comparator with Sine Wave at 1kHz: Refer to figure 9c – orange wire Figure 13a PWM Output Signal of the Comparator/Input Signal to the LED: Refer to figure 9b – Pin 6 - Input: Triangle Wave at 1MHz + Input: Sine Wave at 1kHz Figure 13b 22 PWM Output Signal of the LED/Input Signal to the Photo-Detector: Figure 13c Output Signal of the Photo-Detector/Input Signal to the 2nd Order LPF: Refer to figure 10a – Pin 1 (use 10X probe to measure)-Note (1) Figure 13d 23 Output Signal of the 2nd Order LPF/Input Signal to the Power Amp: Refer to figure 10a – Pin 2 Figure 13e Output Signal of the Power Amp/Input Signal to the Speaker: Figure 13f 24 Test the Circuit with Sine Wave at 10kHz Input Signal to Comparator with Sine Wave at 10kHz: Refer to figure 9c – orange wire Figure 14a PWM Output Signal of the Comparator/Input Signal to the LED: Refer to figure 9b – Pin 6 - Input: Triangle Wave at 1MHz + Input: Sine Wave at 10kHz Figure 14b 25 PWM Output Signal of the LED/Input Signal to the Photo-Detector: Figure 14c Output Signal of the Photo-Detector/Input Signal to the 2nd Order LPF: Refer to figure 10a – Pin 1 (use 10X probe to measure)-Note (1) Figure 14d 26 Output Signal of the 2nd Order LPF/Input Signal to the Power Amp: Refer to figure 10a – Pin 2 Figure 14e Output Signal of the Power Amp/Input Signal to the Speaker: Figure 14f 27 Test the Circuit with Sine Wave at 20kHz Input Signal to Comparator with Sine Wave at 20kHz: Refer to figure 9c – orange wire Figure 15a PWM Output Signal of the Comparator/Input Signal to the LED: Refer to figure 9b – Pin 6 - Input: Triangle Wave at 1MHz + Input: Sine Wave at 20kHz Figure 15b 28 PWM Output Signal of the LED/Input Signal to the Photo-Detector: Figure 15c Output Signal of the Photo-Detector/Input Signal to the 2nd Order LPF: Refer to figure 10a – Pin 1 (use 10X probe to measure)-Note (1) Figure 15d 29 Output Signal of the 2nd Order LPF/Input Signal to the Power Amp: Refer to figure 10a – Pin 2 Figure 15e Output Signal of the Power Amp/Input Signal to the Speaker: Figure 15f 30 Data Table 2: Input Input Sin Frequency Vp-p PWM output Vp-p LED Output Photodiode 100Hz 1KHz 10KHz 20KHz 16.8 V 15.8 V 16 V 15.8 V 7.52 V 7.36 V 7.4 V 7.4 V 799mV 764mV 793mV 746mV 233mV 221mV 230mV 232mV Output LPF Output of Power Amp 138mV 330mV 143mV 336mV 118mV 310mV 90.4mV 384mV Note(1): All the measurement of Photodiode was taken under dark room condition. Measurements for output of Photodiode were captured using 10X probe. 31 Frequency Response of the Circuit Build Transmitting Side of the Circuit The following graph shows the frequency respond of gain and phase of the transmitting side of the circuit in Log(gain) vs. Log(ω) and Log(phase) vs. Log(ω). The gain is approximately 11 is due to the LM7171 setting the output signal to its rails which is determined by the batteries used to drive the IC. In this case the batteries used to drive the LM7171 is +/9V, but when measured it was approximately +/-9.6V. Thus, the gain is affected by the batteries supplied to the LM7171. As for the phase, as frequency increases, the phase decreases possibly because at higher frequencies, the RC time constant will increase and this will make the input and output signal be out of phase. Phase Log (Gain) and Log (Phase) Gain Log (Hz) Figure 16a 32 Receiving Side of the Circuit (2nd order LPF) The following graph shows the frequency respond of gain and phase of the receiving side of the circuit in Log(gain) vs. Log(ω) and Log(phase) vs. Log(ω). The gain is approximately 1 at low frequencies and drops off to 0.703 at -3dB is because it is a passive low pass filter, which is designed to have a gain of 1 and at high frequencies the gain drops due to the design of RC values. As for the phase, as frequency increases, the input and output will be more out of phase due to the RC time constant. Gain Log (Gain) and Log (Phase) Phase Log (Hz) Figure 16b 33 Conclusion The final goal of this project is to transmit a modulated audio signal optically, receive the signal and demodulate the audio signal within several feet away is successful. The circuit build is placed into a box which holds everything in place. According to the test result waveforms, it corresponds with the PSPICE simulations waveforms and is as expected in terms of how the signal behaves and its amplitude. The waveforms for the PWM and how to demodulate the PWM signal into a sine wave are consistent with the background research. The key point into making this project successful is to do a thorough research on the parts such as fast comparator/op-amp, clock oscillator and troubleshooting the circuit. Also, one thing to keep in mind is that there should not be any DC voltage being input into the comparator thus that is the reason why there is a coupling capacitor to bias out DC components. Basically, only AC signal can be input into the comparator. Also, in order to produce a clean PWM signal is to first produce a stable carrier signal as a reference signal at desired frequency. This carrier signal has to be greater in AC voltage than the audio signal at all times or else it will be cut off. If we were to redo this project, we would research for a fast comparator that can compare frequencies of over 1MHz, build an active LPF for integration as well as demodulation and search for parts which uses higher power to give a high voltage swing of the AC signal. This will be sufficient for transmitting the signal optically. From this course, we’ve learn important issues such as how a background research can save time from trouble shooting the circuit. If a thorough research is done and the circuit is well understood, then there should not be much to troubleshoot besides wiring errors. Another important issue is to have a good PSPICE simulation of what the ideal circuit may be to have an understanding of how the waveforms may change under different constraint. Lastly, teamwork is rather important in order to get the task complete in the end because if one group delays, then the other group has to wait in order to proceed. For example, if the optical group was finished early, but the PWM or FM was not ready to transmit the signal, then the task will be delay. 34 References Sedra and Smith. Microelectronic Circuit. 5th Edition. Oxford University Press, 2003. Wikipedia, The Free Encyclopedia. 18 Dec. 2007. <http://en.wikipedia.org/wiki/Lowpass_filter> 35 Appendix A – CMX309 36 Appendix B – OP-AMP LM7171 37 38 39 40 41 Appendix C – OP-AMP TLV2362 42 43 44 45