Multiple motors are too slow when using AccelStepper library - suggestions?

Dear all,

I've setup a robot with 6 stepper motors using the AccelStepper library on an Arduino Mega (16Mhz clock speed). (Each stepper is driven by either an A4988 stepper driver or a DM542T stepper driver).

The library works fine, and most of the motors are set to "half step" on the driver (400 steps per revolution), and in the AccelStepper library I set each one to "4000" as the Max Speed. That equates to about 600 rpm at 400 steps per revolution.

And the speed of the motor seems to be pretty accurate when I run a single motor.

However, the moment I have multiple motors moving at the same time, all of the motors turn slower than what I had set as their max speed. The more motors that are being told to run, the more the speed of each individual motor slows down.

This seems to be because my Arduino Mega's processor needs time to compute more code, since now instead of just having a "MotorX.run()" command, I also have "MotorY.run()" and "MotorZ.run()" in my code. And therefore, the Arduino Mega sends each pulse at a slower interval than its theoretical maximum capability of 4000 pulses per second (according to the AccelStepper library).

This becomes an issue when I'm trying to make the robot perform movements at a fast speed, because unless I only command one motor at a time, it will never appear to perform at the actual "SetMaxSpeed()" value that I apply.

Any suggestions as to how to possibly overcome this? Is it as simple as picking an Arduino with a faster processor? The Arduino Due looks to have an 84Mhz clock speed, but I'm worried that there will be multiple hurdles to overcome when porting my hardware connections and trying to make the code work...so I thought I'd ask if there perhaps is some other workaround or solution others are using in this kind of situation..

Thank you!

accelstepper needs to execute the "run() function more often than each single-step-pulse occurs. This means your main-loop must run as fast as possible so the execution-time of the whole void loop()-function is smaller than the time between two step-pulses.

I would recommend using an even much faster microcontroller like the teensy 4.0 / teensy 4.1 or to use a different stepper-library combined with using this different stepper-library on a microcontroller that can create such high step-pulsefrequencies.
And Arduino Mega will not do
This library is called MobaTools.

As the first step calculate the maximum step-frequency and then look up the MobaTools documentation with which microcontroller you can achieve these frequencies

best regards Stefan

Thank you for your reply and for your explanation! Makes sense...I have a teensy 3.2 laying around so may give that a try!

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