论坛元老
 
- 积分
- 4894
- 金钱
- 4894
- 注册时间
- 2015-1-10
- 在线时间
- 612 小时
|
发表于 2021-8-3 09:45:28
|
显示全部楼层
给你个参考:void TIM11_IRQHandler(void)
{
static uint16_t capStart = 0, overflowCnt = 0;
uint16_t freq = 0;
if (TIM_GetITStatus(TIM11, TIM_IT_Update) == SET) {
TIM_ClearITPendingBit(TIM11, TIM_IT_Update);
if (overflowCnt & 0x8000)
overflowCnt++;
}
if (TIM_GetITStatus(TIM11, TIM_IT_CC1) == SET) {
/* Clear TIM11 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM11, TIM_IT_CC1);
if (!(overflowCnt & 0x8000)) {
/* Get the Input Capture value */
capStart = TIM_GetCapture1(TIM11);
overflowCnt = 0x8000; //set capture start count flag
} else {
freq = 1000000/(1000*(overflowCnt[0] & 0x7FFF) + TIM_GetCapture1(TIM11) - capStart);
capStart = TIM_GetCapture1(TIM11);
overflowCnt = 0x8000;
}
}
}
}
|
|