How to decide acceleration in Accelstepper stepper library

Hello,

I am new to Accelstepper library. I am using MDBT40 with Stepper motor and programming it using Arduino IDE.
Here are the specification of motor:

Max rated Current: 0.8A
Inductance: 5mH
Input supply : 12V
1.8 degree
1/4th microstepping mode

Since the RPM was not mentioned in the datasheet, I did some calculation using these links:
http://www.daycounter.com/Calculators/Stepper-Motor-Calculator.phtml

I got minimum and maximum RPM to be 100-480 RPM.
i.e. (480*200)/60=1600 steps/sec=> 6400 steps/sec for 1/4th microstepping
So converting it from RPM to steps/seconds gives me maximum speed of 6400 steps/sec.

Thus using this calculation, I used setMaxspeed(6000). About acceleration, I set it to 12000 (random trial and error).
The speed of motor doesn`t seems to fast enough when I run the same motors using timers or without acceleration. After certain value of acceleration, the speed remains constant and is very low (not expected maximum speed). My application requires a slow start for a very small time (5% to total distance).
Can some one help we with how to decide the value of acceleration? Is there any specific calculation?
Also is the maximum speed calculation correct?
Am I going in right direction?

Please someone guide me.
Thanks in advance.

It sounds like you have made tests with two different programs. You need to post the programs so we can see exactly what you are talking about.

What, exactly, is the MDBT40 - at first I thought it was your stepper motor, and then the stepper driver. But I'm not going to read 51 pages to figure it out.

...R

I believe acceleration is steps per second per second so 12000 is out of the ball park and across the river, start with a more conservative value (500?) and work your way up. Also seems like the max steps per second for a 16 MHz processor is around 4000, sounds like your motor is missing lots of steps and falling behind.

Max acceleration and top speed of a stepper need to be experimentally determined with the motor under
load, since miss-stepping depends on many factors including inertia and resonance of the load, supply
voltage, microstepping factor and so forth.

Once you've found the max values that work, back-off about 20% to guarantee reliable operation.

Note that the AccelStepper library has a top step rate thats pretty low (read the source file comments),
since it uses floating point calculations.

So, you ask if there is a calculation, Yes there is. However, it is fairly complicated. So it depends on the drive, the motor, the power supply etc. I usually take real good notes and play with each set up. Make sure you have enough current and voltage to drive the motor first. You mentioned the max speed set to 12,000. One of my projects is set to 2000. and acceleration at 1000 and others, because of the motors are set drastically different.

Do not forget target.setMinPulseWidth(xx). Minimum pulse width keeps the drive from pulsing to quickly. start around 25 and move up or down from there. if this number is to small it will be weak and slow. if it is to large it will keep it from reaching the top speed.

Acceleration numbers react in this way. smaller the number the longer it takes to get to speed. and the larger the number the quicker it gets to speed. I hope this helps.

Dave

There isn’t a meaningful calculation, unless you are prepared to measure torsional inertia and damping
across a range of frequencies in situ (you don’t have the equipment for this) and simulate the composite
system of motor + load in something like matlab.

Trial and error is how its done.

Thanks Alot everyone for the replies.

@Robin2 MDBT40 is 32bit ARM-M0 microprocessor similar to due. I am using arduino IDE to upload firmware to it.

I am using the example code which is provided in accelstepper library. Please check the code below:

// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>
#define MOTOR_A_ENABLE_PIN 16
#define MOTOR_A_STEP_PIN 12
#define MOTOR_A_DIR_PIN 13
// Define a stepper and the pins it will use
AccelStepper stepper(1, MOTOR_A_STEP_PIN, MOTOR_A_DIR_PIN); 

void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(6000);
  stepper.setAcceleration(12000);
  stepper.moveTo(2000);
}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}

The value of setMaxSpeed(6000); is based on calculation and stepper.setAcceleration(12000); is based on trial and error.

edgemoron:
I believe acceleration is steps per second per second so 12000 is out of the ball park and across the river, start with a more conservative value (500?) and work your way up. Also seems like the max steps per second for a 16 MHz processor is around 4000, sounds like your motor is missing lots of steps and falling behind.

The stepper motor moves very fast when there is no acceleration. For acceleration, when the keeping the maxspeed to 6000, if the acceleration is 500 then motor moves very very slow. As I increase the acceleration, the motor rotates faster. However, the speed is very slow till the acceleration is below 6000. When the acceleration exceeds 6000, the motor start moving faster and after some value (~12000) speed saturates to a constant speed.

MarkT:
Max acceleration and top speed of a stepper need to be experimentally determined with the motor under
load, since miss-stepping depends on many factors including inertia and resonance of the load, supply
voltage, microstepping factor and so forth.

Once you’ve found the max values that work, back-off about 20% to guarantee reliable operation.

Note that the AccelStepper library has a top step rate thats pretty low (read the source file comments),
since it uses floating point calculations.

@MarkT I can see the torque is enough. AccelStepper: AccelStepper Class Reference
In the performance section its mentioned that “Gregor Christandl reports that with an Arduino Due and a simple test program, he measured 43163 steps per second using runSpeed(), and 16214 steps per second using run();”

@weldsmith I didnt try “target.setMinPulseWidth(xx).” will try this to incorporate in my code.

MarkT:
There isn’t a meaningful calculation, unless you are prepared to measure torsional inertia and damping
across a range of frequencies in situ (you don’t have the equipment for this) and simulate the composite
system of motor + load in something like matlab.

Trial and error is how its done.

This might be difficult for me :slight_smile: .

Is the calculation for maximum speed correct?
Am I on right direction?

dhiraj_gehlot:
The stepper motor moves very fast when there is no acceleration. For acceleration, when the keeping the maxspeed to 6000, if the acceleration is 500 then motor moves very very slow. As I increase the acceleration, the motor rotates faster. However, the speed is very slow till the acceleration is below 6000. When the acceleration exceeds 6000, the motor start moving faster and after some value (~12000) speed saturates to a constant speed.

Without meaning to be unkind, that makes no sense.

If you have expressed yourself accurately then it seems to me the library is not working properly on your microprocessor.

The max speed of the motor should not be affected by the acceleration figure. The acceleration should only affect how quickly the motor gets to the max speed.

Can you try some suitable test code on a regular 16MHz Arduino and then see if the identical code gives the same effect on your super-duper MCU.

...R

Max speed can be affected by acceleration if the travel is to short.

weldsmith:
Max speed can be affected by acceleration if the travel is to short.

How?

...R

Its simple maths - if to reach max speed you'd end up more than 50% of the way to the destination then
you must stop accelerating before reaching max speed or else overshoot the target.

MarkT:
Its simple maths - if to reach max speed you’d end up more than 50% of the way to the destination then
you must stop accelerating before reaching max speed or else overshoot the target.

In that case the max speed is not reached and it is not affected by the acceleration setting.

…R

weldsmith:
Max speed can be affected by acceleration if the travel is to short.

I tried increasing the distance to a large value. But the behaviour is same.
It doesn`t seems to be affected by distance.
I think I would share video links of motor running at different value of acceleration and speed soon, it may help to debug it in better way. Do you guys think it will help?

