accelStepper skips steps while accelerating

hi, i am trying to run a stepper with acceleration. AccelStepper library looks like a good way for it. but when i try it, it skips steps while accelerating but it doesn’t when it goes faster (even if i resist it with my finger). here is a video of running with given code.

what is the problem here? can anyone help?

/*Example sketch to control a stepper motor with A4988 stepper motor driver, AccelStepper library and Arduino: acceleration and deceleration. More info: https://www.makerguides.com */
// Include the AccelStepper library:
#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);


void setup()
{

  // Set the maximum speed and acceleration:
  stepper.setMaxSpeed(2100);
  stepper.setAcceleration(50);

}
void loop() {


  // Set the target position:
  stepper.moveTo(20000);
  // Run to target position with set speed and acceleration/deceleration:
  stepper.runToPosition();
  delay(1000);

}

How do you know it skips steps? I can't make out any evidence for that in your video.

What happens if you try a lower maximum speed?

...R

on these seconds you can see the rotational movement is disturbed. also when i check the start and finish points (on single or multiple turns) they don't match.

with lower speed;
for 100, there is no issue,
for 300 and over, problem is still there,
for 200, it skips turns wile turning on max speed.

so i am thinking that, if i can start the motion with 300 speed value, than accelerate from there, it should fix my problem. don't know how to do it tho. is there such an option for accelStepper?

The steps are fixed by the specification of the particular stepper motor.
Going outside that can result in the sort of things you are seeing.

To change the speed of a stepper there are other more common methods.
Read up HERE

Bob.

thanks bob, i am checking now. but i think i find another way without the library for my problem.

What microstepping are you using? An unloaded stepper motor is about the most resonant configuration possible so mid-band resonance will be an issue without microstepping and without mechanical damping. I'd suggest starting at x16 microstepping if you aren't already. Some mechanical damping may help (belt drive systems are inherently damped, lead-screw systems much less so)

that's makes sense. i am using full step. gonna try it with 16 microsteps.

Hello Beebbop, I am having the same issue as well. Have you found a solution?

The thing is when I use a very simple code sending myself pulses to the driver the stepper simply moves very fast and doesnt skip steps. Code below is from How To Control Stepper Motor with A4988 Driver and Arduino I have just adjusted the pin numbers.

const int stepPin = 8;
const int dirPin = 9;

void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay

digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}

But when I use Accel stepper with speed higher than 100 the motor cannot finalize one revolution (corresponding to 200 steps in my case). It always has a deficit of around 15degrees or more when the speed is set higher.
Code below is from Accelsteppers own page. Again I agve adjusted only pins. AccelStepper: ConstantSpeed.pde
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(1,8,9); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
int x;

void setup()
{

}
void loop()
{
if (stepper.distanceToGo() == 0)
{
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
delay(1000);
x=x+200;
stepper.moveTo(x);
stepper.setMaxSpeed(100);
stepper.setAcceleration(200);
}
stepper.run();
}

Since its a resonance phenomenon the longer you are at the resonant frequency the more violent the resonance.

Use mechanical damping and/or microstepping to tame such behaviour. Also tune the acceleration as high as
works reliably under load, so you aren't spending a long time at a resonant speed.