Beruflich Dokumente
Kultur Dokumente
By:
Val Tocitu
Jason Kulpe
Alexandre Mariuzza
Presenter: Val Tocitu
Introduction and definitions
Types of PWM
Methods of generation
Characteristics of PWM
Applications and examples
Implementation on the HCS12
PWM output is
formed by the
intersection of
the saw-tooth
wave and
sinusoid
Requirements
1. Maxon EC-16 brushless motor,
Time constant = 8.75 ms
1
8.5 ms f 117 Hz
f
2. Want to avoid audible frequencies
f 20 kHz
3. PID control loop running at 150 Hz
f 10 150 Hz
Pulse Width Modulation - Val Tocitu,
10/29/2009 Jason Kulpe, Alex Mariuzza 24
Example: Specifying circuit elements
1.44
f
R1C1
Check constraints
Set f to 25 kHz to add in a factor of safety
117 Hz
Choosing C1 to be 100 nF, R1 is 576 ~ 500
f 20 kHz
1.5 kHz
Recalculating with these values f = 28.8 kHz
Pulse Width Modulation - Val Tocitu,
10/29/2009 Jason Kulpe, Alex Mariuzza 25
Matlab can do PWM!
H
Critical Velocity Motor Control
BIGGER
SMALL
U
Texas Instruments
TAS5508B
G
8-Channel Digital Audio
PWM Processor
64 pin chip, max 192 kHz 18 kHz frequency 120 amps, used for
E
frequency Continuous 28 amps hybrid vehicles
$7.25 $55.95 $469.00
Pulse Width Modulation - Val Tocitu,
10/29/2009 Jason Kulpe, Alex Mariuzza 27
Presenter: Alex Mariuzza
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
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
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
Located at $00E3
Variable: PWMPRCLK
Used to prescale clocks A and B
Located at $00E8
Code Warrior variable: Clock A Frequency
Clock SA Frequency
PWMSCLA 2 PWMSCLA
Store a hexadecimal value
in order to change the clock
frequency of SA
Note: if set to $00,
PWMSCLA is set to 256
Located at $00E9
Code Warrior variable: Clock B Frequency
Clock SB Frequency
PWMSCLB 2 PWMSCLB
Store a hexadecimal value
in order to change the clock
frequency of SA
Note: if set to $00,
PWMSCLB is set to 256
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
Located at $00E5
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
Pulse Width Modulation - Val Tocitu,
10/29/2009 Jason Kulpe, Alex Mariuzza 41
PWM Counter Register
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
PWM5INL: Determines active level of pin 5 45
How it all works
Clock A, SA, B, or SB
ORG $1000
LDAA #$00
STAA PWMCLK ; Sets source clocks to clock A
STAA PWMPOL ; The signal goes from low to high
STAA PWMCTL ; Makes all channels 8-bit
STAA PWMCAE ; Signals are left aligned
LDAA #$FA
STAA PWMPER1 ; Sets the period to 250 clock cycles
LDAA #$AF
STAA PWMDTY1 ; Makes the duty cycle equal to 30%
LDAA #$02
STAA PWMPRCLK ; Sets the prescaler to 4
STAA PMWE ; Enables and starts channel 1
10/29/2009 48
C Code
#include <hidef.h> /* common defines and macros */
#include <mc9s12c32.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE mc9s12c32