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; |
请提完整工程,只凭你给出的信息,无法判断。
dispersion) */
/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG counter clock: LSI/32 */
IWDG_SetPrescaler(IWDG_Prescaler_32);
/* Set counter reload value to obtain 250ms IWDG TimeOut.
Counter Reload Value = 250ms/IWDG counter clock period
= 250ms / (LSI/32)
= 0.25s / (LsiFreq/32)
= LsiFreq/(32 * 4)
= LsiFreq/128
*/
IWDG_SetReload(LsiFreq/128);
/* Reload IWDG counter */
IWDG_ReloadCounter();
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable();
定时器5检测到的频率应该就是内部时钟频率,可是为什么算出来后,还需要乘以8
请提供完整工程,只凭你给出的信息,无法判断。
这还不完整?库例程也就是这样的,直接就是3.5版的库的
当然不完整。
有工程吗?你说过是STM32F1的库吗?说过路径是“STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\IWDG”吗?
main.c中第200行的8分频,看到了吗?
SystemCoreClock为72M,TIM5也是72MHz。