Stepper not coming back to zero, losing steps??

Hi,

i have an issue with a stepper motor driven feed on a vertical slotter,

it basically fires up the spindle which is a 3phase motor, then every revolution that triggers feed to be put on and also taken off at the bottom off the stroke in order to cut out of the material and back to zero, however its often a few degrees off when it comes back to zero,

i have tried it with a different motor and driver not connected to the machine and its doing the same thing so i suspect its steps getting lost between the arduino and the driver,

whats really confusing me is i have tried slowing the motor right down to 2000 steps/sec and acceleration right down and it seems to do exactly the same thing, heres some of the code,

how else can i diagnose where the steps are going?

Cheers
Ralph

AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);

stepper1.setMaxSpeed(3000.0);
stepper1.setAcceleration(60000.0);

if (CNCCut)
{
digitalWrite(spindle, HIGH);
if (CNCCut && tdctop != lasttdctop && tdctop == LOW)
{

stepper1.moveTo(cuttingzero + steps + 4); // - number gives its a first cut and helps backlash??
stepper1.run();
cuton = true;
steps += 4;
Delay = ((( millis() - previousMillis) * 0.625) - (steps) * 2.7) - 29;
revtime = (millis() - previousMillis);
Serial.println(steps);
Serial.println(revtime);
Serial.println(Delay);
previousMillis = millis();
}
lasttdctop = (tdctop);
if (cuton && CNCCut && millis() >= previousMillis + (Delay)) // this needs replacing a delay
{
if (modestate == LOW) stepper1.moveTo(cuttingzero); // mode switch 2 blind hole
else stepper1.moveTo(cuttingzero + steps - 4); // mode switch 1 through cut
stepper1.run();
cuton = false;
}
}
else if (!tdctop) digitalWrite(spindle, LOW);
if (steps > stepstocut)
{
stepper1.moveTo(cuttingzero);
CNCCut = false;
steps = 0;
}

You are probably not calling the run() method often enough - those serial prints may be stuttering the
motor if you don't call run() in between then.

You code is all mangled, and not in a code tags anyway - please post, in code tags, the complete sketch verbatim
if you can.

Ideally the run() method should not be in any function or structure. The run() method should be called every time through loop() and the loop() time must be less than the time between steps.

 stepper1.setAcceleration(60000.0);

That acceleration is very very high. Nearly the same as no acceleration. That can cause missed steps if you start the motor at higher speeds.

Your code would be easier to read and follow if it was indented (formatted). The IDE autoformat tool (ctrl-t or Tools, Auto Format) will do that for you.

Will try this tomorrow, I can remove the serial bits that was just for checking stuff,

I'm a code newbie really, could you explain more about where I'm not laying it out right? I'm keen on improving this,

Edit, acceleration seems to be ok, it's a closed loop 12nm motor and seems ok even faster, I'm trying to take the cut off as quick as possible at the bottom,

Cheers for the help,
Ralph

That's a very small motor!
N = newton
n = nano

You have already received some good advice but I would slow everything way down speed. 2000 steps/sec still maybe to fast. We do not know what your mechanical setup is. What do you have for micro steps. is it geared and what mechanism are you using to run your saw up and down? I would certainly slow down the acceleration. what are you using for a closed loop system? Sorry for all of the questions but all of this matters.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.