## control 2 stepper motors at same time in different speed?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Renjith
Posts: 10
Joined: Wed Jul 23, 2014 4:13 am
Has thanked: 2 times
Been thanked: 1 time
Contact:

### control 2 stepper motors at same time in different speed?

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.

Benj
Matrix Staff
Posts: 14795
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4756 times
Been thanked: 4361 times
Contact:

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

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

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.
These users thanked the author Benj for the post (total 4):
kersing (Tue Mar 31, 2020 4:14 pm) • medelec35 (Tue Mar 31, 2020 9:10 pm) • Renjith (Sat Apr 04, 2020 6:10 am) • AbhijitR (Sat Apr 04, 2020 12:11 pm)
Rating: 20%

Renjith
Posts: 10
Joined: Wed Jul 23, 2014 4:13 am
Has thanked: 2 times
Been thanked: 1 time
Contact:

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

Dear Mr.Benj
Well noted with Thanks..
Best Regards
Renjith
These users thanked the author Renjith for the post:
Benj (Sat Apr 04, 2020 9:48 pm)
Rating: 5%