Hi all,
I am working with a stepper motor for a project and I am running into a weird issue with the accuracy of its steps.
My setup consists of an Arduino Uno, DRV8825 Pololu Breakout Board and a Stepper motor(Step angle 1.8 degree, so 200 steps for 360 degrees). Stepper motor is connected to a linear mechanical system with a ball screw arrangement with a 4mm pitch. See attached Pic1 and Pic2 for the images of the mechanical setup. I have also connected a linear encoder to measure the accuracy of the mechanical assembly along its axis.
I am trying to step the motor, one step at a time, when I am sending a command via Arduino's Serial monitor. Following is the code I am using.
// Arduino Digital Pins and Motor Connections
int dPin = 6; // Direction motor || HIGH - Towards the Motor || LOW - Away from the Motor
int sPin = 7; // Step Pin for providing square pulses
int wake = 9;
int M1 = 4; // Mode Pins
int M0 = 5; // Mode Pins
int enb = 8; // Enable Pin for driver || HIGH - Driver Disabled || LOW - Driver Enabled
char input;
void step(boolean dir, int steps, int dirPin, int stepperPin)
{
digitalWrite(dirPin, dir);
for (int i = 0; i < steps; i++)
{
digitalWrite(stepperPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepperPin, LOW);
delayMicroseconds(800);
}
}
void setup()
{
Serial.begin(9600);
pinMode(dPin, OUTPUT);
pinMode(sPin, OUTPUT);
pinMode(wake, OUTPUT);
pinMode(enb, OUTPUT);
pinMode(M0, OUTPUT);
pinMode(M1, OUTPUT);
// Full Step Mode
digitalWrite(M0, LOW);
digitalWrite(M1, LOW);
digitalWrite(enb, HIGH);
digitalWrite(wake, HIGH);
}
void loop()
{
if (Serial.available() > 0)
{
input = Serial.read();
if (input == 'F')
{
digitalWrite(enb, LOW);
step(HIGH, 1, dPin, sPin);
delay(100);
digitalWrite(enb, HIGH);
Serial.println("Move Forward");
}
else if (input == 'B')
{
digitalWrite(enb, LOW);
step(LOW, 1, dPin, sPin);
delay(100);
digitalWrite(enb, HIGH);
Serial.println("Move Backward");
}
else
{
Serial.println("Wrong Input");
}
}
}
The mechanical setup is supposed to move a distance of 4mm/200steps = 20 micrometer per one step of instruction. I am driving the driver DRV8825 in the full step mode.
So here is the problem I am facing,
When I am sending a command 'F' for the first 2-3 times, I am seeing the motor is moving only around 15 microns. Beyond that, its accurately moving to around 20microns. This always happens first few times whenever I change the direction of motion by changing the direction command from 'F' to 'B'. See the following reading in the table for a command 'F' and command 'B'. Notice the distance moved in the first few steps in each table.
The following table shows the results when I toggle F and B alternatively via the Serial Monitor.
When I am toggling 'F' and 'B' its moving almost similar distances(but not 20microns though) forward and back.
I have tried with different stepper motors and result always seem to be the same, there seems to be an error in the movement for the first few steps and then distance moved becomes OK.
Why is this problem coming up? Is it a documented issue with Stepper Motors? If so, how do I fix it?
I don't think its due to mechanical inertia because there is always a delay between 2 commands being sent via the Serial monitor. I am providing sufficient time between the commands.
Hoping someone can help out.
Thanks in advance.