Skip to main content
Killstreet30
Associate III
March 21, 2023
Solved

Doubt on Timer Interrupt

  • March 21, 2023
  • 8 replies
  • 2282 views

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!

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

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.

8 replies

LCE
LCEBest answer
Principal II
March 21, 2023

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.

Killstreet30
Associate III
March 21, 2023

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

  }

}

Graduate II
March 21, 2023

Use HAL_TIM_Base_Start_IT and then start correct timer ( now htim1 / htim3).

Killstreet30
Associate III
March 21, 2023

yeah sorry my bad it was 1 only but still doesn't work and I have enabled global interrupt too.

LCE
Principal II
March 21, 2023

Is the timer doing anything?

Can you check some registers, be it via debugging or UART output?

Killstreet30
Associate III
March 22, 2023

I checked it's not performing anything it's just sitting like that. I'm clueless on how to debug further. any ideas?

waclawek.jan
Super User
March 22, 2023

As LCE said above, read out and check/post the TIM registers content.

JW

Killstreet30
Associate III
March 23, 2023

Yeah thank you! it works perfectly fine now.