I have a Nema23 Stepper motor which I have connected using a DM542 Stepper Driver. I supply it a current of around 3Amps and have set the step value to 1/8th of a full Step. While I am rotating the entire assembly using the stepper motor as shown in the video link attached below , it seems to be stopping with a sudden jerk .
#include <Servo.h> //Servo library
// Pin Definitions
#define dirPin 2 // Direction
#define stepPin 3 // Step Pulse
#define enaPin 4 // Enable Motor
// #define STPR 200 // Steps per Revolution
Servo myservo; //Servo name is myservo
// Variables
int stepDelay = 1250; // Delay between steps in microseconds
int stepsToMove = 20;
void setup() {
Serial.begin(9600);
// myservo.attach(9); // attaches the servo signal pin on pin D6
// Set pin modes
pinMode(enaPin, OUTPUT);
digitalWrite(enaPin, LOW); // Enable motor
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
}
void loop() {
// myservo.write(160); //Turn clockwise at high speed
// delay(3000);
// myservo.write(40);
// delay(3000);
digitalWrite(dirPin, LOW); // Set direction to clockwise
for (int i = 0; i < stepsToMove; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(20);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay - 20);
}
delay(3000); // Delay for 1 second
}
Any Ideas why the stepper is stopping in this manner , I tried playing around with different current values as well as different mini steps and also tried reducing the rmps but l but nothing seems to fix it.
Any help would be greatly appreciated.