cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt on Timer Interrupt

Killstreet30
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions
LCE
Principal

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.

View solution in original post

8 REPLIES 8
LCE
Principal

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.

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

  }

}

JTP1
Lead

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

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

LCE
Principal

Is the timer doing anything?

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

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

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

JW

Killstreet30
Associate III

Yeah thank you! it works perfectly fine now.