使用的是TIMER2的CH1通道,PWM信号接在PA0脚。输入PWM的周期信号为100Hz,根据捕获值计算出来却是105Hz,这误差也太大了吧!!哪位高手知道是什么原因呀,指点一下呀,万分感谢呀!! 下面是我的相关部分程序: 1、时钟部分,TIMER2的时钟频率,我是初始化为36M. RCC_PCLK1Config(RCC_HCLK_Div2); //设置低速AHB时钟=系统时钟/2 RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // 倍频系数为9 PLLCLK=8*9=72 2、TIMER初始化 TIM_DeInit(TIM2); TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 18; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV4; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_PWMIConfig(TIM2, &TIM_ICInitStructure); TIM_SelectInputTrigger(TIM2, TIM_TS_TI1FP1); TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset); //复位模式为从模式 TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable); //使能主从模式 TIM_Cmd(TIM2, ENABLE); //使能TIM2计数器 TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE); //使能CC2中断请求 3、TIMER中断处理 void TIM2_IRQHandler(void) { /* Clear TIM2 Capture compare interrupt pending bit */ TIM_ClearITPendingBit(TIM2, TIM_IT_CC2); /* Get the Input Capture value */ IC2_Value = TIM_GetCapture2(TIM2); } |
回复:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
RE:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
说搞定也没搞定,只是搞清楚原因了。原来STM32的TIMER的时钟经过预分频后,TIMER的时钟误差也相应变大了不少(有点太离谱了)。不分频测量1KHz的脉冲误差0.5us.分18频后的误差就像我上面讲的了。
各位朋友用到这一块,要小心了。
RE:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
STM32F101C4T6.STM32F101C6T6.STM32F101R4T6.STM32F101R6T6.STM32F101T4U6.STM32F101T6U6.STM32F101T8U6
STM32F101C8T6.STM32F101CBT6 STM32F101R8T6 STM32F101RBT6 STM32F101V8T6 STM32F101VBT6 STM32F101RCT6
STM32F101RDT6 STM32F101RET6 STM32F101VCT6 STM32F101VDT6 STM32F101VET6 STM32F101ZCT6 STM32F101ZDT6
STM32F101ZET6
STM32F103C4T6.STM32F103C6T6.STM32F103R4T6.STM32F103R6T6.STM32F103T4U6.STM32F103T6U6.STM32F103T8U6
STM32F103C8T6.STM32F103CBT6 STM32F103R8T6 STM32F103RBT6 STM32F103V8T6 STM32F103VBT6 STM32F103RCT6
STM32F103RDT6 STM32F103RET6 STM32F103VCT6 STM32F103VDT6 STM32F103VET6 STM32F103ZCT6 STM32F103ZDT6
STM32F103ZET6
深圳市迪通科技有限公司
联系人:吴丽群
联系地址:深圳市福田区上梅林105号多丽工业区2607
电话:0755-83312947
移动电话:13480904394
传真:0755-83311568
EMAIL:WUDETONE@QQ.COM QQ:648278784
RE:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
2、TIMER初始化
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 18;
这里的18应该改为17才行哟,我觉得。
RE:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
回复:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
回复:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
LZ说要18分频,但是
2、TIMER初始化
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 18;
这里的18应该改为17才行哟,我觉得。
5楼正解。。楼主应该看看。
RE:使用STM32的TIMER捕获功能,求取输入PWM信号的周期,误差很大,请求解决!
多采集几次 取平均 得经验值来校准