本帖最后由 iplayboy 于 2012-7-25 18:14 编辑
求解答:
void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);//清除中断位
if(CaptureNumber == 0)
{
IC3ReadValue1 = TIM_GetCapture2(TIM2); //捕获输入脉冲
CaptureNumber = 1;
}
else if(CaptureNumber == 1)
{
IC3ReadValue2 = TIM_GetCapture2(TIM2);
if (IC3ReadValue2 > IC3ReadValue1)
{
Capture = (IC3ReadValue2 - IC3ReadValue1);
}
else
{
Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2);
}
//频率计算
//Capture = (IC3ReadValue2 - IC3ReadValue1)*100/ Capture;
TTIM2Freq = (uint32_t) SystemCoreClock / Capture;
CaptureNumber = 0;
}
}
}
为什么TIM_GetCapture2(TIM2)捕获的时间一直是0呢? IC3ReadValue2和 IC3ReadValue1一直是0,不知道为什么? |