Hello,
this is my very first contact with MicroPython and I could need some directions ...
I want a stepper motor to make 5 steps. To avoid jerk, I want to decrease the delay between the steps, to "ramp" the stepper slowly up and down. So I have a list of delays between pulses, for example [2, 1, 1, 2].
How would I implement this? My first idea was to use a timer, which is reconfigured in each interrupt. Basically the callback "eats" the next element in the list and uses timer.freq() to reconfigure.
For only one stepper I could think about a main loop which uses delay() etc, but as soon as I want to control several motors (not just one) independently I think I should use the interrupt mechanisms.
(The context of this question is a CNC mill)
Can someone give me some hints and help me to get the right way of thinking?
Best,
Philipp
Control stepper motor, exact number of steps
Re: Control stepper motor, exact number of steps
I would probably run a 32-bit timer at say 25 kHz. Then I'd figure out on which of these pulses you'd like a step to occur.
I'd set the timer to run from 0 to 0x3fffffff.
Then setup the timer using output compare to toggle the output and create an interrupt.
In the interrupt you'd make the timer output go low and setup the timer for the next time you want an interrupt.
I'd set the timer to run from 0 to 0x3fffffff.
Then setup the timer using output compare to toggle the output and create an interrupt.
In the interrupt you'd make the timer output go low and setup the timer for the next time you want an interrupt.
Re: Control stepper motor, exact number of steps
Thank you for your answer, Dave!
Another very important hint that I found was the Bresenham algorithm. In combination with your answer I have a basic idea how this may be implemented.
Another very important hint that I found was the Bresenham algorithm. In combination with your answer I have a basic idea how this may be implemented.