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

Post Reply
Renjith
Posts: 12
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?

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

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

Post 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.

Renjith
Posts: 12
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?

Post by Renjith »

Dear Mr.Benj
Well noted with Thanks..
Best Regards
Renjith

Post Reply