cancel
Showing results for 
Search instead for 
Did you mean: 

Timer interrupt confusion for prescaler & counter period values

sireevenkat1
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions
sireevenkat1
Senior

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

 

 

View solution in original post

2 REPLIES 2
gbm
Lead III

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!

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
sireevenkat1
Senior

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