2023-12-10 10:59 PM
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);
}
}
Thanks
Solved! Go to Solution.
2023-12-11 12:43 AM
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
2023-12-10 11:41 PM
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!
2023-12-11 12:43 AM
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