HCS12 Technical Training Module
description
Transcript of HCS12 Technical Training Module
Add additional legal text here if required by your local Legal Counsel.
Version # : 1.0 Date: 04-April-2002
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
HCS12 Technical TrainingModule
PWM
HCS12 Technical Training Module 9-PWM, Slide 2
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
What is PWM?
period
on
TT
Ratio Width Pulse
Ton Toff
Tperiod
Average
0 %
10 %
50 %
90 %
99 %
Applications: Digital-Analog Conversion Electrical Motor Control Tone Generation Sine Waveform Generation
HCS12 Technical Training Module 9-PWM, Slide 3
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
Generation of PWM Signals (Edge Aligned)
Start
Period TPWM
TPWM
Duty Cycle TDuty
PWMDTYx PWMPERx PWMPERx
fClock, TClock
8-bit CounterPWMCNTx
Clock
8-bit Compare =PWMDTYx
8-bit Compare =PWMPERx
0x00 0x00
Reset
Pin
HCS12 Technical Training Module 9-PWM, Slide 4
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Features
8 independent PWM channels with programmable period and duty cycle
Four clock sources with programmable clock select logic
Dedicated counter for each PWM channel
PWM duty pulse polarity for each channel
Enable/disable for each PWM channel
Double Buffering of period and duty cycle
Individual center aligned or left aligned outputs on each channel
Resolution: 8-bit (8 channel), 16-bit (4 channel)
Emergency shutdown with interrupt capability
Operation Modes
HCS12 Technical Training Module 9-PWM, Slide 5
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Block Diagram
Channel 7
Period and Duty Counter
Channel 6
Period and Duty Counter
...Channel 0
Period and Duty Counter
Pin
Enable
Polarity
Alignment
Back
Pin
Pin
HCS12 Technical Training Module 9-PWM, Slide 6
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Clock Select (1 of 4)1. Clock A (Ch 0, Ch 1, Ch 4, Ch 5)
2. Clock SA (scaled A; Ch 0, Ch 1, Ch 4, Ch 5)
3. Clock B (Ch 2, Ch 3, Ch 6, Ch 7)4. Clock SB (scaled B; Ch 2, Ch 3, Ch 6, Ch 7)
Four clock sources:
Bus ClockDivide by Prescaler Taps:
2 4 8 16 32 64 128
PRESCALE
PWMPRCLK @ $_03 Clock SA
Clock SB
Clock A
Further Division of the clock:
2 4 6 8 ... 512
Clock B
Further Division of the clock:
2 4 6 8 ... 512
PWMSCLA @ $_08
PWMSCLB @ $_09
SCALE
HCS12 Technical Training Module 9-PWM, Slide 7
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Clock Select - PRESCALE (2 of 4)
0 PCKB2 PCKB1 PCKB0 0 PCKA2 PCKA1 PCKA0R
WReset: 0 0 0 0 0 0 0 0
= Unimplemented or Reserved
PWMPRCLK @ $_03
PCKx2 PCKx1 PCKx0 Value of Clock x
0 0 0 Bus Clock
0 0 1 Bus Clock / 2
0 1 0 Bus Clock / 4
0 1 1 Bus Clock / 8
1 0 0 Bus Clock / 16
1 0 1 Bus Clock / 32
1 1 0 Bus Clock / 64
1 1 1 Bus Clock / 128
Can be read and written anytime!x = A or B
Setting the PRESCALE Register:PWMPRCLK = 0x22; // B= Bus/4, A = Bus/4PWMPRCLK = 0x07; // B = Bus, A = Bus/128
Software Examples
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 8
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Clock Select - SCALE (3 of 4)
Bus ClockfBus
Divide by Prescaler Taps:
2 4 8 16 32 64 128
8-Bit Down Counter
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
PWMSCLxScale Value
SxClockxClockPWMSCLx
PWMSCLxxClockSxClock
_2_
2__
PWMSCLx = $00 PWMSCLx value is 256Can be read and written anytime!x = A or B
/ 2Clock Sx
Clock x
Clock x =fBus / PWMPRCLK
Count = 1
PWMPRCLK @ $_03
PWMSCLB @ $_09 PWMSCLA @ $_08
Example:Required: Clock Sx = 1 kHzBus Clock = 16 MHz
Prescaler = 128 Prescaler = 64Clock x = 125 kHz Clock x = 250 kHzPWMSCLx = 63 PWMSCLx = 125 Clock Sx = 992 Hz Clock Sx = 1000 Hz
HCS12 Technical Training Module 9-PWM, Slide 9
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Clock Select (4 of 4)
PCLK6 PCLK5 PCLK4 PCLK3 PCLK2 PCLK1 PCLK0R
WReset: 0 0 0 0 0 0 0 0
PWMCLK @ $_02
PCLK7
PCLK7 — Pulse Width Channel 7 Clock Select1 = Clock SB is the clock source for PWM channel 7.0 = Clock B is the clock source for PWM channel 7.
PCLK6 — Pulse Width Channel 6 Clock Select1 = Clock SB is the clock source for PWM channel 6.0 = Clock B is the clock source for PWM channel 6.
PCLK5 — Pulse Width Channel 5 Clock Select1 = Clock SA is the clock source for PWM channel 5.0 = Clock A is the clock source for PWM channel 5.
PCLK4 — Pulse Width Channel 4 Clock Select1 = Clock SA is the clock source for PWM channel 4.0 = Clock A is the clock source for PWM channel 4.
PCLK3 — Pulse Width Channel 3 Clock Select1 = Clock SB is the clock source for PWM channel 3.0 = Clock B is the clock source for PWM channel 3.
PCLK2 — Pulse Width Channel 2 Clock Select1 = Clock SB is the clock source for PWM channel 2.0 = Clock B is the clock source for PWM channel 2.
PCLK1 — Pulse Width Channel 1 Clock Select1 = Clock SA is the clock source for PWM channel 1.0 = Clock A is the clock source for PWM channel 1.
PCLK0 — Pulse Width Channel 0 Clock Select1 = Clock SA is the clock source for PWM channel 0.0 = Clock A is the clock source for PWM channel 0.Back
Select Clock Source:PCLK0 = 1; // SA is source of ch 0PCLK6 = 0; // B is source of ch 6PWMCLK = 0x11; // all channels
Software Examples
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 10
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWMPERx
PWMDTYx
PWM Timer Channel
8-Bit Counter
PWMCNTx
8-Bit Compare =
PWMDTYx
8-Bit Compare =
PWMPERx
PWMCNT0 @ $_0CPWMCNT1 @ $_0DPWMCNT2 @ $_0EPWMCNT3 @ $_0FPWMCNT4 @ $_10PWMCNT5 @ $_11 PWMCNT6 @ $_12PWMCNT7 @ $_13
PWMDTY0 @ $_1CPWMDTY1 @ $_1DPWMDTY2 @ $_1E PWMDTY3 @ $_1FPWMDTY4 @ $_20 PWMDTY5 @ $_21PWMDTY6 @ $_22PWMDTY7 @ $_23
PWMPER0 @ $_14PWMPER1 @ $_15PWMPER2 @ $_16PWMPER3 @ $_17PWMPER4 @ $_18PWMPER5 @ $_19PWMPER6 @ $_1APWMPER7 @ $_1B
Polarity Bit = 1 Duty = High Time
Back
Channel xx = 0 ... 7
DoubleBuffered
DoubleBuffered
PWMDTYx
PWMPERx
HCS12 Technical Training Module 9-PWM, Slide 11
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
Enable/Disable PWM
PWME6 PWME5 PWME4 PWME3 PWME2 PWME1 PWME0R
WReset: 0 0 0 0 0 0 0 0
PWME @ $_00
PWME7
Back
1 = Pulse Width channel x is enabled. The pulse modulated signal becomes available at PWM output bit x when its clock source begins its next cycle.
0 = Pulse Width channel x is disabled.
Channel 7 Channel 6 Channel 0...
Enable/Disable PWM channels:PWME5 = 1; // Enable PWM channel 5PWME3 = 0; // Disable PWM channel 3PWME = 0xFF // Enable all 8 PWM channelsPWME = 0; // Disable all 8 PWM channels
Software Examples
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 12
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Polarity Enable Register
PPOL6 PPOL5 PPOL4 PPOL3 PPOL2 PPOL1 PPOL0R
WReset: 0 0 0 0 0 0 0 0
PWME @ $_00
PPOL7
Channel 7 Channel 6 Channel 0...
1 = PWM channel x output is high at the beginning of the period, then goes low when the duty count is reached.
0 = PWM channel x output is low at the beginning of the period, then goes high when the duty count is reached.
Back
PWMDTYx
PWMPERx
PPOLx = 1
PWMDTYx
PWMPERx
PPOLx = 0
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 13
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
Left Aligned Output (1 of 3)
Clock SourceE = 100 ns
Duty Cycle= 75 %
Period= 400 ns
%100_:1
%100_:0
),,,(_
PWMPERxPWMDTYxCycleDutyPolarity
PWMPERxPWMDTYxPWMPERxCycleDutyPolarity
PWMPERxSBSABAClockFrequencyPWMx
Clock Source = E = 10 MHz (100 ns period)PPOLx = 0PWMPERx = 4PWMDTYx = 1
PWMx Frequency = 10 MHz/4 = 2.5 MHzPWMx Period = 400 nsPWMx Duty Cycle = ¾*100% = 75%
Start
HCS12 Technical Training Module 9-PWM, Slide 14
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
Center Aligned Output (2 of 3)
PWMDTYxE = 100ns
Period = PWMPERx*2= 800 ns
%100_:1
%100_:0
2),,,(_
PWMPERxPWMDTYx
CycleDutyPolarity
PWMPERxPWMDTYxPWMPERxCycleDutyPolarity
PWMPERxSBSABAClockFrequencyPWMx
Clock Source = E = 10 MHz (100 ns period)PPOLx = 0PWMPERx = 4PWMDTYx = 1
PWMx Frequency = 10 MHz/8 = 1.25 MHzPWMx Period = 800 nsPWMx Duty Cycle = ¾*100% = 75%
Start
PWMDTYxE = 100ns
PWMPERx PWMPERx
Duty Cycle = 75%
HCS12 Technical Training Module 9-PWM, Slide 15
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Center Align Enable Register (3 of 3)
Back
CAE6 CAE5 CAE4 CAE3 CAE2 CAE1 CAE0R
WReset: 0 0 0 0 0 0 0 0
PWMCAE @ $_04
CAE7
Channel 7 Channel 6 Channel 0...
CAEx – Center aligned Output Mode on channel x1 = Channel x operates in Center Aligned Output Mode0 = Channel x operates in Left Aligned Output Mode
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 16
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
16-Bit ResolutionTwo 8-bit channels of the PWM module can be concatenated to a 16-Bit PWM channel
Period/Duty Compare
PWMCNT6 PWMCNT7
PWM7
Clock Source 7
CONxx PWMEx PPOLx PCLKx CAEx PWMx OUTPUT
CON67 PWME7 PPOL7 PCLK7 CAE7 PWM7
CON45 PWME5 PPOL5 PCLK5 CAE5 PWM5
CON23 PWME3 PPOL3 PCLK3 CAE3 PWM3
CON01 PWME1 PPOL1 PCLK1 CAE1 PWM1Back
HCS12 Technical Training Module 9-PWM, Slide 17
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
Emergency Shutdown
Emergency ShutdownChannel 7
Channel 6
Period and Duty Counter
Channel 5
Period and Duty Counter
...Channel 0
Period and Duty Counter
FaultInput PWMLVL=1 PWMLVL=0
PWM7INL=1
PWMLVL=0
InterruptPWMIE
PWMIF
HCS12 Technical Training Module 9-PWM, Slide 18
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Shutdown Register
PWMIE PWMRSTRT
PWMLVL 0PWM7INL PWM7EN
R
WReset: 0 0 0 0 0 0 0 0
PWMSDN @ $_24
PWMIF
Back
0 PWM7IN
= Unimplemented or Reserved
Set shutdown active levelPWM7INL
Set shutdown output levelPWMLVL
Enable emergency shutdownPWM7ENA
Initialisation
Interrupt EnablePWMIE
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 19
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
Modes of Operation
Wait Mode
Allow input clock to prescaler
while in WAIT
PSWAI=
10
Stop input clock to prescaler
while in WAIT
Freeze Mode
PWM continue while in FREEZE
PFRZ=
10
Disable input clock to prescaler
while in FREEZE
HCS12 Technical Training Module 9-PWM, Slide 20
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Control Register
CON45 CON01 0PSWAIR
WReset: 0 0 0 0 0 0 0 0
PWMCTL @ $_05
CON67
= Unimplemented or Reserved
CON23 PFRZ 0Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
16 bit operation
Enable/Disable clockin WAIT
Enable/Disable clockIn FREEZE
Back
HCS12 Technical Training Module 9-PWM, Slide 21
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Channel Period Registers
Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0R
WReset: 1 1 1 1 1 1 1 1
PWMPERx @ $_14-_1B
Bit 7
Back
PeriodClockChannelPeriodPWMxPWMPERx
PWMPERxPeriodClockChannelPeriodPWMx
__2_
2___0)(CAExOutput AlignedLeft
OutputAlignedCenterPeriodPWMxPWMPERx
OutputAlignedCenterPWMPERxPeriodClockChannelPeriodPWMx
__2_
_____1)(CAExOutput AlignedCenter
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 22
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
PWM Channel Duty Registers
Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0R
WReset: 1 1 1 1 1 1 1 1
PWMDTYx @ $_1C-_23
Bit 7
Back
%100_
1)(PPOLx 1 Polarity
%100_
0)(PPOLx 0 Polarity
PWMPERxPWMDTYxCycleDuty
PWMPERxPWMDTYxPWMPERxCycleDuty
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
HCS12 Technical Training Module 9-PWM, Slide 23
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective owners. © Motorola, Inc. 2001.
Setup the PWM
1. Disable PWMPWME
2. Select clock (prescaler and scale) for the PWM PWMPRCLK, PWMSCLA, PWMSCLB, PWMCLK
3. Select polarityPWMPOL
4. Select center or left aligned modePWMCAE
5. Program duty cycle and periodPWMDTYx, PWMPERx
6. Enable used PWM channelsPWME