2023-03-20 11:11 PM
Hi,
So I want to have a timer interrupt of 15 seconds. So I calculated the values of pre scalar and counter accordingly:
Prescalar - 18356
Counter - 65347
I just wanted to ask if I set such values. Will it work? Cause I tried the same using an LED Toggle program but the LED didn't toggle. Also PS I'm using 3 timers and 2 External interrupts so I wonder if all collide and thats's why maybe it doesn't work?
Thanks!
Solved! Go to Solution.
2023-03-20 11:20 PM
That depends on your STM32, the timer, and the timer's clock.
Looks like your timer's clock is 80 MHz, so these values are about okay.
But make it a little easier for you, and use other values:
prescaler PSC: take something like 19999 = 20k - 1
-> clock now 4 kHz
auto reload ARR = (15 * 4000) - 1
Then you also need to enable the interrupt, and do something in the ISR.
But because waiting 15 seconds is too boring, start with a LED toggle rate you can see instantly.
2023-03-20 11:20 PM
That depends on your STM32, the timer, and the timer's clock.
Looks like your timer's clock is 80 MHz, so these values are about okay.
But make it a little easier for you, and use other values:
prescaler PSC: take something like 19999 = 20k - 1
-> clock now 4 kHz
auto reload ARR = (15 * 4000) - 1
Then you also need to enable the interrupt, and do something in the ISR.
But because waiting 15 seconds is too boring, start with a LED toggle rate you can see instantly.
2023-03-21 02:34 AM
Yeah I checked all that still doesn't seem to work even for shorter durations. I tried using another timer channel also but it doesn't work. Any help?
My code is like this
HAL_TIM_Base_Start(&htim1);
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim == &htim3) {
time_up_load = 1 ; // it enables motor to rotate clockwise
}
}
2023-03-21 03:10 AM
Use HAL_TIM_Base_Start_IT and then start correct timer ( now htim1 / htim3).
2023-03-21 03:13 AM
yeah sorry my bad it was 1 only but still doesn't work and I have enabled global interrupt too.
2023-03-21 04:05 AM
Is the timer doing anything?
Can you check some registers, be it via debugging or UART output?
2023-03-22 09:28 AM
I checked it's not performing anything it's just sitting like that. I'm clueless on how to debug further. any ideas?
2023-03-22 10:20 AM
As LCE said above, read out and check/post the TIM registers content.
JW
2023-03-22 11:45 PM
Yeah thank you! it works perfectly fine now.