Stepper Motor Step Accuracy Issues

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. :slight_smile:

Please post a link to the data sheet for the motors, the power supply and a clear (not "Fritzing for the brain dead") wiring diagram.

To what value did you carefully set the current limit on the driver?

Try setting a much lower step rate.

This always happens first few times whenever I change the direction of motion by changing the direction command from 'F' to 'B'.

This is how people measure the mechanical backlash in the system.

jremington:
This is how people measure the mechanical backlash in the system.

That sounds like a reasonable interpretation of the symptom.

I have written code for controlling a small lathe and I measured (by experiment) how many extra steps are needed to overcome backlash. Then when the direction changes that many steps are added to the first move.

...R
Stepper Motor Basics
Simple Stepper Code

I have written code for controlling a small lathe and I measured (by experiment) how many extra steps are needed to overcome backlash. Then when the direction changes that many steps are added to the first move.

Is this quite common in mechanical systems?
Also our ball screw nut is preloaded. Wouldn’t it remove the backlash?

I have attached the motor and power supply(Model GST25A12) datasheets.

I highly doubt its the circuitry as its functioning fine in all other cases except for the change of direction case. Circuit connections are same as what is mentioned in the code. Direct connections from Arduino board to the module pins.

I think the full scale current was set to around 1A.
I did try lowering the step rate but the problem still persists.

Motor BH42SH38-1684LA-BholanathStepperMotor.pdf (72.7 KB)

Power SUpply Meanwell GST25A-SPEC.PDF (564 KB)

Is this quite common in mechanical systems?

Backlash is completely unavoidable, but by very careful (and usually quite expensive) design it can be minimized so as to be negligible. That does not appear to be the case for your system.

I think the full scale current was set to around 1A.

“I think” is not reassuring, consider that motor current is such an important parameter for a properly functioning system.

You need to write a short Arduino program to explore the behaviour of the motor and the mechanical system. Perhaps set it to move the machine 15mm in one direction, pause and move 15mm in the other direction and see if it gets back to the starting position.

Also put some sort of tell-tale on the motor shaft so you can be sure the motor is not missing steps. The motor shaft should return the exact same angle if the same number of steps is used for out and back.

Of course, if you need to add steps to compensate for backlash then you will have more steps for the return move compared to the outward move.

Start with a low step rate and then increase it gradually until it starts missing steps so you know the working limits.

If you accelerate the motor up to speed and decelerate to a stop it should be possible to get significantly higher speeds.

In all of this testing don't bother trying to send any data from the PC - just modify the program when you need to try something different.

...R

Hey guys,

I was doing a couple of tests today to see if it was really a backlash problem.
So I changed the ball screw arrangement to one with a 1mm pitch. So, the mechanical setup is supposed to move a distance of 1mm/200steps = 5 micrometer per one full step.

Following is the testing pattern which I did.

I moved the motor Forward 3 times and then moved the motor Backward one time. Each of those times, I moved the motor 'X' number of steps in a single shot, where X = 5, 10, 100, 500, 1000 steps. Testing pattern is as shown in the diagram below.

Notice the positions A, B, C, D and E. I connected the linear encoder and measured the position in each of the cases. I repeated the test for each 'X' case, multiple times and recorded the average of the readings. Data is as shown in the table below. All readings are in mm.

I would assume backlash error is the difference between Postion E and Postion C.

Backlash errors seem to be constant for X =10, 100, 500, 1000 but for X = 5, Backlash seems to be more.

Shouldn't the backlash error be same for X= 5 steps as well. Or is there something else at play here? Or is the issue not even related to backlash?

"I think" is not reassuring, consider that motor current is such an important parameter for a properly functioning system.

It is set at 1A.

The backlash is only when you change direction of rotation. That is where the name comes from. This parameter is part of the setup for all normal CNC machines. Your problem may be related to not letting the stepper control hold the position when stopped.

Paul

Your problem may be related to not letting the stepper control hold the position when stopped.

What does this mean? What could be cause of this? How can I verify if this is the issue?

Try turning the stepper motor after doing one of the step tests you did to get your backlash measurements. If you can turn the shaft, then the motor controller has released the motor to turn. This should not happen until you are ready to stop the program.

Paul

Thanks. I will do the test and report back on Monday.

Your ballscrew is probably not the main source of backlash - you seem to have single
bearings at each and of the leadscrew - for low backlash you need at least one to be a preloaded
double-race bearing.

Also the end-plates may be flexing - they don't seem to have very solid joints to the trackway.
Try adding stiffing bar across the top between the two end-plates.

Problem still seems to persist. I tried all tests mentioned here but no positive results so far.

I found this interesting video Cause of Vibration in Stepper Motors - YouTube

This can be a probable issue when I am moving only a few steps?

dev_000:
Problem still seems to persist. I tried all tests mentioned here but no positive results so far.

I found this interesting video Cause of Vibration in Stepper Motors - YouTube

This can be probable issue when I am moving only a few steps?

If the video related the action to the current in the motor coils, then it might be meaningful.

Paul

They do show vibrational characteristics of the motor vs motor speed here : Vibration Characteristics of Stepper Motors - YouTube

dev_000:
Problem still seems to persist. I tried all tests mentioned here but no positive results so far.

Post the latest version of your program and describe in detail what it does.

…R

While the video in Reply #12 is a nice illustration of vibration it does nothing to explain your loss of accuracy unless the vibration or resonance is sufficient to cause the motor to miss steps.

If you are not getting accurate movement at low step speeds (i.e. at speeds where there are definitely no missed steps) then the problem is within the machine rather than the motor or the program.

And with a suitable telltale on the motor shaft it is very easy to detect missed steps - just command the motor to rotate the motor forward for (say) 400 steps and then backwards by the same number.

...R

Robin2:
And with a suitable telltale on the motor shaft it is very easy to detect missed steps - just command the motor to rotate the motor forward for (say) 400 steps and then backwards by the same number.

There seems to be issue in conducting a test, when I put the motor in a no load condition with lets say, a flag sticker connected to it, I cant visually see it missing steps(I tried this with multiple motors with code mentioned before). But then again I wont be able to see visually that accurately to see if it had missed a step(as the step angle is small).
I tried connecting it to a shaft system and recording values on the encoder and that's what I had posted before.

A general question, how does lets say 3D printers achieve really good repeatable accuracy(Or am I wrong here) with steppers? Do they usually correct for backlashes in the code? I don't see them using encoded motors.

Do you have access to 2 dial indicators similar to this and know how to use them?

I think I would probably have one lying around in the lab. I am not sure I will check and I am not sure of its least count either.

Are you proposing to do something like this Arduino Stepper: Ultimate Accuracy! - YouTube ?

I think atleast I am doing something similar with a digital encoder connected next to it with a least count of 0.001mm. That's how I reported the previous readings.