AccelStepper is really slow in rpm

Hi ! I am trying to use the accelstepper.h to run my Nema 34 stepper with hbs86h driver. I am running a basic code (i tried different numbers for acceleration and speed), but I didn't managed to achieve high speeds. It's about 5 times slower than using digitalwrite made pulses...

#include <AccelStepper.h>
AccelStepper stepper(1,2,3);
void setup()
{  
   stepper.setMaxSpeed(50000);
   stepper.setSpeed(50000); 
   stepper.setAcceleration(1000);
   stepper.setMinPulseWidth(5);
}
void loop()
{  
  stepper.move(10000000);
   stepper.run();
}

What Arduino board are you using?

With a 16MHz Arduino (such as Uno or Mega) the AccelStepper documentation says the max is about 4000 steps per second.

This is because it uses floating point maths.

You will definitely get higher speeds with your own code and digitalWrite() - or better still the digitalWriteFast.h library. And it is not all that difficult to create your own acceleration code. See, for example, this Simple acceleration code.

...R

What microstepping do you use and what speeds are you wanting to achieve?

Robin2:
What Arduino board are you using?

With a 16MHz Arduino (such as Uno or Mega) the AccelStepper documentation says the max is about 4000 steps per second.

This is because it uses floating point maths.

You will definitely get higher speeds with your own code and digitalWrite() - or better still the digitalWriteFast.h library. And it is not all that difficult to create your own acceleration code. See, for example, this Simple acceleration code.

...R

Thanks a lot !!! The code in the link is working very well ! Otherwise, when I use it to calibrate my system ( the motor turns until it reaches a switch), the driver runs in safe mode... It's the same code, even with slower pulses...

#define directionPin  3
#define stepPin  2

//Step or pulse pin, check how DirectionManager is written.

#define StopPin1 4

#define StepPin2  5
#define DirPin2   6
#define StopPin2 7
unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long slowMicrosBetweenSteps = 130; // microseconds
unsigned long fastMicrosBetweenSteps = 45;
unsigned long stepIntervalMicros;
unsigned long stepAdjustmentMicros;
int numAccelSteps = 500; // 100 is a half turn of a 200 step mmotor
int numSteps = 0;
int stepsToGo;
byte direction = 1;

int totalStep;


int step1 = 0, step2 = 0; // The number of pulse that each motor will receive. If the number is negative, it inverts the direction
unsigned int pitchTarget, rollTarget; // The pitch and roll positions we want to reach
unsigned int  pitchPosition, rollPosition; // The actual positions

int c = 0;
int dir1 = 1, dir2 = 1;         //Will be used to set the motors direction
int x,y;


void setup() {
  delay(1000);    //safety delay to flash the code
  Serial.begin(115200);    //To communicate with Simtools or Monitor
  pinMode(StopPin1,INPUT_PULLUP);
  pinMode(StopPin2,INPUT_PULLUP);
    pinMode(directionPin, OUTPUT);
    pinMode(stepPin, OUTPUT);

    stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
    stepIntervalMicros = slowMicrosBetweenSteps;
    stepsToGo = numSteps;
    digitalWrite(directionPin, direction);
    calibrate();
}

void loop() {
  
moveMotor();
//delay(5);
//Serial.println(stepsToGo);
//Serial.println(totalStep);

}

void calibrate(){
totalStep = 0;
stepsToGo=0;
  delay(3000);
  Serial.println("Calibrating");
 
 //while (digitalRead(StopPin1) == LOW) {
while(!Serial.available()){
stepsToGo=1;
        moveMotor();
    totalStep = totalStep + 1;
    Serial.println(totalStep);
  }
  
 // numSteps=totalStep;
  Serial.println("finish");
  delay(2000);
stepsToGo=totalStep/2;

  delay(2000);
  
}


