:(试着用输入捕获模式来测量输入信号的频率。。结果算出来和实际值相差很大,请大家帮忙分析一下原因吧,谢谢啊
程序:
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
TIM_ICInitStructure.TIM_ICMode = TIM_ICMode_ICAP; //配置为输入捕获模式
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; //选择通道2
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //输入上升沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; // 通道方向选择
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //每次检测到捕获输入就触发一次捕获
TIM_ICInitStructure.TIM_ICFilter = 0x0; //
TIM_ICInit(TIM2, &TIM_ICInitStructure);
/* Select the TIM2 Input Trigger: TI2FP2 【输入触发源选择】*/
TIM_SelectInputTrigger(TIM2, TIM_TS_TI1FP1);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
最后在程序中通过TIM_GetCapture1(TIM2);读取值。。。结果误差很大。。。
请问这样做的问题出在哪? |