By: Val Tocitu Jason Kulpe Alexandre Mariuzza: ME 4447/6405 October 29, 2009
By: Val Tocitu Jason Kulpe Alexandre Mariuzza: ME 4447/6405 October 29, 2009
By: Val Tocitu Jason Kulpe Alexandre Mariuzza: ME 4447/6405 October 29, 2009
By:
Val Tocitu
Jason Kulpe
Alexandre Mariuzza
10/29/2009
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
Definitions
Duty Cycle: on-time / period
Vlow is often zero
10/29/2009
10/29/2009
10/29/2009
10/29/2009
10/29/2009
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
11
different phases
Phase: 120 degrees apart
transfer
Rotating magnetic field
Pulses substitute for AC
current
10/29/2009
12
10/29/2009
13
10/29/2009
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 kHz
digital signal is resistant to noise
less heat dissipated versus using resistors
for intermediate voltage values
10/29/2009
15
Disadvantages of PWM
Cost
Complexity of circuit
Radio Frequency Interference
Voltage spikes
Electromagnetic noise
10/29/2009
16
10/29/2009
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
18
10/29/2009
19
10/29/2009
20
22
10/29/2009
23
Requirements
1. Maxon EC-16 brushless motor,
Time constant = 8.75 ms
1
8.5 ms
f
f 117 Hz
24
1.44
f
R1C1
Check constraints
Set f to 25 kHz to add in a factor of safety
Choosing C1 to be 100 nF, R1 is 576 ~ 500
Recalculating with these values f = 28.8 kHz
10/29/2009
117 Hz
20 kHz
1.5 kHz
25
26
BIGGER
SMAL
L
Texas Instruments
TAS5508B
8-Channel Digital
Audio PWM
Processor
64 pin chip, max
192 kHz frequency
$7.25
10/29/2009
18 kHz frequency
Continuous 28
amps
Pulse Width
Modulation - Val Tocitu,
$55.95
Jason Kulpe, Alex Mariuzza
H
U
G
E
27
10/29/2009
28
PWM Implementation
The signal is outputted
through Port P
Six Channels
Dedicated Chip
10/29/2009
29
PWM Module
Each channel has a
dedicated counter
Programmable duty
and period
Independently
adjustable clock,
polarity, and
alignment
10/29/2009
30
10/29/2009
31
PWM Configuration
Configured through
specific registers
Registers are located from
$00E0 to $00FE
There are repeated
registers (ex. 0013-0017)
10/29/2009
32
Located at $00E0
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 PWME4/2/0 are deactivated
10/29/2009
33
Located at $00E1
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
34
Located at $00E2
Code Warrior variable : PWMCLK
Set PCLK5/4/1/0 to 0 to use clock A
Set PCLK5/4/1/0 to 1 to use clock SA
Set PCLK3/2 to 0 to use clock B
Set PCLK3/2 to 1 to use clock SB
10/29/2009
35
Located at $00E3
Variable: PWMPRCLK
Used to prescale clocks A and B
Presclarer
10/29/2009
36
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
Clock SA Frequency
Clock A Frequency
2 PWMSCLA
37
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
Clock SB Frequency
Clock B Frequency
2 PWMSCLB
38
Located at $00E4
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
39
Signal Alignment
Signal changes when counter
10/29/2009
40
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
41
10/29/2009
42
10/29/2009
Left-Aligned:
PWMPERx
Center-Aligned:
PWM Source Frequency
PWMPERx
2 PWM Signal Frequency
43
44
Located at $00FE
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
PWM5IN (Input Status): Reflects status of pin 5
45
PWM5INL: Determines active level of pin 5
10/29/2009
46
Example
8 106
Prescaler 8
3.91 4 PWMPRCLK $02
(2 1) 8 103
Desired Signal:
8 kHz PWM signal
Duty Cycle of 30%
Left Aligned
Channel 1
Low High
8-bit channel
8 10 6
4
2 10 6
PWMPER1
250 $FA
8 103
8 103
PWMDTY1 250 -
30 250
175 $AF
100
PWMCLK $00
PWMCAE $00
PWMPOL $00
PWMCTL $00
PWME $02
10/29/2009
47
Assembly Code
PWME
EQU
PWMPOL EQU
PWMCLK EQU
PWMPRCLK
PWMCAE
PWMCTL EQU
PWMPER1
PWMDTY1
ORG
LDAA
STAA
STAA
STAA
STAA
LDAA
STAA
LDAA
STAA
LDAA
STAA
STAA
10/29/2009
$00E0
$00E1
$00E2
EQU
EQU
$00E5
EQU
EQU
$00E3
$00E4
$00F3
$00F9
$1000
#$00
PWMCLK ; Sets source clocks to clock A
PWMPOL ; The signal goes from low to high
PWMCTL ; Makes all channels 8-bit
PWMCAE ; Signals are left aligned
#$FA
PWMPER1
; Sets the period to 250 clock cycles
#$AF
PWMDTY1
; Makes the duty cycle equal to 30%
#$02
PWMPRCLK
; Sets the prescaler to 4
PMWE
; Enables and starts channel 1
48
C Code
#include <hidef.h>
/* common defines and macros */
#include <mc9s12c32.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE mc9s12c32
// Set up chip in expanded mode
MISC = 0x03;
PEAR = 0x0C;
MODE = 0xE2;
//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
PWMPER1 = 250; // Sets the period of the signal to 250 clock
PWMDTY1 = 175; // Makes the duty cycle equal to 30%
PWMPRCLK = 2;
//Sets the prescaler to 4
PMWE = 2;
//Enables and starts channel 1
.
10/29/2009
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/00538c.pdf
http://www.allaboutcircuits.com/vol_6/chpt_6/9.html
http://www.dprg.org/tutorials/2005-11a/index.html
http://www.4qdtec.com/pwm-01.html
http://skywalker.cochise.edu/rgill/ch02elec.ppt
http://pcbheaven.com/wikipages/PWM_Modulation/
Matlab 2009 online documentation
http://www.epanorama.net/links/motorcontrol.html#ac
MC9S12C Family, MC9S12GC Family Reference Manual, (pp. 347-382)
10/29/2009
50
Questions?
10/29/2009
51