1.CUBEMAX配置
2.代码部分
HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_1);
HAL_TIM_IC_Start_IT(&htim16,TIM_CHANNEL_1);//开启输入捕获功能
uint32_t fre1,capture_value1,fre2,capture_value2;
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance==TIM16)
{
capture_value1=HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);
TIM16->CNT=0;
fre1=80000000/(80*capture_value1);
}
if(htim->Instance==TIM2)
{
capture_value2=HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);
TIM2->CNT=0;
fre2=80000000/(80*capture_value2);
}
}