Skip to main content
anze2
Associate
December 10, 2014
Question

STM32F4 Discovery change timer ARR on the fly

  • December 10, 2014
  • 5 replies
  • 2320 views
Posted on December 10, 2014 at 18:41

Hello everyone!

I am experiencing problem with my discovery board. 

I am trying to accelerate my stepper motor, so when i push the button, i decrease value in TIM2 ARR with this command:

uSeconds-=20;

TIM_SetAutoreload(TIM2, uSeconds);

TIM2 is configured so that every 1 unit in arr means 1uS.

So when i push the button, i decrease value in ARR and stepper motor speeds up. 

This actualy works, but when i push multiple times, the motor stops (so timere stops giving impulses). 

Where is the problem? 

The same thing hapens, when i try to accelerate the motor with other timer, so every 1ms tim4 changes ARR value of tim2. For some time it actually accelerates, but then it stops....And at random time...

I am very confused about this and i would really appreciate your help!

Thanks in advance!

Anže
    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    December 10, 2014
    Posted on December 10, 2014 at 18:52

    Do you implement any limits (high/low) so you don't exceed the specifications of the motor, or the counter?

    Do you debounce the button press, or display any of the numbers being written to the register?

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    anze2
    anze2Author
    Associate
    December 10, 2014
    Posted on December 10, 2014 at 19:08

    Whoa, that was fast answer, thank you! :)

    Limits on the counter? Counter is 32 bit, i have values between 200 and 2000 so 200uS and 2000uS...

    When i manually set the arr to 200, motor rotates very fast, but it is stable, same thing when i manually set it to 2000 it rotates stable but slow, so it's not the motor limitation i guess.

    Button press doesn't need to be debounced, because i use bluetooth USART interrupt from android application (button 'U' means up and 'D' menas down)  instead of physical buttons.

    I am working on this problem for 1 week and i still didn't figure this out. Any other ideas? 

    waclawek.jan
    Super User
    December 10, 2014
    Posted on December 10, 2014 at 19:15

    > Counter is 32 bit,

    OK so you have say ARR = 100 and counter CNT counting up, and when CNT = 90 you set ARR to 50. When do you think the next update/reload happens?

    JW

    anze2
    anze2Author
    Associate
    December 10, 2014
    Posted on December 10, 2014 at 22:49

    :) at approx. 4 billion micro seconds :):)

    Ok, so every time i change arr, i must also set counter to 0. Sounds logical, i feel stupid i didn't remember this before. I'll let you know how this works, tomorrow will give it a try.

    Thanks!

    Anže
    anze2
    anze2Author
    Associate
    December 11, 2014
    Posted on December 11, 2014 at 16:14

    Every time i changed ARR, i also reset counter to 0, so now it finally works!

    Thanks guys!