1.现象:
CNT乱跳
2.原因:
在江协科技视频给定的代码和网上的代码中,滤波器给定0x00关闭状态
//通过ETR外部引脚的时钟模式2
TIM_ETRClockMode1Config(TIM2,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted,0x00);
3.处理方法:
更改成0x0f:
//通过ETR外部引脚的时钟模式2
TIM_ETRClockMode1Config(TIM2,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted,0x0f);
4.相关代码内容:
// 选择ETR外部时钟模式1输入的时钟,TIM_ExtTRGPrescaler为ETR外部时钟预分频器,
//TIM_ExtTRGPolarity为输入极性选择,ExtTRGFilter为滤波配置
void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,uint16_t ExtTRGFilter);