![](http://kessokuryo.top/wp-content/uploads/2024/03/1711284386-屏幕截图-2024-03-24-204446.png)
选择TIMx_CH1
![](http://kessokuryo.top/wp-content/uploads/2024/03/1711284386-屏幕截图-2024-03-24-204502-1024x432.png)
![](http://kessokuryo.top/wp-content/uploads/2024/03/1711284387-屏幕截图-2024-03-24-204515.png)
定时器配置
uint16_t count, frq;
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)//记不住可以在stm32g4xx_hal_tim.h中最后找到
{
if(htim->Instance == TIM2)
{
count = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);//获取计数
__HAL_TIM_SetCounter(htim,0);//清零计数
frq = (80000000/80)/count;//计算频率
HAL_TIM_IC_Start(htim, TIM_CHANNEL_1);//重新打开定时器
}
}
HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_1);//在main中调用,开启定时器
Comments NOTHING