freescale hcs12 微控制器 mc9s12dp256
DESCRIPTION
Freescale HCS12 微控制器 MC9S12DP256. 2005 年 8 月. Enhanced Capture Timer Module 增强型捕捉定时器模块. ECT 模块结构. 一个 16 位向上带可编程预分频的主计数器 . 一个 16 位的带可编程预分频的模数向下计数器 8 个独立的定时器通道,每个通道具备输入捕捉和输出比较功能 4 个 8 位脉冲累加器,也可设置成 2 个 16 位脉冲累加器 . 通过对寄存器编程可以实现不同的功能. T O F. ******* ****** ** ****. $0000. $FFFF. - PowerPoint PPT PresentationTRANSCRIPT
Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
TM
Freescale HCS12 微控制器MC9S12DP256
2005 年 8 月
Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
TM
Enhanced Capture Timer Module增强型捕捉定时器模块
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 3
ECT 模块结构
• 一个 16 位向上带可编程预分频的主计数器 .
• 一个 16 位的带可编程预分频的模数向下计数器
• 8 个独立的定时器通道,每个通道具备输入捕捉和输出比较功能
• 4 个 8 位脉冲累加器,也可设置成 2 个 16 位脉冲累加器 .
• 通过对寄存器编程可以实现不同的功能
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 4
定时器结构
预分频选择
PR[2:0]
M Clock
1 2 4 8 16 32 64 128
TCNT
15...........................................0
DATA BUSPIN
R RRR
1 – 计数器使能0 – 计数器禁止
TEN TSWAI TSFRZ TFFCA
TSCR1 - 定时器控制寄存器
RST: 0 0 0 0 0 0 0 0
TCNT CLK
.TENB0.......……...B7 B8……..........B15
R = Reserved
$0006
Address Offset $0004, 05
$FFFE $FFFF $0000
******************* TOF
模块时钟
计数器寄存器
脉冲累加器
计时器溢出时,对溢出标志位置位,如允许中断,则向 CPU发出中断请求
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 5
定时器,预分频,计数器寄存器 :
1. TCNT
16 位自由运行 / 模计数器B15............................................................................................................................…B0
RST: 0........................................................................................................................0
Address Offset $0004, $0005
1 – 定时器溢出中断使能0 – 定时器中断禁止
$000D3. TSCR2
RST: 0 0 0 0 0 0 0 0
1 – 定时器由 OC7 比较符合时复位0 – 定时器自由运行
TCRE - 允许使用 PWM 功能
B7....................................................................................B0
TOI 0 0 0 TCRE PR2 PR1 PR0
2. TFLG2
定时器溢出标志位,写 ‘ 1’ 清零
TOF 0 0 0 0 0 0 0
B7......................................................................B0
RST: 0 0 0 0 0 0 0 0
$000F 标志寄存器
除以1248
163264
128
00001111
01010101
00110011
PR2 PR1 PR0
预分频系数选择
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 6
定时器编程步骤
用途: 产生周期中断• 初始化
1. 设定预分频系数2. 定时器溢出中断使能3. 定时器使能
• 中断函数1. 清标志位2. 用户自己的代码
void ECT_Init(void) { TSCR2_PR = 7; //prescale factor is 8, bus clock/128=8Mhz/8 TSCR2_TOI = 1; //timer overflow interrupt enable TSCR1_TEN = 1; //timer enable}
#pragma CODE_SEG NON_BANKED#pragma TRAP_PROCvoid Int_TimerOverFlow(void){ TFLG2_TOF = 1; //clear timer overflow flag // 用户自己的代码 …………….}#pragma CODE_SEG DEFAULT
在 PRM 文件中,加入VECTOR ADDRESS 0xFFDE Int_TimerOverFlow
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 7
输出比较功能
16 位自由运行计数器
16 位输出比较寄存器 比如: 0x5678 软件可以修改
引脚控制逻辑
中断请求
OCxF 状态标志位置位,当比较发生时(值相等时)
OCxI
中断屏蔽( 通过软件使能 )
• 共有 8 个输出比较通道• 每个通道有自己的向量表和控制寄存器
• 在特定的时刻输出一个信号
当比较寄存器的值和计数器的值相等时,采取行动比如:当 TCNT=0x5678
TCNT
TOCx
PinOCx
比较比较器 相等
置位
OR OR
清零 翻转
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 8
输出比较寄存器
C7F C6F C5F C4F C3F C2F C1F C0F
OM7 OL7 OM6 OL6 OM5 OL5 OM4 OL4
1. TC7 – TC0
2. TFLG1
3. TIE
4. TCTL1
比较 / 捕捉标志位写 ‘ 1’ 清除中断状态标志位
比较 / 捕捉屏蔽位 0 = 屏蔽中断请求 1 = 中断请求允许
OMX OLX Action on OCx
0011
0101
No Action OCxToggle OCxDrive OCx LODrive OCx HI
输出模式和输出电平 (O7–OC0)B6 B5 B4 B3B7 B2 B1 B0
5. TCTL2
B6 B5 B4 B3B7 B2 B1 B0
RST: 0 0 0 0 0 0 0 0
$0008
RST: 0 0 0 0 0 0 0 0
RST: 0 0 0 0 0 0 0 0
RST: 0 0 0 0 0 0 0 0
$000C
$000E
$0009
Address Offset
$0010 - $0011 - -$001E - $001F
16 位捕捉 / 比较寄存器 (TC7)
16 位捕捉 / 比较寄存器 (TC0)
--
C7F C6F C5F C4F C3F C2F C1F C0F
B6 B5 B4 B3B7 B2 B1 B0
OM3 OL3 OM2 OL2 OM1 OL1 OM0 OL0B6 B5 B4 B3B7 B2 B1 B0
FOC7 FOC6 FOC5 FOC4 FOC3 FOC2 FOC1 FOC0
6. CFORC
B7 B6 B5 B4 B3 B2 B1 B0
RST: 0 0 0 0 0 0 0 0$0001
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 9
输出比较 , OC7-OC0
中断 : •清除中断,对 TFLG1 其中的 OCxF 写’ 1’•不要使用位操作•使用 OC7-OC0 向量表
复位条件:• 自由运行计数器 (TCNT) 被初始化为 $0000 ,并且被禁止• 输出比较寄存器被初始化为 $0000•捕捉 / 比较引脚与比较功能断开•中断被禁止•标志位被清零•强制比较位被清零
•
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 10
输出比较 , 通道 7 OC7 (1 of 2)
用途 :
1 、多个输出比较引脚的控制
2 、通过 2 个输出比较来控制 1 个引脚,可以输出短脉冲
在每个时钟周期内,输出比较寄存器 7 和自由运行的计数器进行比较如果它们的值相等,则:
1 、中断标志位被置 12 、输出引脚 OC7-OC0 的状态被改变 或 / 和 产生中断
OC7 可以影响多个引脚( OC7-OC0 )当 OC7 和 OC7-OC0 某个引脚的动作有冲突时, OC7 的动作将被执行
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 11
输出比较 7 (2 of 2)
C7I C6F C5F C4F C3F C2F C1F C0F
OC7M7 OC7M6 OC7M5 OC7M4 OC7M3 OC7M2 OC7M1 OC7M0
4. TIE – 定时器中断允许使能
5. OC7M - OC7MASK
B7.............................................................................................B0
1 - TC7 -16 位比较寄存器 7.
RST: 0 0 0 0 0 0 0 0
RST: 0 0 0 0 0 0 0 0
$0002
$000C
C7F C6F C5F C4F C3F C2F C1F C0F
RST: 0 0 0 0 0 0 0 0
$000E
B7.............................................................................................B0
2. TCNT - 16- 位计数器B15...............................................................................................................................................................B0
RST: 0..................................................................................................................................................0
$0004, $05
B7.............................................................................................B03. TFLG1 – 标志位
OC7D7 OC7D6 OC7D5 OC7D4 OC7D3 OC7D2 OC7D1 OC7D0
6. OC7D - OC7DATA
RST: 0 0 0 0 0 0 0 0
$0003
B7.............................................................................................B0
OC7MASK 根据寄存器的设置,可以控制任意一路或全部输出比较引脚
OC7DATA 当 OC7 比较事件发生时,引脚的逻辑电平
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 12
定时器溢出时电平翻转
TOV7 TOV6 TOV5 TOV4 TOV3 TOV2 TOV1 TOV0
TOVx – 定时器溢出时,电平翻转只有当通道被配置成输出比较时,才有效
Address Offset $0007
RST: 0……………………………………………………………….…..0
1. TTOV - 定时器溢出时电平翻转寄存器
$000D
2. TSCR2 – 定时器系统控制寄存器
RST: 0 0 0 0 0 0 0 0
B7.....................................……………..............................................B0
TOI 0 0 0 TCRE PR2 PR1 PR0
1 – 定时器由 OC7 比较事件发生来复位0 – 定时器自由运行
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 13
输入捕捉 , IC7-IC0 (1 of 3)
用途 :1 、测量事件发生的间隔时间2 、对实时时间进行响应
输入捕捉能感应到引脚上的电平的变化如果发现电平变化,则:1 、计数器的值被保存到到输入捕捉寄存器中,状态标志位被置 12 、如果中断允许,则向 CPU 发出中断请求
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 14
输入捕捉功能
比较 / 捕捉 单元16 位自由运行计数器
16 位输入捕捉锁存器
捕捉发生时,状态位置 1
向 CPU 发出中断请求
Edge沿选择检测ICx
ICxF
ICxI
上升 / 下降沿
可选中断屏蔽
当外部事件发生时,或外部信号输入发生变化时,记录当前时间 TCNT
TICx
延时计数器
0 0 0 0 0 0 DLY1 DLY0
Bit 7 6 5 4 3 2 1 0DLYCT – 延时计数器控制寄存器
DLY[1:0] - Delay Counter Values 00 = Disabled 01 = 256 M Clocks 10 = 512 M Clocks 11 = 1024 M Clocks
Address Offset $0029
注 : 如果输入信号电平和跳变之前的电平相反时,延时计数器在当前时钟计数时刻产生一个脉冲,它用来去除噪声
OR OR
16 位保持寄存器
应用 : ABS 刹车 . 雷达测距,发动机
引脚
• 共有 8 个输入捕捉通道• 每个通道有自己的向量表和控制寄存器
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 15
输入捕捉 , IC7-IC0 (2 of 3)
B2 B1 B0
EDGxB
输入捕捉沿控制 (IC7–IC0)EDGxA ICx EDGE
0101
无边沿 – ICx 禁止上升沿下降沿任何沿
4. TCTL3
C7F C6F C5F C4F C3F C2F C1F C0F
C7I C6I C5I C4I C3I C2I C1I C0I
2. TFLG1
3. TMSK1
1. TC7 – TC0
EDG7B EDG7A EDG6B EDG6A EDG5B EDG5A EDG4B EDG4A
5. TCTL4 EDG3B EDG3A EDG2B EDG2A EDG1B EDG1A EDG0B EDG0A
B6 B5 B4 B3B7 B2 B1 B0
RST: 0 0 0 0 0 0 0 0
RST: 0 0 0 0 0 0 0 0
RST: 0 0 0 0 0 0 0 0
RST: 0 0 0 0 0 0 0 0
B6 B5 B4 B3B7 B2 B1 B0
B6 B5 B4 B3B7 B2 B1 B0
B6 B5 B4 B3B7 B2 B1 B0
$000E
$000C
$000A
$000B
Address Offset
$0010 - $0011 - -$001E - $001F
16 位捕捉 / 比较寄存器 (TC7)
16 位捕捉比较寄存器 (TC0)
--
比较 / 捕捉标志位写 ‘ 1’ 清除中断状态标志位
比较 / 捕捉屏蔽位 0 = 屏蔽中断请求 1 = 中断请求允许
0011
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 16
输入捕捉 / 输出比较选择
IOS7 IOS6 IOS5 IOS4 IOS3 IOS2 IOS1 IOS0
TIOS – 定时器输入捕捉 / 输出比较选择寄存器
IOSx = 1 输出比较功能 = 0 输入捕捉功能
RST: 0 0 0 0 0 0 0 0
$0000B6 B5 B4 B3B7 B2 B1 B0
TIMER 定时器使能1 – 计数器使能0 – 计数器禁止
TSCR – 定时器系统控制寄存器
RST: 0……………………………………………………………………………0
$0006TEN TSWAI TSFRZ TFFCA Reserved
TSWAI – 在 WAIT 模式时,定时器停止 0 = 不停止 1 = 停止
TSBCK – 在 DEBUG 模式时, 定时器停止 0 = 不停止 1 = 停止
TFFCA – 定时器快速标志位清除使能 0 = 定时器标志位正常清零 1 = 输入捕捉时读取寄存器 , 输出比较时写寄存器,可以对相应通道标志位清零
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 17
脉冲累加模式
8 – 位计数器PA7/PAI
脉冲累加器输入引脚
事件计数模式引脚作为计数器时钟软件选择以什么沿来计数计数器溢出时,产生中断(可选)在 PAI 引脚每个主动电平将产生中断
8 位计数器PA7/PAI
脉冲累加器输入引脚
时间累加模式引脚作为计数器
软件选择主动电平作为门的输入当计数器溢出时产生中断在使能的引脚上后面的边缘时产生中断
自由运行E/64 时钟
对事件计数模式, PEDGE 选择哪个 PAI 的沿用来增加 PACNT 寄存器
对门累加模式, PEDGE 选择哪个 PAI 状态用来禁止计数( 比如 . PEDGE = 1 -- 禁止计数 当 PAI = HI).
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 18
脉冲累加结构
PIN
TCx PIN Logic
DIV by 64
Control Reg.
+ 8/16 BIT CNTR
Holding Register
POLARITYCONTROL
PTx
IRQ
DATA
BUS
注 1: PTx 可以被用作脉冲累加,输入捕捉或输出比较
这里 PTx = PT0 - PT3
SELECTED CLOCK
DelayCounter
EdgeDetector
0 0 0 0 0 0 DLY1 DLY0
Bit 7 6 5 4 3 2 1 0DLYCT - Delay Counter Control Register
DLY[1:0] - Delay Counter Values 00 = Disabled 01 = 256 M Clocks 10 = 512 M Clocks 11 = 1024 M Clocks
Address Offset $0029
注 : 如果输入信号电平和跳变之前的电平相反时,延时计数器在当前时钟计数时刻产生一个脉冲,它用来去除噪声
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 19
增强型捕捉ECT 比标准的 TIM 增强的特点 • 4 个输入捕捉通道有 16 位缓冲寄存器 • 4 个 8 位 / 2 个 16 位脉冲累加器• 16 位带 4 位预分频的模数向下计数器 • 4 个用户选择的延时计数器用来消除噪声 • 主定时器预分频扩展至 7 位 • 队列和锁定模式
主定时器
输入捕捉寄存器
保持寄存器
外部事件
拷贝拷贝
拷贝
读取数据
读取数据
外部事件
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 20
模向下计数器
• 二进制向下计数器 . 可以完全控制计数起始值 • 应用于精确事件计时 - 用于产生周期性的标志位和中
断• 主定时器单独运行。时钟来自总线时钟,并经过预分
频。• 可以被设置为定时中断或产生标志位。或装载初始值
后向下计数到 $0000 。
Parameter Value UnitsCrystal Frequency 16 MHz
Bus Frequency 8 MHzBus Tick Time 125.0000 nS
Periodic Interrupt Time 191 uS
Bus Ticks Required 1528.00 Ticks
Modulus Counter Prescaler 4
Modulus Counter Start Value 382
装载向下计数
至 0
执行动作
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 21
ABS 应用举例
PT0
PT1
PT2
SENSOR 1
SENSOR 2
SENSOR 3
SENSOR 4
PB1
PB2
PB3
PB4
BRAKEFLUIDPUMP
SYSTEM
SIGNALCONDITIONINGLOGIC
IC/PA
SIGNALCONDITIONINGLOGIC
SIGNALCONDITIONINGLOGIC
SIGNALCONDITIONINGLOGIC
PT3
左前轮
右前轮
左后轮
右后轮
HCS12
TIMER
• 定时器输入捕捉测量车轮转速• 发送命令到刹车压力调节阀来调节压力
IC/PA
IC/PA
IC/PA
如果左右轮速脉冲周期不等
则
调节电磁阀
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 22
低功耗模式
TSCR – 定时器系统控制寄存器
RST: 0……………………………………………………………………………0
$0006TEN TSWAI TSFRZ TFFCA Reserved
TSWAI – 在 WAIT 模式时,定时器停止 0 = 不停止 1 = 停止
TSBCK – 在 DEBUG 模式时, 定时器停止 0 = 不停止 1 = 停止
TFFCA – 定时器快速标志位清除使能 0 = 定时器标志位正常清零 1 = 输入捕捉时读取寄存器 , 输出比较时写寄存器,可以对相应通道标志位清零
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 23
PULSE WIDTH
MODULATION
(PWM)脉宽调制模块
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 24
什么是 PWM?
period
on
T
TRatio Width Pulse
Ton Toff
Tperiod
Average
0 %
10 %
50 %
90 %
99 %
应用 : D/A 转换 马达控制 音调生成 正弦波生成
占空比 = 高电平时间 / 周期 =Ton/Tperiod
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 25
PWM 信号的产生 ( 边缘对齐 )
开始
周期 TPWM
TPWM
占空比 TDuty
PWMDTYx PWMPERx PWMPERx
fClock, TClock
8-bit Counter
PWMCNTx时钟
8-bit Compare =
PWMDTYx
8-bit Compare =
PWMPERx
0x00 0x00
Reset
Pin
当 8 位计数器的值等于 PWMDTY(duty cycle 寄存器 ) 时,电平从有效跳到无效;当 8 位计数器的值等于 PWMPER (周期寄存器)时,电平从无效跳到有效,然后计数器清 0 ,重新开始计数
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 26
PWM 模块特点
8 个带周期占空比可程控的 PWM 独立通道 4 个可程控选择的时钟源 每个 PWM 通道有专用的计数器 PWM 每个通道脉冲极性可以选择 每个 PWM 通道可使能 / 禁止 周期和占空比双缓冲 每个通道有中心对齐和边缘对齐方式 分辨率 : 8 位 (8 通道 ), 16 位 (4 通道 ) 带中断功能的紧急切断 工作模式
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 27
PWM 结构框图
通道 7
周期和占空比 计数器
通道 6
周期和占空比 计数器
...通道 0
周期和占空比 计数器
管脚
使能选择
极性选择
对齐方式选择
管脚
管脚
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 28
PWM 初始化步骤
1. 禁止 PWM Disable PWMPWME
2. 选择时钟 Select clock (prescaler and scale) for the PWM
PWMPRCLK, PWMSCLA, PWMSCLB, PWMCLK3. 选择极性 Select polarity
PWMPOL4. 选择对齐模式 Select center or left aligned mode
PWMCAE5. 对占空比和周期编程 Program duty cycle and period
PWMDTYx, PWMPERx6. 使能 PWM 通道 Enable used PWM channels
PWME
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 29
PWM 时钟选择 (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)
4 个时钟源 :
Bus ClockDivide by Prescaler Taps:
2 4 8 16 32 64 128
预分频
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
分频
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 30
PWM 时钟选择 – 预分频寄存器 (2 of 4)
0PCKB2 PCKB1 PCKB0
0PCKA2 PCKA1 PCKA0
R
W
Reset: 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
可在任意时刻读写 !x = A or B
设置 PRESCALE 寄存器 :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
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 31
PWM 时钟选择 – 分频寄存器 (3 of 4)
总线时钟fBus
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
PWMSCLx分频值
SxClock
xClockPWMSCLx
PWMSCLx
xClockSxClock
_2
_2
__
PWMSCLx = $00 PWMSCLx value is 256可在任意时刻读写 !x = A or B
/ 2Clock Sx
Clock x
Clock x = fBus / PWMPRCLK Count = 1
PWMPRCLK @ $_03
PWMSCLB @ $_09 PWMSCLA @ $_08
例如 :要求 : Clock Sx = 1 kHz总线时钟 = 16 MHz
Prescaler = 128 Prescaler = 64Clock x = 125 kHz Clock x = 250 kHzPWMSCLx = 63 PWMSCLx = 125 Clock Sx = 992 Hz Clock Sx = 1000 Hz
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 32
PWM 时钟选择寄存器 (4 of 4)
PCLK6 PCLK5 PCLK4 PCLK3 PCLK2 PCLK1 PCLK0R
W
Reset: 0 0 0 0 0 0 0 0
PWMCLK @ $_02
PCLK7
选择时钟源 :PCLK0 = 1; // SA is source of ch 0PCLK6 = 0; // B is source of ch 6PWMCLK = 0x11; // all channels
软件示例
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
PCLK5 — 通道 5 时钟选择 1 = 时钟源为 SA 0 = 时钟源为 APCLK4 — 通道 4 时钟选择 1 = 时钟源为 SA 0 = 时钟源为 A
PCLK3 — 通道 3 时钟选择 1 = 时钟源为 SB. 0 = 时钟源为 BPCLK2 — 通道 2 时钟选择 1 = 时钟源为 SB 0 = 时钟源为 B
PCLK1 — 通道 1 时钟选择1 = 时钟源为
SA0 = 时钟源为 A
PCLK0 — 通道 0 时钟选择1 = 时钟源为
SA0 = 时钟源为 A
PCLK7 — 通道 7 时钟选择 1 = 通道 7 的时钟源为SB 0 = 通道 7 的时钟源为 B.PCLK6 — 通道 6 时钟选择 1 = 时钟源为 SB. 0 = 时钟源为 B
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 33
PWMPERx
PWMDTYx
PWM 计时器通道
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
Channel xx = 0 ... 7
DoubleBuffered
DoubleBuffered
PWMDTYx
PWMPERx
占空比寄存器
周期寄存器
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 34
使能 / 禁止 PWM
PWME6 PWME5 PWME4 PWME3 PWME2 PWME1 PWME0R
WReset: 0 0 0 0 0 0 0 0
PWME @ $_00
PWME7
1 = 通道 x 使能 . 下一个时钟开始输出PWM
0 = 通道 x 禁止
通道 7 通道 6 通道 0...
使能 / 禁止 PWM 通道 :PWME5 = 1; // Enable PWM channel 5PWME3 = 0; // Disable PWM channel 3PWME = 0xFF // Enable all 8 PWM channelsPWME = 0; // Disable all 8 PWM channels
软件示例
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 35
PWM 极性选择寄存器
PPOL6 PPOL5 PPOL4 PPOL3 PPOL2 PPOL1 PPOL0R
W
Reset: 0 0 0 0 0 0 0 0
PWME @ $_00
PPOL7
1 = 在周期开始时, PWM通道输出为高电平,当计数器等于占空比寄存器的值时,输出为低电平
0 = 在周期开始时, PWM通道输出为低电平,当计数器等于占空比寄存器的值时,输出为高电平
PWMDTYx
PWMPERx
PPOLx = 1
PWMDTYx
PWMPERx
PPOLx = 0
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
通道 7 通道 6 通道 0...
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 36
对齐方式选择 - 左对齐 (1 of 3)
Clock SourceE = 100 ns
Duty Cycle= 75 %
Period= 400 ns
%100_:1
%100_:0
),,,(_
PWMPERx
PWMDTYxCycleDutyPolarity
PWMPERx
PWMDTYxPWMPERxCycleDutyPolarity
PWMPERx
SBSABAClockFrequencyPWMx
时钟源 = E = 10 MHz (100 ns period)PPOLx = 0PWMPERx = 4PWMDTYx = 1
PWMx 频率 = 10 MHz/4 = 2.5 MHzPWMx 周期 = 400 nsPWMx 占空比 = ¾*100% = 75%
Start
分辨率?
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 37
对齐方式选择 - 中央对齐 (2 of 3)
PWMDTYxE = 100ns
Period = PWMPERx*2= 800 ns
%100_:1
%100_:0
2
),,,(_
PWMPERx
PWMDTYxCycleDutyPolarity
PWMPERx
PWMDTYxPWMPERxCycleDutyPolarity
PWMPERx
SBSABAClockFrequencyPWMx
时钟源 = E = 10 MHz (100 ns period)PPOLx = 0PWMPERx = 4PWMDTYx = 1
PWMx 频率 = 10 MHz/8 = 1.25 MHzPWMx 周期 = 800 nsPWMx 占空比 = ¾*100% = 75%
Start
PWMDTYxE = 100ns
PWMPERx PWMPERx
Duty Cycle = 75%
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 38
PWM 中央对齐使能寄存器 (3 of 3)
CAE6 CAE5 CAE4 CAE3 CAE2 CAE1 CAE0R
W
Reset: 0 0 0 0 0 0 0 0
PWMCAE @ $_04
CAE7
CAEx – 中心对齐模式选择,通道 x1 = 通道 x 中心对齐输出0 = 通道 x 左边对齐输出
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
通道 7 通道 6 通道 0...
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 39
16 位分辨率
两个 8 位 PWM 通道可以组合成一个 16 位 PWM 通道
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 PWM1
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 40
16 位 PWM 组合
• 软件可选择通道组合 .
• 在组合模式下,可以左对齐或中心对齐输出
• 增加了分辨率,周期可以更长
CLOCK SOURCE 5 PWCNT 4 PWCNT 5
PERIOD/DUTY COMPARE
CLOCK SOURCE 7 PWCNT 6 PWCNT 7
PERIOD/DUTY COMPARE
CLOCK SOURCE 3 PWCNT 2 PWCNT 3
PERIOD/DUTY COMPARE
CLOCK SOURCE 1 PWCNT 0 PWCNT 1
PERIOD/DUTY COMPARE
PWM7
PWM5
PWM3
PWM1
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 41
紧急关闭
紧急关闭通道 7
Channel 6
Period and Duty Counter
Channel 5
Period and Duty Counter
...Channel 0
Period and Duty Counter
故障输入信号 PWMLVL=1 PWMLVL=0
PWM7INL=1
PWMLVL=0
InterruptPWMIE
PWMIF
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 42
PWM 关闭寄存器
PWMIE PWMRSTRT
PWMLVL0
PWM7INL PWM7ENR
W
Reset: 0 0 0 0 0 0 0 0
PWMSDN @ $_24
PWMIF0 PWM7IN
= Unimplemented or Reserved
设置关闭有效电平PWM7INL
设置关闭时的输出电平PWMLVL
使能紧急关闭PWM7ENA
Initialisation
中断使能PWMIE
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 43
工作模式
等待模式
在 WAIT 模式下,允许输入时钟到预分频器
PSWAI=
10
在 WAIT 模式下,停止输入时钟到预分频器
冻结模式
在 FREEZE 模式下, PWM 计数器继续
PFRZ=
10
在 FREEZE 模式下, PWM 计数器停止
CON45 CON010
PSWAIR
W
PWMCTL @ $_05
CON67 CON23 PFRZ0
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
使能 / 禁止时钟在 WAIT 模式时
PFRZ — PWM 计数器停止在 Freeze 模式时
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 44
PWM 控制寄存器
Reset: 0 0 0 0 0 0 0 0
Bits[1:0]= Unimplemented or Reserved
CON45 CON010
PSWAIR
W
PWMCTL @ $_05
CON67 CON23 PFRZ0
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
16 位工作模式
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 45
PWM 通道周期寄存器 - 周期计算
Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0R
W
Reset: 1 1 1 1 1 1 1 1
PWMPERx @ $_14-_1B
Bit 7
PeriodClockChannel
PeriodPWMxPWMPERx
PWMPERxPeriodClockChannelPeriodPWMx
__2
_
2___
0)(CAExOutput AlignedLeft
OutputAlignedCenter
PeriodPWMxPWMPERx
OutputAlignedCenterPWMPERxPeriodClockChannelPeriodPWMx
__2
_
_____
1)(CAExOutput AlignedCenter
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
左对齐输出
中心对齐输出
TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.
Slide 46
PWM 通道占空比寄存器 - 占空比计算
Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0R
W
Reset: 1 1 1 1 1 1 1 1
PWMDTYx @ $_1C-_23
Bit 7
%100_
1)(PPOLx 1 Polarity
%100_
0)(PPOLx 0 Polarity
PWMPERx
PWMDTYxCycleDuty
PWMPERx
PWMDTYxPWMPERxCycleDuty
Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 0
极性 = 0
极性 = 1