高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-4-2
|
楼主 |
发表于 2016-7-27 21:26:44
|
显示全部楼层
这是中断的程序,大家如有时间,还望多多指教
void TIM2_IRQHandler(void)
{
static u16 this_time_CH3 = 0;
static u16 last_time_CH3 = 0;
static u8 capture_number_CH3 = 0;
vu16 tmp16_CH3;
if(TIM_GetITStatus(TIM2, TIM_IT_CC3) == SET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
if (capture_number_CH3 == 0)
{
capture_number_CH3 = 1;
last_time_CH3 = TIM_GetCapture3(TIM2);
}
else
if (capture_number_CH3 == 1)
{
capture_number_CH3 = 0;
this_time_CH3 = TIM_GetCapture3(TIM2);
if (this_time_CH3 > last_time_CH3)
{
tmp16_CH3 = (this_time_CH3 - last_time_CH3);
}
else
{
tmp16_CH3 = ((65535 - last_time_CH3) + this_time_CH3);
}
sum+=tmp16_CH3;
i++;
if(i==4)
{
F=72000000.000/(sum/4);
printf("\n\r %.4f Hz !\n\r",F);
sum=0;
i=0;
}
}
}
} |
|