Control stepper motor, exact number of steps

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
huibooh
Posts: 2
Joined: Fri Sep 30, 2016 8:15 pm

Control stepper motor, exact number of steps

Post by huibooh » Fri Sep 30, 2016 8:31 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Control stepper motor, exact number of steps

Post by dhylands » Sat Oct 01, 2016 4:38 am

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.

huibooh
Posts: 2
Joined: Fri Sep 30, 2016 8:15 pm

Re: Control stepper motor, exact number of steps

Post by huibooh » Thu Oct 13, 2016 6:43 pm

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.

Post Reply