Control 3 stepper motors simultaneously?

I'm using an arduino mega to control 2 stepper motors using a CL57T from stepperonline currently at the same time using this code:

  digitalWrite(STEP_PIN_L, LOW);
  digitalWrite(STEP_PIN_L, HIGH);
  digitalWrite(STEP_PIN_R, LOW);
  digitalWrite(STEP_PIN_R, HIGH);
delayMicroseconds(10);

I originally tried moving them using the accelstepper library but they moved far slower than simply stepping myself.

I would to add another axis of movement by adding another stepper motor that is controlled by a tmc5160. Is it possible to move all 3 of these motors at the same time? The new motor would be moving a slower rate than the other 2 motors and would stop earlier also.

sterisk:
currently at the same time using this code:

I can see how the code will work but it is very primitive and not a good basis for a more complex program.

How many steps per second do you need from each of your motors and how many steps are there in a single move.

If you want two motors to move exactly in step with each other then just connect the step pins from the two drivers to the same Arduino pin.

And please post the complete program.

...R
Stepper Motor Basics
Simple Stepper Code

I'm not sure how to calculate my steps per second, as mainly I see the difference in speed due to observation.

Here's my code:

bool move(long millimeters)
{
  if (millimeters < 0)
  {
    digitalWrite(DIR_PIN_L, LOW);
    digitalWrite(DIR_PIN_R, LOW);
  }
  else
  {
    digitalWrite(DIR_PIN_L, HIGH);
    digitalWrite(DIR_PIN_R, HIGH);
  }
  long stepsNeeded = abs(millimeters) * STEPS_PER_MM * GEAR_RATIO;
  for (long i = stepsNeeded; i > 0; i--)
  {
    //check for alarms
    if (digitalRead(ALARM_L) == LOW && digitalRead(ALARM_R) == LOW)
    {
      return false;
    }
    else if (digitalRead(ALARM_L) == LOW)
    {
      digitalWrite(RELAY_L, HIGH);
      delay(2000);
      digitalWrite(RELAY_L, LOW);
      delay(5000);
      return false;
    }
    else if (digitalRead(ALARM_R) == LOW)
    {
      digitalWrite(RELAY_R, HIGH);
      delay(2000);
      digitalWrite(RELAY_R, LOW);
      delay(5000);
      return false;
    }
    else if (digitalRead(LIMIT_L) == HIGH && digitalRead(LIMIT_R) == HIGH && !digitalRead(DIR_PIN_R))
    {
      return true;
    }
    else
    {
       digitalWrite(STEP_PIN_L, LOW);
       digitalWrite(STEP_PIN_L, HIGH);
       digitalWrite(STEP_PIN_R, LOW);
       digitalWrite(STEP_PIN_R, HIGH);
     }
     delayMicroseconds(23);
  }
  return true;
}

sterisk:
I'm not sure how to calculate my steps per second, as mainly I see the difference in speed due to observation.

Don't you know how fast you want the motors to rotate?

Here's my code:

That's still not a complete program.

...R

I have a general idea based on timing it, but the rest of my code would be too large and across a too many files to post on here. This is the code that's relevant to my question though.

sterisk:
I have a general idea based on timing it, but the rest of my code would be too large and across a too many files to post on here. This is the code that's relevant to my question though.

I am certainly too lazy to study a long program. Perhaps you can incorporate the code in Reply #2 into a short complete program just for learning purposes. Long programs are not good for learning.

...R

What step rates are you needing?

MarkT:
What step rates are you needing?

Already asked and answered - OP does not seem to know.

...R

MarkT:
What step rates are you needing?

So right now I'm using a Nema 23 and I have 10 microseconds between pulses based on my original code, with a cl57t as my motor driver. Is there a way to calculate my step rate with these variables?

EDIT: So I'm running my motor driver at 800pulses/rev, and my nema 23 is 200steps/rev. And so I have 10 microseconds between steps.

I fixed my problem. Once you guys made me calculate my steps/second, I was able to write that value into accelstepper.

My motor driver is set to 800steps/rev, so when multiplied with 1000rpm, and divided by 60, I get 13,333.33 steps/sec.

MarkT:
What step rates are you needing?

Do you know about an upper limit for using multistepper? I recalculated my desired steps/sec to be ~40000 to match the 3000rpm I get from my original code, but it doesn't seem any faster than the 13333 from my earlier post.

The AccelStepper documentation says "Speeds of more than 1000 steps per second are unreliable"

The problem is that the library uses floating point maths which is slow on a 16Mhz Arduino

If you need higher step rates then you will have to write your own code. Have a look at the second example in my Simple Stepper Code as a starting point.

Using the digitalWriteFast library will allow considerably faster code and it is as easy to use as the standard digitalWrite() and digitalRead(). I have used a Hardware Timer and the digitalWriteFast library to get step rates of about 25,000 per sec from a Mega. The very carefully optimised GRBL program can go a bit faster - up to 35,000 IIRC.

...R

Your example looks like you're only running a single motor, but with my code I'm trying to run 3 stepper motors simultaneously. So would that be a major bottleneck for writing my own code?

sterisk:
Your example looks like you're only running a single motor, but with my code I'm trying to run 3 stepper motors simultaneously. So would that be a major bottleneck for writing my own code?

Running 3 motors should add relatively little to the code. My own personal project can drive 4 motors for a small CNC machine.

You have not told us what project you are trying to create or how the movements of the motors relate to each other or anything that would help us better to understand your problem. Give us the big picture.

...R

My motor driver is set to 800steps/rev, so when multiplied with 1000rpm, and divided by 60, I get 13,333.33 steps/sec.

I see your driver doesn't let you go below 800 steps/rev. To get your higher terminal RPM, you would possibly look at different drivers, like TB6600 with a min 200 steps/rpm => 3,333 steps/sec.

srhnz:
I see your driver doesn't let you go below 800 steps/rev.

The OP has not said that.

I presume he has chosen x4 microstepping for a reason. I would be very surprised if the driver he is using does not allow for single stepping.

...R

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.