2022-02-24 02:36 AM
I have this code:
//SystemCoreClock=64 MHZ
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6);
LL_TIM_SetPrescaler(TIM6, __LL_TIM_CALC_PSC(SystemCoreClock, 1000)); /* 1 tick /1 ms */
LL_TIM_EnableCounter(TIM6);
time0 = LL_TIM_GetCounter(TIM6);
LL_mDelay(3000);
time1 = LL_TIM_GetCounter(TIM6);
LL_TIM_DisableCounter(TIM6);
I can see time1 is 3000.
When i'm replacing LL_mdelay function with :
while ( LL_TIM_GetCounter(TIM6) < 3000 );
I can see again time1 is 3000,but it's not actually passed 3 seconds,it's changing time1 instantly.
When i'm adding an LL_mdelay inside the while function like this:
while ( 1) {
if (LL_TIM_GetCounter(TIM6) > 3000)
break;
LL_mDelay(1);
}
I can see that it's actually passed 3 seconds.
What's going wrong?
2022-02-24 04:03 AM
Timer prescaler is preloaded.
JW