2014-12-10 09:41 AM
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že2014-12-10 09:52 AM
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?2014-12-10 10:08 AM
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?2014-12-10 10:15 AM
> 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? JW2014-12-10 01:49 PM
:) 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že2014-12-11 07:14 AM
Every time i changed ARR, i also reset counter to 0, so now it finally works!
Thanks guys!