我的初始化函数与中断函数如下:
void TIM4_Config(void)
{
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_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM4, &TIM_ICInitStructure);
/* Select the TIM4 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM4, TIM_TS_TI1FP1);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM4, TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM4, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);
}
void TIM4_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1);
IC2Value = TIM_GetCapture1(TIM4);
if (IC2Value != 0)
{
Frequency = 72000000 / IC2Value;
}
else
{
Frequency = 0;
}
}
我将PB8直接连上PB6,用定时器发出1000HZ的方波,用示波器检测也已经是1khz。然后TIM4的捕获器捕出来的值经计算后却不是1k,请大家帮我检查一下,是不是我上面的初始化函数有问题?我使用官方提供的例子,也是不正确。谢谢大家。初学者,希望大家帮忙。 |