您好,欢迎访问三七文档
FreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.TMFreescaleHCS12微控制器微控制器微控制器微控制器MC9S12DP2562005年年年年8月月月月FreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.TMEnhancedCaptureTimerModule增强型捕捉定时器模块增强型捕捉定时器模块增强型捕捉定时器模块增强型捕捉定时器模块TMFreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.Slide2ECT模块结构模块结构模块结构模块结构•一个16位向上带可编程预分频的主计数器.•一个16位的带可编程预分频的模数向下计数器•8个独立的定时器通道,每个通道具备输入捕捉和输出比较功能•4个8位脉冲累加器,也可设置成2个16位脉冲累加器.•通过对寄存器编程可以实现不同的功能TMFreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.Slide3定时器结构定时器结构定时器结构定时器结构预分频选择PR[2:0]MClock1248163264128TCNT15...........................................0DATABUSPINRRRR1–计数器使能0–计数器禁止TENTSWAITSFRZTFFCATSCR1-定时器控制寄存器定时器控制寄存器定时器控制寄存器定时器控制寄存器RST:00000000TCNTCLK.TENB0.......……...B7B8……..........B15R=Reserved$0006AddressOffset$0004,05$FFFE$FFFF$0000*******************TOF模块时钟模块时钟模块时钟模块时钟计数器寄存器计数器寄存器计数器寄存器计数器寄存器脉冲累加器脉冲累加器脉冲累加器脉冲累加器计时器溢出时,对溢出标志位置位,如允许中断,则向CPU发出中断请求TMFreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.Slide4定时器定时器定时器定时器,,,,预分频预分频预分频预分频,,,,计数器计数器计数器计数器寄存器:1.TCNT16位自由运行/模计数器B15............................................................................................................................…B0RST:0........................................................................................................................0AddressOffset$0004,$00051–定时器溢出中断使能0–定时器中断禁止$000D3.TSCR2RST:000000001–定时器由OC7比较符合时复位0–定时器自由运行TCRE-允许使用PWM功能B7....................................................................................B0TOI000TCREPR2PR1PR02.TFLG2定时器溢出标志位,写‘1’清零TOF0000000B7......................................................................B0RST:00000000$000F标志寄存器标志寄存器标志寄存器标志寄存器除以1248163264128000011110101010100110011PR2PR1PR0预分频系数选择预分频系数选择预分频系数选择预分频系数选择TMFreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.Slide5定时器编程步骤定时器编程步骤定时器编程步骤定时器编程步骤用途:产生周期中断•初始化1.设定预分频系数2.定时器溢出中断使能3.定时器使能•中断函数1.清标志位2.用户自己的代码voidECT_Init(void){TSCR2_PR=7;//prescalefactoris8,busclock/128=8Mhz/8TSCR2_TOI=1;//timeroverflowinterruptenableTSCR1_TEN=1;//timerenable}#pragmaCODE_SEGNON_BANKED#pragmaTRAP_PROCvoidInt_TimerOverFlow(void){TFLG2_TOF=1;//cleartimeroverflowflag//用户自己的代码…………….}#pragmaCODE_SEGDEFAULT在PRM文件中,加入VECTORADDRESS0xFFDEInt_TimerOverFlowTMFreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.Slide6输出比较功能输出比较功能输出比较功能输出比较功能16位自由运行计数器16位输出比较寄存器比如:0x5678软件可以修改引脚控制逻辑中断请求OCxF状态标志位置位,当比较发生时(值相等时)OCxI中断屏蔽(通过软件使能)•共有8个输出比较通道•每个通道有自己的向量表和控制寄存器•在特定的时刻输出一个信号在特定的时刻输出一个信号在特定的时刻输出一个信号在特定的时刻输出一个信号当比较寄存器的值和计数器的值相等时,采取行动比如:当TCNT=0x5678TCNTTOCxPinOCx比较比较比较比较比较器相等相等相等相等置位置位置位置位OROR清零清零清零清零翻转翻转翻转翻转TMFreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.Slide7输出比较寄存器输出比较寄存器输出比较寄存器输出比较寄存器C7FC6FC5FC4FC3FC2FC1FC0FOM7OL7OM6OL6OM5OL5OM4OL41.TC7–TC02.TFLG13.TIE4.TCTL1比较/捕捉标志位写‘1’清除中断状态标志位比较/捕捉屏蔽位0=屏蔽中断请求1=中断请求允许OMXOLXActiononOCx00110101NoActionOCxToggleOCxDriveOCxLODriveOCxHI输出模式和输出电平(O7–OC0)B6B5B4B3B7B2B1B05.TCTL2B6B5B4B3B7B2B1B0RST:00000000$0008RST:00000000RST:00000000RST:00000000$000C$000E$0009AddressOffset$0010-$0011--$001E-$001F16位捕捉/比较寄存器(TC7)16位捕捉/比较寄存器(TC0)--C7FC6FC5FC4FC3FC2FC1FC0FB6B5B4B3B7B2B1B0OM3OL3OM2OL2OM1OL1OM0OL0B6B5B4B3B7B2B1B0FOC7FOC6FOC5FOC4FOC3FOC2FOC1FOC06.CFORCB7B6B5B4B3B2B1B0RST:00000000$0001TMFreescaleSemiconductorConfidentialandProprietaryInformation.Freescale™andtheFreescalelogoaretrademarksofFreescaleSemiconductor,Inc.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners.©FreescaleSemiconductor,Inc.2005.Slide8输出比较输出比较输出比较输出比较,OC7-OC0中断:•清除中断,对TFLG1其中的OCxF写’1’•不要使用位操作•使用OC7-OC0向量表复位条件:•自由运行计数器(TCNT)被初始化为$0000,并且被禁止•输出比较寄存器被初始化为$0000•捕捉/比较引脚与比较功能断开•中断被禁止•标志位被清零•强制比较位被清零•TMFreescaleSemiconduc
本文标题:飞思卡尔定时器模块
链接地址:https://www.777doc.com/doc-5951102 .html