Skip to main content
Raül G
Associate II
April 11, 2018
Question

Change the interrupt frequency

  • April 11, 2018
  • 2 replies
  • 847 views
Posted on April 11, 2018 at 18:08

Hello,

I'm just starting to create a basic code in order to play with the timer interrupt.

Now I have a little problem: my led blinks but I want to change the frequency when I push the button. Why this code inside the main function don't change the frequency?

while

 {

if (!HAL_GPIO_ReadPin(BotoBlau_GPIO_Port, BotoBlau_Pin))      htim14.Init.Period = 10000;

else  htim14.Init.Period = 2000;

 

}

Thanks!

Raul

    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    April 11, 2018
    Posted on April 11, 2018 at 18:14

    Because that's just a variable, and it does not get magiaclly applied to the real physical register of the timer, only when the initialization function is called.

    JW

    Tesla DeLorean
    Guru
    April 11, 2018
    Posted on April 11, 2018 at 21:00

    if (!HAL_GPIO_ReadPin(BotoBlau_GPIO_Port, BotoBlau_Pin))      TIM14->ARR = 10000-1;

    else  TIM14->ARR = 2000-1;

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..