void moveMotor() {
       if (stepsToGo > 0) {
        if (micros() - prevStepMicros >= stepIntervalMicros) {
            prevStepMicros += stepIntervalMicros;
            singleStep();
            stepsToGo --;
            if (stepsToGo <= numAccelSteps) {
                if (stepIntervalMicros < slowMicrosBetweenSteps) {
                    stepIntervalMicros += stepAdjustmentMicros;
                }
            }
            else {
                if (stepIntervalMicros > fastMicrosBetweenSteps) {
                    stepIntervalMicros -= stepAdjustmentMicros;
                }
            }
        }
    }
    else {

        stepsToGo = numSteps;
        prevStepMicros = micros();
    }
}

void singleStep() {

    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);

}

@MarkT I use 800 microsteppings, and I try to achieve the fastest speed possible..

Lebois:
Otherwise, when I use it to calibrate my system ( the motor turns until it reaches a switch), the driver runs in safe mode... It's the same code, even with slower pulses...

I'm not sure if that means you are happy with everything or if there is still a problem.

...R

Sorry, my english is poor.
When i use the code in the link, everything is ok, the motor turns fast.
When I use it in my calibration code, the driver crashes and turn into safe mode, even with slower parameters. My calibration code works like that
Void setup{
...
Calibrate(){turn one step until i send a serial through monitor, and then steptogo = travel/2
}
Vood loop{
MoveMotot();
}
And it crashes during the loop...

It makes no sense to use acceleration code if you are moving the motor 1 step at a time.

What is the purpose of the calibrate() function?

Please post a link to the datasheet for your stepper driver - I don't know what you mean by "crash" or by "safe mode"

...R

One step at a time to check the travel length, I will use more steps after.
The calibrate function just add one step to stepToGo , and add one to totalStep, until I send a serial through the monitor (the switch is mounted on an actuator, and I remove the motor for testing, so sending a serial instead of touching a switch is handier).
When the serial is sent, the new target is totalstep/2 (half of the travel). Then we enter the main loop, where there is only moveMotor(). This is where the driver enters in "drive protection" (the red LED powers up).

The driver is an HBS86h. Link to documentation :
http://www.astrosurf.com/jd85/ESA/HBS-90-8.2.PDF

Thanks a lot for your help.

From a quick look at the datasheet that driver is intended for

HBS86 can work with the following Leadshine three phase hybrid stepper motors with encoder as follows:

Do you have one of those motors or are trying to use a regular stepper motor?

...R

The motor and the driver are provited by the same manufacturer :

As I said, driver & motor are working perfectly with the basic code, and then when I try to implement it with my calibration function, it doesn't work :confused:

I am not familiar with that type of motor.

My guess is that your calibration code is trying to move the motor too fast (without acceleration) and it is missing steps so that the actual position as determined by the feedback encoder is out of sync with the number of steps that were commanded by the Arduino.

...R

Lebois:
@MarkT I use 800 microsteppings, and I try to achieve the fastest speed possible..

Hmm, that's not standard. Or do you mean x4 microstepping, meaning the standard 200 step motor
becomes 800 microsteps per revolution?

"Fastest speed possible" isn't going to help calculate the max step rate I'm afraid. The torque/speed
graphs in the motor datasheet should provide some sort of guide for this.

Robin2:
I am not familiar with that type of motor.

My guess is that your calibration code is trying to move the motor too fast (without acceleration) and it is missing steps so that the actual position as determined by the feedback encoder is out of sync with the number of steps that were commanded by the Arduino.

...R

I change my code a little bit to be closer than yours and not it works. I replace the if by while in movemotors, so now the motor reaches the target position before anything else is done.
Otherwise I will need to spend more time to entirely understand how your code work to take full advantage of it.

MarkT:
Hmm, that's not standard. Or do you mean x4 microstepping, meaning the standard 200 step motor
becomes 800 microsteps per revolution?

"Fastest speed possible" isn't going to help calculate the max step rate I'm afraid. The torque/speed
graphs in the motor datasheet should provide some sort of guide for this.

Yes it's x4. No graph available I am afraid ... I will ask them, nobody knows... Yes it's a 200 step motor.