Skip to main content
Explorer II
December 11, 2023
Solved

Timer interrupt confusion for prescaler & counter period values

  • December 11, 2023
  • 2 replies
  • 1353 views

Hi,

I am working with STM32G4. I am using Timer1 for the hardware interrupt delay.

TImer1 works with APB2 clock -My APB2 clock is 48 MHz.

1.I need to generate timer with 50 usec delay.
What will be the prescaler and counter period.Can anyone suggest. 

2.For testing I tested for 500 msec delay with
prescaler=12000-1
Counter period =2000=1

With above settings led should toggle for(500 msec on time/500 msec off time)
but led is toggling with 5 sec delay(2.5 sec on/2.5 sec off).
What am I doing wrong? can any one suggest.

 

 

 

HAL_TIM_Base_Start_IT(&htim1);

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

if (htim == &htim1)

 {

 HAL_GPIO_TogglePin(GPIOA, user_led);

}

}

 

 

sireevenkat1_0-1702277289497.png

sireevenkat1_1-1702277894424.png

sireevenkat1_2-1702277930548.png

 

Thanks

    This topic has been closed for replies.
    Best answer by sireevenkat1

    Hi @gbm ,I disabled the auto-reload preload in timer1 configuration. Now its working fine.

    My Input frequency to HSE is 24 MHz.
    Timer uses APBx TIMER CLOCK  ---- I am taking APB2 timer clock frequency for timer calculation i.e 48 MHz

     

     

    2 replies

    Graduate
    December 11, 2023

    Timer uses APBx TIMER CLOCK, which is not the same as APBx clock. In your example APB2 timer clock seems to be 48 MHz (so basically ok), provided that you set the HSE oscillator frequency correctly - check it against the physical configuration of your board!

    sireevenkat1AuthorAnswer
    Explorer II
    December 11, 2023

    Hi @gbm ,I disabled the auto-reload preload in timer1 configuration. Now its working fine.

    My Input frequency to HSE is 24 MHz.
    Timer uses APBx TIMER CLOCK  ---- I am taking APB2 timer clock frequency for timer calculation i.e 48 MHz