Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Losing steps #4

Open
sebasu90 opened this issue Mar 30, 2020 · 5 comments
Open

Losing steps #4

sebasu90 opened this issue Mar 30, 2020 · 5 comments

Comments

@sebasu90
Copy link

sebasu90 commented Mar 30, 2020

test Stepper.txt

Hi, I'm using the library with a Stepper driver (only use Pulse pin and Dir pin).
I'm running an example (one revolution forward, one revolution reverse).
I notice that it's losing about 1 degree each iteration. If I let it run for a while the zero moves a lot.
I try it with different accelerations, low speeds, medium speeds.

@sebasu90 sebasu90 changed the title Loosing steps Losing steps Mar 30, 2020
@ryancasler
Copy link

I've noticed the same thing. Mine is much more dramatic at lower speeds though. In fact, I can actually see the motor shaft spin in the opposite direction for a brief second during the rotation. I'm using a Nema 17 stepper with a DRV8825 Stepper Driver. Using the regular stepper library i get perfect alignment back at the starting point no matter how many starts and stops I make. With this library, it never winds back up at the same place it started unless I crank the acceleration up to like 100x the Steps Per Second, which defeats the purpose of using the accel library.

@tony-maulaz
Copy link

I had the same problem, it is because during a change of direction, the signal on the DIR pin changes too quickly compared to the signal on the STEP pin. The driver does not yet take into account the change of direction and the first pulse is incorrect.
To fix the problem, you need to add a delay between the state change of the DIR pin and the pulse on the STEP pin.

@ryancasler
Copy link

ryancasler commented Aug 11, 2023

But I am not making a direction change when I see the problem. Why would a problem with he direction pin cause the motor to sin in te opposite direction in the middle of a movement in one direction?
Plus, the reason that delay is not needed is because whatever stepper motor driver you are using is also going to have a delay between the time it receives the pulse and it makes the step and between when it receives the direction command and when it responds to it. As you can see from this datasheet for the TMC2209, it only takes the driver 20ns to be ready to step when a change in direction is made. It's going to take longer than that to begin stepping after the move command is made. So, I don't really think this is a timing problem.

image

@tony-maulaz
Copy link

Hello,
indeed with a TMC2209 there is no problem, but with other types of drivers, the time must be longer between the change on the dir pin and pulse. In this case, the library did not work.
I had to add the following patch:

void moveTo_wait(long step){
    long dist = stepper.distanceToGo();
        if(dist > 0)
            digitalWrite(pinDir, HIGH);
        else
             digitalWrite(pinDir, LOW);

      delay(10); // added delay (10 ms)
     stepper.moveTo(step);
}

Based on my measurements, the change time is about 10us, which is not suitable for the driver.

image

@drf5n
Copy link

drf5n commented Nov 28, 2023

I had the same problem, it is because during a change of direction, the signal on the DIR pin changes too quickly compared to the signal on the STEP pin. The driver does not yet take into account the change of direction and the first pulse is incorrect. To fix the problem, you need to add a delay between the state change of the DIR pin and the pulse on the STEP pin.

Looks like that would be here:

setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses

A DRV8825 driver needs a 650ns setup time per https://www.ti.com/lit/ds/symlink/drv8825.pdf An A4988 needs 200ns per https://www.pololu.com/file/0J450/A4988.pdf

If the existing delay isn't long enough, you could add another delay after it like:

    setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
    delayMicroseconds(_minPulseWidth);     // add extra dir->step delay
    setOutputPins(_direction ? 0b11 : 0b01); // step HIGH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants