Is it Possible to change the timer count direction dynamically without having to wait for it to over- or underflow?
Hello dear ST-Community,
here is a brief explaination of my problem:
I'm using multiple stepper-motors in my system.
I want to use 3 timers per stepper.
- Timer generates the PWM signal for the stepper-driver (easy to achive)
- Timer captures the signal of the 1. Timer. It has a low arr and increases the stepper-speed (aka decreases 1. Timer arr and ccr) after every overflow to achive ramps when accelerating/decelerating. (also no Problem)
- Timer also captures the signal of the 1. Timer and is supposed to keep track of the position of the stepper. This mens the CNT value of the 3. Timer always corresponds to the Position of the motor.
My Problem is, that I need to change the conting direction of the 3. Timer according to the rotational direction of the motor. I change direction of the motor in software, so all I thougt I needed to do was to change the count-direction of the 3. Timer simultaniously.
Is this possible? I coundn't find a __HAL-Macro for chainging the timers counting direction at runtime. I know it corresponds to the timers CR1 register, but woudn't it wait for the timer to over- or underflow until the change takes effect? Sadly I can't confirm it with hardware atm because I'm still waiting for my drivers.
My last resort would be to store the timers value befor chainging direction and resetting it with a new arr. So if I'm changing from a up-couting mode to down-counting, I'd have to store the CNT, reset the timer, change direction and use the stored CNT as new ARR. Then the down-counting would start from that ARR.
The whole reason for using 3 timers for one motor is to minimize cpu time, so I'd like to just change a register when I change direction and nothing more.
I'd love to here from an experienced timer-user if this approch is an good or if there is something more elegant.
Thanks in andvance!
Greetings from Germany
johofz