(ThisexampleshowshowtosetuptheTIM,anduseittomeasurethefrequencyanddutycycleofanexternalinputsignal.TIM2clocksetto72MHzandtheprescalerissetto0,TIM2iscounterclockcanbeexpressedas:TIM2iscounterclock=TIMxCLK/(prescaler.Ppls1)=72MHz,theminimummeasurablefrequencyvalueof1100Hz.SetTIM2PWMinputmode(PWMInputMode),theexternalsignalasaninputconnectedtothetheTIM2Channel2.TIM2counterinterruptsignaltomeasurefrequencyanddutycycle.CalculatethefrequencyanddutycycleofthesignalinTIM2_IRQHandlerasfollows:variable"Frequency"onthegroundsoftheexternalsignalfrequencybythefollowingformula:Frequency=TIM2iscounterclock/TIM2_CCR2unitHzvariableDuty_Cycle"onthegroundsofthefollowingformulatogetexternaldutycycle:Duty_Cycle=(TIM2_CCR1*100)/(TIM2_CCR2)in) - IMDN开发者社群-imdn.cn">
登录
首页 » C/C++ » example6_TIM

example6_TIM

于 2012-05-18 发布 文件大小:247KB
0 73
下载积分: 1 下载次数: 9

代码说明:

  本例展示了如何设置TIM,用它来测量一个外部输入信号的频率和占空比。 TIM2时钟设置为72MHz,预分频设置为0,TIM2计数器时钟可表达为: TIM2 counter clock = TIMxCLK / (Prescaler +1) = 72 MHz,因此可测量的最小频率值为1100Hz。 设置TIM2工作在PWM输入模式(PWM Input Mode),把外部信号作为输入连接到TIM2通道2。 利用TIM2计数器中断来测量信号的频率和占空比。在TIM2_IRQHandler中,计算信号的频率和占空比,方法如下: 变量"Frequency"为由下式得到的外部信号频率: Frequency = TIM2 counter clock / TIM2_CCR2 单位Hz 变量"Duty_Cycle"为由下式得到的外部信号占空比: Duty_Cycle = (TIM2_CCR1*100)/(TIM2_CCR2) 单位 (This example shows how to set up the TIM, and use it to measure the frequency and duty cycle of an external input signal. TIM2 clock set to 72MHz and the prescaler is set to 0, TIM2 is counter clock can be expressed as: TIM2 is counter clock = TIMxCLK/(prescaler. Ppls1) = 72 MHz, the minimum measurable frequency value of 1100 Hz. Set TIM2 PWM input mode (PWM Input Mode), the external signal as an input connected to the the TIM2 Channel 2. TIM2 counter interrupt signal to measure frequency and duty cycle. Calculate the frequency and duty cycle of the signal in TIM2_IRQHandler as follows: variable " Frequency" on the grounds of the external signal frequency by the following formula: Frequency = TIM2 is counter clock/TIM2_CCR2 unit Hz variable Duty_Cycle " on the grounds of the following formula to get external duty cycle: Duty_Cycle = (TIM2_CCR1* 100)/(TIM2_CCR2) in )

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 696522资源总数
  • 104040会员总数
  • 35今日下载