void TIM5_IRQHandler(void)
{
if (TIM_GetITStatus(TIM5, TIM_IT_CC4) != RESET)
{
if(CaptureNumber == 0)
{
/* Get the Input Capture value */
IC1ReadValue1 = TIM_GetCapture4(TIM5);
}
else if(CaptureNumber == 1)
{
/* Get the Input Capture value */
IC1ReadValue2 = TIM_GetCapture4(TIM5);
/* Capture computation */
if (IC1ReadValue2 > IC1ReadValue1)
{
Capture = (IC1ReadValue2 - IC1ReadValue1);
}
else
{
Capture = ((0xFFFF - IC1ReadValue1) + IC1ReadValue2);
}
/* Frequency computation */
LsiFreq = (uint32_t) SystemCoreClock / Capture;
LsiFreq *= 8;
}
CaptureNumber++;
/* Clear TIM5 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM5, TIM_IT_CC4);
}
}
ST官方的例程,用于检测内部LSI时钟频率,为什么计算出来的频率要乘以8
LsiFreq *= 8; |