初级会员

- 积分
- 157
- 金钱
- 157
- 注册时间
- 2015-11-30
- 在线时间
- 32 小时
|
我想用stm32的输入捕获来检测输入脉冲的频率,有师兄以前写的代码,其实是和网上类似的。可是我就不太明白他到底是什么意思void TIM3_IRQHandler(){
if(TIM_GetITStatus(TIM3, TIM_IT_CC2) == SET)
{
// LCD_DisplayStringLine(Line9,"GPIOA2 TIM2_CH3 50%"); //
// Clear TIM3 Capture compare interrupt pending bit
TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);
if(CaptureNumber == 0)
{
// Get the Input Capture value
IC3ReadValue1 = TIM_GetCapture2(TIM3);
CaptureNumber = 1;
}
else if(CaptureNumber == 1)
{
// Get the Input Capture value
IC3ReadValue2 = TIM_GetCapture2(TIM3);
// Capture computation
if (IC3ReadValue2 > IC3ReadValue1) //
{
Capture = (IC3ReadValue2 - IC3ReadValue1);
}
else
{
Capture = ((60000 - IC3ReadValue1) + IC3ReadValue2); //这个又是为什么要60000来减
}
// Frequency computation
TIM3Freq = 36000000/ Capture;
CaptureNumber = 0;
counn++;
if(counn==1000) //为什么要加到1000才进行计算
{
counn=0;
sprintf(string,"Frequnecy:%dHz ",TIM3Freq);
LCD_DisplayStringLine(Line9,string);
}
}
}
}
发一个中断服务函数看下,预分频是1,自动重装载值为60000。谁能告诉我这是怎么计算的吗?原子计算代码捕获的使用的是寄存器,表示不能理解。小弟刚刚学习STM32还是有很多不懂的。希望大神不啬赐教!!!谢谢!!!
|
|