Motor not turning at 200 steps per second

Hi, i have a nema 17 stepper motor not work normally it start vibrating when i set the speed of rotation at 200 steps per second or under , but when i set the speed at 210 and above it work perfectly .

#include <AccelStepper.h>
//Define stepper motor connections
#define dirPin 2
#define stepPin 3
//Create stepper object
AccelStepper stepper(1,stepPin,dirPin); //motor interface type must be set to 1 when using a driver.
void setup()
{
  stepper.setMaxSpeed(1000); //maximum steps per second
}

void loop()
{ 
  stepper.setCurrentPosition(0); //set the current position to 0
  //run the motor forward at 200 steps/second until the motor reaches 400 steps (2 revolutions).
  while(stepper.currentPosition() != 400)
  {
    stepper.setSpeed(200);
    stepper.runSpeed();
  }
  stepper.setCurrentPosition(0); //reset the position
  delay(1000);

}

Have you tried using the run() function which uses acceleration?

Post a link to the datasheet for your stepper motor and tell us what stepper motor driver you are using.

...R
Stepper Motor Basics
Simple Stepper Code

Non , because i want a constant speed . I am using the DRV8825 driver .

aymannox:
Non , because i want a constant speed .

That may be, but doing some tests with acceleration may help to diagnose the problem.

...R

Robin2:
That may be, but doing some tests with acceleration may help to diagnose the problem.

...R

As i mentioned the problem appears just when i set the speed at 200 or under but with more than 200 it work perfectly with constant speed

aymannox:
As i mentioned the problem appears just when i set the speed at 200 or under but with more than 200 it work perfectly with constant speed

I was aware of that when I wrote Reply #1

...R

You should be setting the acceleration in setup() too, not just max speed, as its dependent on your electrical and mechanical setup.

stepper.setAcceleration(...)

Experimentation will determine the highest acceleration your system can reliably handle. In the AccelStepper
library acceleration is given in terms of (micro)steps per second per second. Try something like 1000 in the
first instance.

I have switched the microstepping from full step to 1/8 and it work perfectly now with speed under 200 steps per revolution

Good!