dhiraj_gehlot:
I think I would share video links of motor running at different value of acceleration and speed soon, it may help to debug it in better way. Do you guys think it will help?

I suspect not.

Have you tried the code with a regular 16MHz Arduino as I suggested in Reply #7

My strong suspicion is that the library is not working properly on your MCU.

...R

Humor me.

// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>
#define MOTOR_A_ENABLE_PIN 16
#define MOTOR_A_STEP_PIN 12
#define MOTOR_A_DIR_PIN 13
// Define a stepper and the pins it will use
AccelStepper stepper(1, MOTOR_A_STEP_PIN, MOTOR_A_DIR_PIN); 

void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(800);// 1R/PS or 60 rpm will take around 3 second to get to position.
     
  stepper.setMinPulseWidth(55); //25 If much faster than 25 it messes with the stepper performance 
                                             

 stepper.setAcceleration(400); // will accelerate for 1/2 Revolution.

 stepper.moveTo(2000);//  moves 2.5 revs your are asking it to move to position in about .33  seconds
                                  @6000
                                    


}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}

weldsmith:
Humor me.

A guy walked into a bar ...

OR

I admire everything about you.

(Your request is ambiguous)

...R

PS. I am assuming your code is for the benefit of the OP.

I modified dhiraj_gehlot 's code. I was simply asking for dhiraj_gehlot to try the code. There are notes explaining how the code works. I feel the sketch would be a good base line for his setup. The accel of 12000 is way to high. The max speed seems to be a bit high as well. Smaller steppers with lower rotor inertia can run higher speeds, but I am not sure it will reach 7.5 R/PS or 450 RPM. The max speed of 6000 is borderline in my opinion. I am very confident that it will not go this fast under load. However it usually is better to start at lower speeds and then increment the parameters from there. All of the notes are in the modified code.

I hope this helps, Dave.

weldsmith:
I modified dhiraj_gehlot 's code. I was simply asking for dhiraj_gehlot to try the code

That's what I had assumed, but your intro in Reply #14 did not make that clear :slight_smile:

...R

Hello Guys,

Thank you for your replies. :slight_smile:

@Robin I have ordered a new Arduino. Will test the same code with Arduino once I receive it.

@weldsmith I tried constantSpeed code of accelstepper to determine maximum speed.

// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author  Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

AccelStepper stepper(1, 12, 13);


void setup()
{  
   stepper.setMaxSpeed(5500);
   stepper.setSpeed(3500);	
   pinMode(16, OUTPUT);
   digitalWrite(16,LOW);
}

void loop()
{  
   stepper.runSpeed();
}

Started with setSpeed of 200 With slight increment of 100. The maximum speed which I achieved is at stepper.setSpeed(3500); (almost half the theoretical calculated speed and 1000 is max mentioned in the accelstepper documentation). After 4000 motor just vibrates. And at setSpeed(5000) it vibrates horribly.

So keeping 3500 as maximum speed for the motor. I experimented with your code.
I kept the same value as your code without any change. Motor moved slowly first. Then started incrementing acceleration with steps of 50 motor started rotating little fast after every increment, but after 1000, it attain maximum speed (relative to 800).

Next step, I increased the speed to 1500. And started the same experiment with slight increment in acceleration. It shows same behaviour.
Observation: As acceleration moves closer to setspeed, the motor started moving faster. And it attains its maximum speed (relative to setspeed) when the acceleration value crosses the setSpeed.

I tried same with setting the maximum speed to 3500 and repeated the same experiment, the output was same.

However, the speed of motor during constant speed code with setspeed(3500) was greater than the speed of motor during code with acceleration. It is like motor is achieving it peak speed in constant speed code but with acceleration it doesn`t. I also tried to experiment with values of minimum pulse width to 20 and 15, but no change.

Is there something which I am missing?
Am I on right direction?

dhiraj_gehlot ,

Are you using the easy driver? How are you measuring the speed to verify that it is not going as fast and is it drastically slower when using acceleration?

Also you mention you were 1/4 micro stepping. You will achieve a small amount of more speed with out micro stepping. Also use the highest voltage that is allowable for your drive. Keep experimenting and you will find the best performance of that system. Sounds like you are on the right track now.

Dave