Page 1 of 1

control 2 stepper motors at same time in different speed?

Posted: Sat Mar 28, 2020 2:40 pm
by Renjith
Hi all,
How control 2 stepper motors at same time in different speed?
I need as below.
Stepper-1 :- Step forward 200 Steps.
Stepper-2 :- Step forward 100 Steps.
Both Steppers are start at same time and stop at same time.
If pause during operation (example 50% of steps) steps should be stepper1 is 100 and stepper2 is 50.
When resume the operation for remaining steps (50%) both motors start at same and reach 100% at same time.

Best Regards,
Renjith.

Re: control 2 stepper motors at same time in different speed?

Posted: Tue Mar 31, 2020 2:34 pm
by Benj
Hello,

Yes this is possible and is often referred to as linear interpolation.

This is maybe overkill for what you need but performs linear interpolation on three axis with automatic speed ramping of the motors. The motors are moved using a timer interrupt. We tweak the timing of the timer to change the speed of the motors and perform the speed ramping. YOu could instead simply use a loop with a delay to perform the movement.

The linear interpolation is done by taking the max movement, in your example 200 and dividing other movements by this.

MoveA = 200
MoveB = 100

if MoveA > MoveB
MaxMove = MoveA
else
MaxMove = MoveB

StepA = MoveA / MaxMove = 1.0
StepB = MoveB / MaxMove = 0.5

On each timer interrupt step or journey round the loop we add the movement to an accumulator and if the accumulator is greater then or equal to 1 then we step that motor and subtract 1 from the accumulator.

AcumA = AcumA + StepA
AcumB = AcumB + StepB

if (AcumA >= 1.0)
{
StepA
AcumA = AcumA - 1.0
}

if (AcumB >= 1.0)
{
StepB
AcumB = AcumB - 1.0
}

In the example StepA would be called every time and StepB would be called every other time.
LinearInterpolation.fcfx
(51.1 KiB) Downloaded 183 times
The other timer in the program demonstrates auto shutdown of the motors if they are stationary for a while. I disabled this in my program as the motors need to be kept powered to maintain the position or they would have to be re-homed.

Hope this helps.

Re: control 2 stepper motors at same time in different speed?

Posted: Sat Apr 04, 2020 6:08 am
by Renjith
Dear Mr.Benj
Well noted with Thanks..
Best Regards
Renjith