PDA

View Full Version : Driving two stepper motors at the same time



Bill Legge
- 20th February 2010, 01:29
I have a flatbed scanner/plotter with a stepper motor on each axis.
The motors drivers take care of high power and phase switching so that I only have to provide:

1. Direction CW or CCW.
2. Step pulse - and after all the electrical and mechanical factors, the maximum frequency I will ever need is about 1000 Hz.

I'm using a PIC18F8722 running at 40MHz and It's working OK - but only moving one motor at a time.

How do I write the code to move both motors at the same time? I need to do this to make diagonal moves.

I presume you work out the ratio of pulses - for example to move X100 and Y300 - you issue one X_Pulse followed by three Y_Pulses?

Has anyone done this or got some better ideas?

Regards Bill Legge

tenaja
- 20th February 2010, 04:12
The easiest way is with interrupts and two timers. Set up one timer to control x, and the other for y. You calculate the timer preset values based on the delay between pulses.

With an 18F you can even do it with low and high priority interrupts... you just use the low priority on the axis that will be going the slowest. If you won't know, then pick any one for low priority, or use one high priority interrupt with a test to see which timer rolled over.

Acetronics2
- 20th February 2010, 17:33
Hi,

If it is for diagonal moves only ...

same clock signal for both motor drivers and just invert or not rotation ...

if direct drive ...

just can be solved by twisting 1 st motor signals ...

only logics with bits ...

Alain