Need help with AccelStepper

Hey Folks !

I need to do the following:

  • Button A is pressed. Motor accelerate FWD to full speed. Button is released, motor decelerate.
  • Button B is pressed. Motor accelerate REV to full speed. Button is released, motor decelerate.

Yes, I know, I could have used a DC motor, but we bought that big NEMA34 Stepper motor, the driver that matches and a power supply. I'm stuck with the choice that was made. I would like to go up to 500 RPM.

According to the specs, (5 amp, 11 mH, fed at 48 Vdc) the the speed is 2.2 Rev / sec. (roughly 130 RPM)

In my first sketch, I use the "Stepper.run()" method, therefore my stepper follow an acceleration curve. The fastest speed I could achieve is 350 RPM, which is way better than the theoretical max speed.

My problem is that at some speeds, the motor make some weird noise, something like if a pulse or 2 went missing.. It does maintain a fairly stable speed. It also follows a nice accel/decel ramp.

My second sketch, uses the "RunSpeed()" method. When I want to start it, since it does not follow any acceleration curve, I must lower the speed below 50%, otherwise it won't start turning: I'm guessing the pulse train is so fast that it can't "beat" the inertia. Once started, I can increase the speed up to 600 RPM !

It does run smooth at any speed.......

Is the a way to combine both behaviour: being able to run up to 5-600 RPM, run smooth following an Accel/Decel curve ?

StepperMotor_RunSpeed_Method.ino (732 Bytes)

StepperMotor_Run_Method.ino (767 Bytes)

Maybe just control the motor without the AccelStepper library - assuming your stepper driver takes step and direction signals it is not difficult.

Have a look at the second example in this Simple Stepper Code for movement without acceleration.

And then look at this simple acceleration code.

The AccelStepper library can't do very high step rates because (I believe) it uses floating point maths.

...R

Robin2

I’m looking at your code and one question came to mind right away. In “single step” you do the following:

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

Now before I go any further, I must mention that I come from the PLC world (mostly Allen-Bradley).

My question: is that time interval going to be long enough !? Output will be High, then a blink later it will be Low ... we’re talking about few micro-seconds at best !!!

In some PLC that wouldn’t work as outputs are “written” at the end of the scan. The Arduino being asynchronous Its outputs are updated in “real-time” but still, that’s not long in-between !

It does depend on the length of pulse required by your stepper driver - you will need to read the stepper driver documentation to be sure. The digitalWrite() function is quite slow so the code you have quoted will give a pulse width of about 5 to 10 microsecs - plenty long enough for the A4988 or DRV8825 drivers that are commonly used with an Arduino. The DRV8825 just needs 1.9µsecs.

If you need a longer pulse you could insert delayMicroseconds(NNN). If NNN is very short (like 10 or 15 µsecs) it would probably not be worth the trouble of writing a non-blocking version.

...R

Robin2: I used your "Step with acceleration" example and modified it.

I'm pretty happy about the result and I can get up to 500RPM.

Just curious how it's going to behave under load !

Thanks for your help/advises !

jasmino:
Just curious how it's going to behave under load !

That depends on your motor rather than the code - except that you may need slower acceleration.

...R