Pulse Width Modulation ME 44476405 October 29 th
Pulse Width Modulation ME 4447/6405 October 29 th, 2009 By: Val Tocitu Jason Kulpe Alexandre Mariuzza
Presenter: Val Tocitu v Introduction and definitions v Types of PWM v Methods of generation v Characteristics of PWM v Applications and examples v Implementation on the HCS 12 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 2
What is it? �Output signal alternates between on and off within specified period �Controls power received by a device �The voltage seen by the load is directly proportional to the source voltage 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 3
Definitions �Duty Cycle: on-time / period �Vlow is often zero 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 4
Types of Pulse Width �Pulse center fixed, edges modulated �Leading edge fixed, tailing edge modulated �Tailing edge fixed, leading edge modulated �Pulse Width constant, period modulated 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 5
Types of Pulse Width 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 6
Analog Generation of PWM Analog PWM signals can be made by combining a saw- tooth waveform and a sinusoid PWM output is formed by the intersection of the saw-tooth wave and sinusoid 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 7
Digital Methods of Generating PWM �Digital: Counter used to handle transition �Delta : used to find the PWM at a certain limit �Delta Sigma: used to find the PWM but has advantage of reducing optimization noise 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 8
Applications to DC Motors • The voltage supplied to a DC motor is proportional to the duty cycle • Both brushed and brushless motors can be used with PWM • Both analog and digital control techniques and components are available 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 11
Three Phase AC motors with PWM � 3 different AC currents at different phases �Phase: 120 degrees apart �Creates constant power transfer �Rotating magnetic field �Pulses substitute for AC current 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 12
Space Vector Modulation Used for three-phase AC motors Convert DC current to AC current Gates turned on/off at different intervals 3 PWM created 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 13
Motor Control Diagrams 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 14
Advantages of PWM • average value proportional to duty cycle, D • low power used in transistors used to switch the signal • fast switching possible due to MOSFETS and power transistors at speeds in excess of 100 k. Hz • digital signal is resistant to noise • less heat dissipated versus using resistors for intermediate voltage values 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 15
Disadvantages of PWM �Cost �Complexity of circuit �Radio Frequency Interference �Voltage spikes �Electromagnetic noise 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 16
Presenter: Jason Kulpe v Introduction and definitions v Types of PWM v Methods of generation v Characteristics of PWM v Applications and examples v Implementation on the HCS 12 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 17
Applications of PWM • In the past, motors were controlled at intermediate speed by using resistors to lower delivered power • Electric stove heater • Lamp dimmers • Voltage regulation – convert 12 volts to 5 volts by having a 41. 7% duty cycle • Sound production: PWM controlled signals give sound effects similar to a chorus • Power transfer: PWM used to reduce the total power given to a load without relying on resistive losses 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 18
PWM used with D/A conversion • commonly used in toys • lowpass filter smooths out transients from harmonic effects • frequency values of harmonics doesn’t change, but the amplitude does, which adjusts the analog output signal 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 19
PWM used to transmit data in telecommunications • clock signal is found “inside” PWM signal • more resistant to noise effects than binary data alone • effective at data transmission over long distance transmission lines 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 20
Frequency of the PWM Signal Upper Limits Lower Limits 1. Must be at least 10 times higher than the control system frequency 2. Higher than 20 k. Hz – audible frequency of sounds to avoid annoying sound disturbances, caused by magnetostriction 3. If too low the motor is pulsed, not continuous, because the motor’s inductance can not maintain the current 4. Inverse of frequency should be much less than the motor/load time constant 5. Higher error from ripple voltages 10/29/2009 1. If too high the inductance of the motor causes the current drawn to be unstable 2. MOSFET transistor generates heat during switching 3. Limited by resolution of controller 4. Eddy currents generated in electromagnetic coils which lead to adverse heating 5. Heat losses in electromagnetic materials is proportional to frequency squared Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 22
Example: PWM with 555 Timer Potentiometer is used to adjust the duty cycle 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 23
Example: Specifying circuit elements Requirements 1. Maxon EC-16 brushless motor, Time constant = 8. 75 ms 2. Want to avoid audible frequencies f ≥ 20 k. Hz 3. PID control loop running at 150 Hz f ≥ 10 ∙ 150 Hz 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 24
Example: Specifying circuit elements This circuit has a PWM frequency according to: Check constraints Set f to 25 k. Hz to add in a factor of safety f Choosing C 1 to be 100 n. F, R 1 is 576 Ω ~ 500 Ω Recalculating with these values f = 28. 8 k. Hz 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason ≥ 117 Hz ≥ 20 k. Hz ≥ 1. 5 k. Hz 25
Matlab can do PWM! The procedure works similar to the generation of analog PWM using a sinusoid and sawtooth wave 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 26
Where can I buy a PWM controller? Texas Instruments Digikey Mouser Electronics Critical Velocity Motor Control BIGGER SMALL Texas Instruments TAS 5508 B 8 -Channel Digital Audio PWM Processor 18 k. Hz frequency 64 pin chip, max 192 k. Hz Continuous 28 amps frequency $55. 95 $7. 25 Pulse Width Modulation - Val Tocitu, 10/29/2009 Kulpe, Alex Mariuzza Jason 120 amps, used for hybrid vehicles $469. 00 H U G E 27
Presenter: Alex Mariuzza v Introduction and definitions v Types of PWM v Methods of generation v Characteristics of PWM v Applications and examples v Implementation on the HCS 12 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 28
PWM Implementation �The signal is outputted through Port P �Six Channels �Dedicated Chip 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 29
PWM Module �Each channel has a dedicated counter �Programmable duty and period �Independently adjustable clock, polarity, and alignment 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 30
PWM Module- Other Features � 8 -bit and 16 -bit resolution supported �Two PWM channels can be concatenated together �Four source clocks (A, SA, B, SB) �Emergency Shutdown �Some changes take a complete cycle to be implemented �Modes of Operation: �Normal: everything is available �Wait: Low-power consumption and clock disabled �Freeze: Option to disable clock is available 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 31
PWM Configuration �Configured through specific registers �Registers are located from $00 E 0 to $00 FE �There are repeated registers (ex. 0013 -0017) 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 32
PWM Enable Register �Located at $00 E 0 �Code Warrior variable: PWME �Set PWMEx to 0 to disable the channel �Set PWMEx to 1 to enable it �Channel is activated when bit is set �If 16 -bit resolution used, then PWME 4/2/0 are deactivated 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 33
PWM Polarity Register �Located at $00 E 1 �Code Warrior variable : PWMPOL �Set PPOLx to 0, signal goes from low to high �Set PPOLx to 1, signal goes from high to low 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 34
PWM Clock Select Register �Located at $00 E 2 �Code Warrior variable : PWMCLK �Set PCLK 5/4/1/0 to use clock A �Set PCLK 5/4/1/0 to 1 to use clock SA �Set PCLK 3/2 to 0 to use clock B �Set PCLK 3/2 to 1 to use clock SB 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 35
PWM Prescaler Register Located at $00 E 3 Variable: PWMPRCLK Used to prescale clocks A and B 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 36
PWM Scale A Register Located at $00 E 8 Code Warrior variable: PWMSCLA Store a hexadecimal value in order to change the clock frequency of SA Note: if set to $00, PWMSCLA is set to 256 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 37
PWM Scale B Register Located at $00 E 9 Code Warrior variable: PWMSCLB Store a hexadecimal value in order to change the clock frequency of SA Note: if set to $00, PWMSCLB is set to 256 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 38
PWM Center Align Register �Located at $00 E 4 �Code Warrior variable: PWMCAE �Set CAEx to 0 for left align signal �Set CAEx to 1 for center align signal �Note: can only be set when channel is disabled 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 39
Signal Alignment � Signal changes when counter is equal to period register � In the center aligned mode, the PWM counter goes from a down-count to a up-count to down-count, etc. � In the left aligned mode, the PWM counter is a up-counter and rests to zero when it overflows 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 40
PWM Control Register � Located at $00 E 5 � Code Warrior variable: PWMCTL � Set CONxy to 0 to keep PWM channels separate (8 -bit) � Set CONxy to 1 to concatenate PWM channels x and y together (16 bit). � Channel y determines the configuration � x becomes the high byte and y becomes the low byte � Bits PSWAI and PFRZ set either wait or freeze mode � Changes only occur when channels are disabled 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 41
PWM Counter Register �Located at $00 EC through $00 F 1 �Code Warrior variable: PWMCNTx �One per channel �It tracks the cycle counts �It can be read �If written to, the count is reset to $00 and a up-count starts 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 42
PWM Period Register Located at $00 F 2 through $00 F 7 Left-Aligned: Variable: PWMPERx Store a hexadecimal value to limit maximum value of counter Changes occur when: Center-Aligned: Current period ends Counter is written to Channel is disabled 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 43
PWM Duty Register • • Located at $00 F 8 through $00 FD Code Warrior variable: PWMDTYx Store a hexadecimal value to control when signal changes Changes occur when: • Current period ends • Counter written to • Channel is disabled Polarity = 0: 10/29/2009 Polarity = 1: 44
PWM Shutdown Register • • Located at $00 FE Code Warrior variable: PWMSDN PWMENA: Enables and disables emergency shut down PWMIF (Interrupt flag): Set when an input is detected in pin 5 PWMIE (Interrupt Enable): Enables and disables CPU interrupts PWMRSTRT: Resets the counters PWMLVL (Shutdown Output Level): Determines if output is high or low when shutdown • PWM 5 IN (Input Status): Reflects status of pin 5 45 • PWM 5 INL: Determines active level of pin 5
How it all works Clock A, SA, B, or SB 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 46
Example Desired Signal: 8 k. Hz PWM signal Duty Cycle of 30% Left Aligned Channel 1 Low → High 8 -bit channel 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 47
Assembly Code PWME PWMPOL PWMCLK PWMPRCLK PWMCAE PWMCTL PWMPER 1 PWMDTY 1 10/29/2009 EQU EQU $00 E 0 $00 E 1 $00 E 2 $00 E 3 $00 E 4 $00 E 5 $00 F 3 $00 F 9 ORG LDAA STAA LDAA STAA …… $1000 #$00 PWMCLK PWMPOL PWMCTL PWMCAE #$FA PWMPER 1 #$AF PWMDTY 1 #$02 PWMPRCLK PMWE ; Sets source clocks to clock A ; The signal goes from low to high ; Makes all channels 8 -bit ; Signals are left aligned ; Sets the period to 250 clock cycles ; Makes the duty cycle equal to 30% ; Sets the prescaler to 4 ; Enables and starts channel 1 48
C Code #include <hidef. h> /* common defines and macros */ #include <mc 9 s 12 c 32. h> /* derivative information */ #pragma LINK_INFO DERIVATIVE “mc 9 s 12 c 32” // Set up chip in expanded mode MISC = 0 x 03; PEAR = 0 x 0 C; MODE = 0 x. E 2; //Set up PWM Registrer PWMCLK = 0; // Sets source clocks to clock A PWMPOL = 0; // The signal goes from low to high PWMCTL = 0; // Makes all channels 8 -bit PWMCAE = 0; // Signals are left aligned PWMPER 1 = 250; // Sets the period of the signal to 250 clock PWMDTY 1 = 175; // Makes the duty cycle equal to 30% PWMPRCLK = 2; //Sets the prescaler to 4 PMWE = 2; //Enables and starts channel 1 …. Pulse Width Modulation - Val Tocitu, 10/29/2009 Jason Kulpe, Alex Mariuzza 49
REFERENCES http: //en. wikipedia. org/wiki/Pulse-width_modulation http: //www. netrino. com/Embedded-Systems/How-To/PWM-Pulse-Width-Modulation Cetinkunt, Sabri. Mechatronics. Hoboken, NJ: Wiley, 2006. Print. http: //www. jimfranklin. info/microchipdatasheets/00538 c. pdf http: //www. allaboutcircuits. com/vol_6/chpt_6/9. html http: //www. dprg. org/tutorials/2005 -11 a/index. html http: //www. 4 qdtec. com/pwm-01. html http: //skywalker. cochise. edu/rgill/ch 02 elec. ppt http: //pcbheaven. com/wikipages/PWM_Modulation/ Matlab 2009 online documentation http: //www. epanorama. net/links/motorcontrol. html#ac MC 9 S 12 C Family, MC 9 S 12 GC Family Reference Manual, (pp. 347 -382) 10/29/2009 Pulse Width Modulation - Val Tocitu, Kulpe, Alex Mariuzza Jason 50
Questions? 10/29/2009 Pulse Width Modulation - Val Tocitu, Jason Kulpe, Alex Mariuzza 51
- Slides: 48