Skip to main content
PTsou.1
Associate
February 24, 2022
Question

LL_TIM counter seems not actually counting.

  • February 24, 2022
  • 1 reply
  • 994 views

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?

This topic has been closed for replies.

1 reply

waclawek.jan
Super User
February 24, 2022

Timer prescaler is preloaded.

JW