Looking for advice on implementing AccelSstepper library.

Hello all

I have been researching and messing around with the Arduino and programming (and electronic circuits) for several months now. Having started with zero knowledge, this forum and other online resources have done me well to get this far.

I am working on a project that will wind wire, received from a wire stripping/processing machine, into coils.
A first version of the machine is built and components have all been selected and the programming for the first portion of the project is complete and working. What i would like to do is have the stepper motor move faster using the AccelStepper library (at least i think thats how i want to do it…). If i try to get the motor faster than currently programmed it chugs, belches and shutters on direction change and some starts. I have played with the AccelStepper library and the motor moves much faster (due to acceleration/deceleration is my guess). My struggle is implementing the library in my current code.

here is what the project scope is :

A homing routine will run and ensure the shuttle is always staring at “HOME” position on initalization and each cycle.

1)When the shuttle reaches home it signals the wire stripper to produce the next piece.

  1. Wire will be pushed from the stripper down the guide tube and between the open drive wheels on the wire shuttle. A fiber optic sensor (PS1) on the stripper will signal when the wire has arrived at the shuttle.(future use)

  2. The drive wheels will close and move the wire until wire is no longer present at PS1, the drive wheels reverse
    direction until PS1 senses a wire. This will be the wire HOME position.(future use)

  3. The shuttle is moved left a predetermined amount. when the location is reached the drive wheels push the
    wire forward a predetermined amount.(future use)

5)The shuttle then moves left an the wire is bent on a 90 degree angle between the wire pin and the roller.(future use)

6)The shuttle moves right and the wire is pushed forward so that the wire is inserted down the center of the winding shaft.

The Shuttle direction cylinder is activated (by photo sensor) and winding back and forth begins in the “Winding Zone”.

7)after several passes through the “Winding Zone” and when wire is no longer sensed in Ps1 the direction cylinder
retracts and the shuttle moves to home. the coil is ejected.

REPEAT

I am trying to provide as much information to you as I can, sorry if its a bit much.

I have attached a drawing of the current setup and a fully commented (hopefully) code for this portion of the project.

link of Rolling Ring Drive http://www.machinedesign.com/mechanical-drives/basics-rolling-ring-linear-motion

I have attached a drawing of the current setup and a fully commented (hopefully) code for this portion of the project.

I don't see any code. I don't see any explanation of what the problem is.

I also realize the code isn’t optimal and any suggestions would be appreciated.

/*  Testing code using Dons Stepper Motor as main drive (4 wire)
   Modified from sketch WANDA LED TEST 02012018
    RR = Rolling Ring Linear Drive
    Using a TB6600 Stepper Driver
   moderate speed, faster wouldn't hurt but maxed out smooth operation with motor speed delay(2)and delayMicroseconds(1)
   AccellStepper library could/would make it faster but need to figure out how to incorporate into this sketch.
   04/03/2018 was able to get faster speeds using delayMicroseconds after writing the step LOW
   04/04/2018 added air solenoids for RR direction change(OUTPUT 4) and coil eject (OUTPUT 3) and programming for these.
   04/06/2018 added photo switch to sense when to engage and disengage directional air cylinder (RRdirection) and started testing programming
   04/09/2018 started programming the photo sensor to activate the direction cylinder and count how many times the RR has passed through it.
   04/24/2018 Programmed initial homing routine in setup, and finalized rough programming of RR Drive to execute a complete cycle.
   I WOULD LIKE TO INCREASE THE TRAVEL SPEED USING THE ACCELSTEPPER LIBRARY OR SOME OTHER METHODOLOGY
*/



// Define the Pins used
#define rrdirection 3//switches the direction of the Rolling Ring (RR) Drive VIA pneumatic cylinder
#define ejector 4    //operates pneumatic cylinder that ejects the wire coil
#define step_pin 5    //Pin 5 connected to Steps pin on RR TB6600
#define dir_pin 6     //Pin 6 connected to RR Direction pin on TB6600 MOTOR DIRECTION HIGH = CCW AND LOW = CW WHEN VIEWED FROM THE SHAFT END
#define sendcommand 7 //led to indicate start command has been sent to the Shleuniger Wire Stripper (for debugging)
#define sleep_pin 8   //Pin 8 connected to RR SLEEP pin TB6600
#define home_switch 9 //Pin 9 connected to Home Switch (Inductive Prox)(will be changed to photo sensor)
#define rrphoto 10    //Pin 10 connected to Photosensor that detects RR location in the "winding zone"
#define home_led 12   //led output to indicate home sensor state (for debugging)


/* *****************************************************FUTURE USE***************************************************
  #define shut_sleep 30 //shuttle motor enable/sleep
  #define shut_dir 31   //shuttle motor direction
  #define shut_step 32  //shuttle motor steps
  #define wire_sens1 33 //first wire sensor
  #define wire_sens2 34 //second wire sensor
  #define wheel_open 35 //operates pneumatic cylinder that opens and closes shuttle wheels
  ********************************************************************************************************************
*/


int home_count = 0;//used to break out of homing loop
int home_state = 0;//used to monitor state of home sensor
int home_lastval = 0;//records last value of home sensor
int commandcount = 0 ;//used to break out of send command loop
//int stepcount = 0;//not currently used
int rrphoto_count = 0;//used to break out of "Winding Zone"
int rrphoto_state = 0;//used to monitor the state of the photo sensor
int rrphoto_lastval = 0;//records the last value of teh photo sensor





void setup() {

  Serial.begin(9600); //debugging aid
  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(sleep_pin, OUTPUT);
  pinMode(home_switch, INPUT_PULLUP);
  pinMode(rrphoto, INPUT_PULLUP);
  pinMode(home_led, OUTPUT);
  pinMode(sendcommand, OUTPUT);
  pinMode(rrdirection, OUTPUT);
  pinMode(ejector, OUTPUT);


  /* ***********************************************FUTURE USE*************************************************************
    pinMode(shut_dir, OUTPUT);
    pinMode(shut_step, OUTPUT);
    pinMode(shut_sleep, OUTPUT);
    pinMode(wire_sens1, INPUT);
    pinMode(wire_sens2, INPUT);
   *************************************************************************************************************************
  */
  digitalWrite(rrdirection, LOW);
  digitalWrite(ejector, LOW);
  Serial.println("Momma Im coming home... ");

  //*********************************************INTIAL HOMING ROUTINE******************************************************
  
  while (!digitalRead(home_switch)) { // Do this until the switch is not activated
    digitalWrite(dir_pin, HIGH);
    digitalWrite(step_pin, HIGH);
    delay(2);                       //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }

  while (digitalRead(home_switch)) {  // Do this until the switch is activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                       //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }

//****************************************************************************************************************************
  Serial.println("Luuucie I'm Home ");//debugging
  //stepcount = 0; // Reset position variable to zero CURRENTLY NOT USED

}

void loop() 

{
//******************************************************REQUEST A WIRE FROM STRIPPER (PULSE)******************************************
   if (commandcount == 0)
  { Serial.println("Send Me A Wire ");//debugging
    digitalWrite (home_led, LOW);
    digitalWrite(sendcommand, HIGH);
    delay(3000);
    digitalWrite(sendcommand, LOW);
    commandcount = 1; // used to exit loop
  }
//*****************************************************MOVE MOTOR TO THE WINDING ZONE****************************************************
  if (rrphoto_count < 3)
  { digitalWrite (sleep_pin, LOW);//ENABLES TB6600
    digitalWrite (dir_pin, LOW);
    digitalWrite (step_pin, HIGH);
    delay(2);                         //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite (step_pin, LOW);
    delayMicroseconds(1);
  }

  if (rrphoto_count == 3)
  { do {                                            //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
      digitalWrite (sleep_pin, LOW);//ENABLES TB6600
      digitalWrite (home_led, LOW);
      digitalWrite (dir_pin, HIGH);
      digitalWrite (step_pin, HIGH);
      delay(2);                         //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
      digitalWrite (step_pin, LOW);
      delayMicroseconds(1);
    }

   //***********************************************MOVING BACK TO HOME TO START CYCLE************************************ 
    while (!digitalRead(home_switch));
    digitalWrite(ejector, HIGH);
    delay(1000);
    digitalWrite(ejector, LOW);
    rrphoto_count = 0;//used to RESET loop
    commandcount = 0;//used to RESET loop

  }
  while (digitalRead(home_switch))
  { //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite (sleep_pin, LOW);//ENABLES TB6600
    digitalWrite (home_led, HIGH);
    digitalWrite (dir_pin, LOW);
    digitalWrite (step_pin, HIGH);
    delay(2);                           //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite (step_pin, LOW);
    delayMicroseconds(1);
  }
  digitalWrite (sleep_pin, HIGH);//DISABLES TB6600;

  //rrphoto_count = 0;//used to break out of loop

  rrphoto_state = digitalRead(rrphoto);


  if (rrphoto_state != rrphoto_lastval) // compare the buttonState to its previous state
  {
    if (rrphoto_state == HIGH)// if the current state is HIGH then the button went from off to on:
    {

      rrphoto_count++;// if the state has changed, increment the counter

      Serial.print("number of sensor passes: ");//debugging
      Serial.println(rrphoto_count);//debugging
    }



    // save the current state as the last state, for next time through the loop
    rrphoto_lastval = rrphoto_state;


    // ***********************************OPERATES the PNEUMATIC solenoid UNTIL 3  sensor COUNTS***********************************
    if (rrphoto_count >= 1) //problem from yesterday
    {
      digitalWrite(rrdirection, HIGH);

    }
//***************************************DISENGAGES THE PNEUMATIC SOLENOID TO ALLOW THE RR DRIVE TO GO BACK HOME ******************
    if (rrphoto_count >= 3)
    {
      digitalWrite(rrdirection, LOW);



    }

  }
}

I am sure I have left out details required to assist. Please ask.

Thank you

Mike

Paul

the problem is that the servo speeds are too slow, i would like the travel speed faster. but decreasing the step delay causes issues with step loss. I don't believe its hardware related as when i run AccellStepper examples it moves without the unwanted characteristics of shudder, step loss etc.

I am not sure how to integrate the library in my code.

Sorry for the delay in post/ reply but a 5 minute wait by the site is in effect.

//HOPING TO USE ACCELSTEPPER TO OPTIMIZE

You are not going to benefit from acceleration when single stepping.

If you need to take a lot of steps, and that number of steps is known (or changes while the stepper has not yet reached it's end position, then you can benefit from acceleration.

Paul

Thank you for the quick reply.

If I understand you, a “target” is necessary. Like the number of steps required to complete the move.
Could a photo sensor be an acceptable “target”? Run until the sensor is activated or a certain number of sensor state changes are made?

The AccelStepper library is designed for the situation where you know in advance exactly how many steps are required. Think about an instruction to move a CNC machine 17.83 mm. When the library knows the number of steps it can work out a sequence for the start and the end of the move that increases / decreases the speed smoothly up to the allowed maximum.

Clearly that system is inappropriate for a system in which the exact number of steps cannot be known in advance. I think it is possible to use the AccelStepper library in a mode in which you tell it to move a very large number of steps - (far more than you will actually need) and then tell it to stop at some point. I believe, when it is told to stop it will decelerate to a stop in as few steps as possible for the given speed and deceleration rate

It is not difficult to implement a simple acceleration system - see the code in this link as an example.

However whether using your own code or the AccelStepper library it is easy to accelerate at at the start of a move but you may have a problem at the end of a move if the end is identified by a limit switch because the deceleration cannot start until the end-limit is detected, and that may be too late.

...R
Stepper Motor Basics
Simple Stepper Code

Thank you Robin

I will try out the code example you have provided. My sensors are pass through so crashing into them shouldn't be an issue.

And thank you PaulS for your responses.

ultratec:
I will try out the code example you have provided. My sensors are pass through so crashing into them shouldn’t be an issue.

You still need to think about how far past the sensor your machine can move without causing damage.

…R

Hi All

I am back with a few more questions and obstacles since receiving a bit of accel/decel programming from Robin in a response above. (Thanks again Robin)

I have been integrating the Accel/Decel into my sketch, and with some trial and error I have had some success.

Here is what happens,

The motor goes through the setup () homing routine perfectly fine and as expected.

The program then issues the “sendcommand” and begins stepping the 2000 steps, once that is complete (indicated by serial “done 2000”) the motor then whines when attempting to return home. If I give it a good spin by hand, it resumes, and completes the homing routine.

What i suspect is happening is that the moveMotor() routine needs a variable(s) reset to begin the next acceleration properly.

It might also be that the setup() instance of motorMove() didn’t complete the deceleration (was interrupted by the home switch) process and that is messing up the next insance its called.

If someone can explain why the second motor move is not accelerating properly it would be most appreciated.

the code is

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses micros() to manage timing to allow high step rates to be tested
// and illustrates a simple method for accleration and deceleration




#define rrdirection 3//switches the direction of the Rolling Ring (RR) Drive VIA pneumatic cylinder
#define ejector 4    //operates pneumatic cylinder that ejects the wire coil
#define step_pin 5    //Pin 5 connected to Steps pin on RR TB6600
#define dir_pin 6     //Pin 6 connected to RR Direction pin on TB6600 MOTOR DIRECTION HIGH = CCW AND LOW = CW WHEN VIEWED FROM THE SHAFT END
#define sendcommand 7 //led to indicate start command has been sent to the Shleuniger Wire Stripper (for debugging)
#define sleep_pin 8   //Pin 8 connected to RR SLEEP pin TB6600
#define home_switch 9 //Pin 9 connected to Home Switch (Inductive Prox)(will be changed to photo sensor)
#define rrphoto 10    //Pin 10 connected to Photosensor that detects RR location in the "winding zone"
#define home_led 12   //led output to indicate home sensor state (for debugging)

unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long slowMicrosBetweenSteps = 6000; // microseconds
unsigned long fastMicrosBetweenSteps = 750;
unsigned long stepIntervalMicros;
unsigned long stepAdjustmentMicros;
int numAccelSteps = 200; // 100 is a half turn of a 200 step motor
int numSteps = 32000;
int stepsToGo;

int home_count = 0;//used to break out of homing loop
int home_state = 0;//used to monitor state of home sensor
int home_lastval = 0;//records last value of home sensor
int commandcount = 0 ;//used to break out of send command loop
//int stepcount = 0;//not currently used
int rrphoto_count = 0;//used to break out of "Winding Zone"
int rrphoto_state = 0;//used to monitor the state of the photo sensor
int rrphoto_lastval = 0;//records the last value of the photo sensor
int step_count;
int step_delay=1400; 

void setup() {

  Serial.begin(115200);
  Serial.println("Starting Stepper Demo with acceleration");

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
 pinMode(sendcommand, OUTPUT);

  stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
  stepIntervalMicros = slowMicrosBetweenSteps;
  stepsToGo = numSteps;
  // digitalWrite(dir_pin, direction);//might not be beeded

  //********************************************************************* Homing (SETUP)**********************************************************
  digitalWrite(rrdirection, LOW);
  digitalWrite(ejector, LOW);
  Serial.println("Momma Im coming home... ");
  while (!digitalRead(home_switch)) { // Do this until the switch is not activated
    digitalWrite(dir_pin, HIGH);
    moveMotor();
  }
  //stepsToGo = 0;//added to try end loop (not needed?)
  delay(500);
  //****************************************************************** back off homing switch (slowly)********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                       //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }
  Serial.println("Luuucie I'm Home ");//debugging
  //****************************************************************************************************************************************
}
//******************************************************REQUEST A WIRE FROM STRIPPER (PULSE)******************************************
void loop() {
  if (commandcount == 0)  { 
    Serial.println("Send Me A Wire ");//debugging
    digitalWrite (home_led, LOW);
    digitalWrite(sendcommand, HIGH);
    delay(3000);
    digitalWrite(sendcommand, LOW);
    commandcount = 1; // used to exit loop
  }
  //*****************************************************MOVE MOTOR TO THE WINDING ZONE****************************************************

while (commandcount == 1)
{for (; step_count <= 2000; step_count++)
  {digitalWrite (sleep_pin, HIGH);
      digitalWrite (home_led, LOW);
      digitalWrite (dir_pin, LOW);
      digitalWrite (step_pin, HIGH);
      delayMicroseconds(step_delay);
      digitalWrite (step_pin, LOW);
      delayMicroseconds(step_delay);}
      Serial.println("done 2000");
      commandcount=2;}
  //********************************************************************* Homing **********************************************************

  if (home_count ==0)
  {while (!digitalRead(home_switch)) { // Do this until the switch is not activated
    digitalWrite(dir_pin, HIGH);
    moveMotor();
  }
  Serial.println("Luuucie I'm Home Again ");//debugging
  home_count = 1 ;
  }
  
  
 
  //****************************************************************** back off homing switch ********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                       //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }
  //****************************************************************************************************************************************



}
void moveMotor() {
  if (stepsToGo > 0) {
    if (micros() - prevStepMicros >= stepIntervalMicros) {
      prevStepMicros += stepIntervalMicros;
      singleStep();
      stepsToGo --;
      if (stepsToGo <= numAccelSteps) {
        if (stepIntervalMicros < slowMicrosBetweenSteps) {
          stepIntervalMicros += stepAdjustmentMicros;
        }
      }
      else {
        if (stepIntervalMicros > fastMicrosBetweenSteps) {
          stepIntervalMicros -= stepAdjustmentMicros;
        }
      }
    }
  }

}

void singleStep() {

  digitalWrite(step_pin, HIGH);
  digitalWrite(step_pin, LOW);

}

Your code is very difficult to read. Before posting the next version use the AutoFormat tool to indent it consistently so it is easy to see which pieces belong where.

You seem to be controlling the motor with the moveMotor() function is some places and without it in other places. Why? Why not use it everywhere that you need to make the motor move?

Your description of the symptom

the motor then whines when attempting to return home

suggests that you are trying to drive it at a too high speed.

For the acceleration feature in moveMotor() to work you need to specify the number of stepsToGo. Without that it won't know what it should be doing.

...R

Thank you for your reply. Sorry i haven’t figured out the quote feature on the forum.

Robin: You seem to be controlling the motor with the moveMotor() function is some places and without it in other places. Why? Why not use it everywhere that you need to make the motor move?

My reason for this is I needed to move the motor away from the home switch so I can call another homing routine using moveMotor().

Robin: suggests that you are trying to drive it at a too high speed.

or trying to start without acceleration? the same speed was used in the first call of the homing routine so the speeds should work with acceleration ramp.

so my question/obstacle is how to reset the acceleration code of the moveMotor code, or at least i think that’s what happening.

code posted with auto format.

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses micros() to manage timing to allow high step rates to be tested
// and illustrates a simple method for accleration and deceleration




#define rrdirection 3//switches the direction of the Rolling Ring (RR) Drive VIA pneumatic cylinder
#define ejector 4    //operates pneumatic cylinder that ejects the wire coil
#define step_pin 5    //Pin 5 connected to Steps pin on RR TB6600
#define dir_pin 6     //Pin 6 connected to RR Direction pin on TB6600 MOTOR DIRECTION HIGH = CCW AND LOW = CW WHEN VIEWED FROM THE SHAFT END
#define sendcommand 7 //led to indicate start command has been sent to the Shleuniger Wire Stripper (for debugging)
#define sleep_pin 8   //Pin 8 connected to RR SLEEP pin TB6600
#define home_switch 9 //Pin 9 connected to Home Switch (Inductive Prox)(will be changed to photo sensor)
#define rrphoto 10    //Pin 10 connected to Photosensor that detects RR location in the "winding zone"
#define home_led 12   //led output to indicate home sensor state (for debugging)

unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long slowMicrosBetweenSteps = 6000; // microseconds
unsigned long fastMicrosBetweenSteps = 750;
unsigned long stepIntervalMicros;
unsigned long stepAdjustmentMicros;
int numAccelSteps = 200; // 100 is a half turn of a 200 step motor
int numSteps = 32000;
int stepsToGo;

int home_count = 0;//used to break out of homing loop
int home_state = 0;//used to monitor state of home sensor
int home_lastval = 0;//records last value of home sensor
int commandcount = 0 ;//used to break out of send command loop
//int stepcount = 0;//not currently used
int rrphoto_count = 0;//used to break out of "Winding Zone"
int rrphoto_state = 0;//used to monitor the state of the photo sensor
int rrphoto_lastval = 0;//records the last value of the photo sensor
int step_count;
int step_delay = 1400;

void setup() {

  Serial.begin(115200);
  Serial.println("Starting Stepper Demo with acceleration");

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(sendcommand, OUTPUT);

  stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
  stepIntervalMicros = slowMicrosBetweenSteps;
  stepsToGo = numSteps;
  // digitalWrite(dir_pin, direction);//might not be beeded

  //********************************************************************* Homing (SETUP)**********************************************************
  digitalWrite(rrdirection, LOW);
  digitalWrite(ejector, LOW);
  Serial.println("Momma Im coming home... ");
  while (!digitalRead(home_switch)) { // Do this until the switch is not activated
    digitalWrite(dir_pin, HIGH);
    moveMotor();
  }

  delay(500);
  //****************************************************************** back off homing switch (slowly)********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                       
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }
  Serial.println("Luuucie I'm Home ");//debugging
  //****************************************************************************************************************************************
}
//******************************************************REQUEST A WIRE FROM STRIPPER (PULSE)******************************************
void loop() {
  if (commandcount == 0)  {
    Serial.println("Send Me A Wire ");//debugging
    digitalWrite (home_led, LOW);
    digitalWrite(sendcommand, HIGH);
    delay(3000);
    digitalWrite(sendcommand, LOW);
    commandcount = 1; // used to exit loop
  }
  //*****************************************************MOVE MOTOR TO THE WINDING ZONE****************************************************

  while (commandcount == 1)
  { for (; step_count <= 2000; step_count++)
    { digitalWrite (sleep_pin, HIGH);
      digitalWrite (home_led, LOW);
      digitalWrite (dir_pin, LOW);
      digitalWrite (step_pin, HIGH);
      delayMicroseconds(step_delay);
      digitalWrite (step_pin, LOW);
      delayMicroseconds(step_delay);
    }
    Serial.println("done 2000");
    commandcount = 2;
  }
  //********************************************************************* Homing **********************************************************

  if (home_count == 0)
  { while (!digitalRead(home_switch)) { // Do this until the switch is activated
      digitalWrite(dir_pin, HIGH);
      moveMotor();
    }
    Serial.println("Luuucie I'm Home Again ");//debugging
    home_count = 1 ;
  }



  //****************************************************************** back off homing switch ********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is not activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                      
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }
  //****************************************************************************************************************************************



}
void moveMotor() {
  if (stepsToGo > 0) {
    if (micros() - prevStepMicros >= stepIntervalMicros) {
      prevStepMicros += stepIntervalMicros;
      singleStep();
      stepsToGo --;
      if (stepsToGo <= numAccelSteps) {
        if (stepIntervalMicros < slowMicrosBetweenSteps) {
          stepIntervalMicros += stepAdjustmentMicros;
        }
      }
      else {
        if (stepIntervalMicros > fastMicrosBetweenSteps) {
          stepIntervalMicros -= stepAdjustmentMicros;
        }
      }
    }
  }

}

void singleStep() {

  digitalWrite(step_pin, HIGH);
  digitalWrite(step_pin, LOW);

}

I can't understand how you are thinking about the problem. Let's try for the basics.

In your setup() function you set stepsToGo = 32000 and then you call moveMotor() lots of times until the home_switch is triggered.

I presume (tell me if I am wrong) that you don't expect to need 32000 steps until the home_switch is triggered.

In the course of implementing the steps each time moveMotor() makes a step it will increase the speed (reduce the interval) until the maximum speed is reached and then it will keep stepping at that speed.

Then the home_switch is triggered and the calls to moveMotor() suddenly stop. Consequently the motor is asked to stop, possibly from a high speed, without decelerating. That could cause the motor to make some extra unwanted steps. But let's keep things simple and assume that it stops OK.

The next time you want to use moveMotor() somewhere else in your program you need to change the value of stepsToGo to something suitable and you need to set stepIntervalMicros to an appropriate value. If the motor is stopped then you need to set it to slowIntervalMicros so it can begin again at the slow speed.

If you want to make the motor slow to a stop then (assuming stepIntervalMicros is already at a value suitable for high speed) you need to set the value of stepsToGo to equal the number of steps over which you want the motor to slow down. In your code the acceleration (up and down) takes place over 200 steps (the value in numAccelSteps) but you can, of course, change that.

If you want the motor to accelerate from a stop and then keep going at full speed for a long time just make sure that the value in stepsToGo is always greater than the value in numAccelSteps.

And if you want to use acceleration then ALL stepper moves should be done using moveMotor() and NO steps should be taken with separate code like

      digitalWrite (step_pin, HIGH);
      delayMicroseconds(step_delay);
      digitalWrite (step_pin, LOW);
      delayMicroseconds(step_delay);

...R

Robin2:
In your setup() function you set stepsToGo = 32000 and then you call moveMotor() lots of times until the home_switch is triggered.

Yes that is what I need to do. And it is happening as expected.

Robin2:
I presume (tell me if I am wrong) that you don’t expect to need 32000 steps until the home_switch is triggered.

Correct, I do not need that many steps, but the number of steps required to make the home switch may vary each start up. I used an arbitrary large number.

Robin2:
In the course of implementing the steps each time moveMotor() makes a step it will increase the speed (reduce the interval) until the maximum speed is reached and then it will keep stepping at that speed.

Then the home_switch is triggered and the calls to moveMotor() suddenly stop. Consequently the motor is asked to stop, possibly from a high speed, without decelerating. That could cause the motor to make some extra unwanted steps. But let’s keep things simple and assume that it stops OK.

The next time you want to use moveMotor() somewhere else in your program you need to change the value of stepsToGo to something suitable and you need to set stepIntervalMicros to an appropriate value. If the motor is stopped then you need to set it to slowIntervalMicros so it can begin again at the slow speed.

In the attached code is my attempt to set the variables before calling the moveMotor() in the IF statement. The motor still behaved the same way.

I assumed you meant slowMicrosBetweenSteps and not slowIntervalMicros, if not please clarify.

Robin2:
And if you want to use acceleration then ALL stepper moves should be done using moveMotor() and NO steps should be taken with separate code like

      digitalWrite (step_pin, HIGH);

delayMicroseconds(step_delay);
      digitalWrite (step_pin, LOW);
      delayMicroseconds(step_delay);




...R

Can you please explain why this is, even for a short move? I don’t need the speed (therefor the acceleration) on short moves like backing off the home switch.

Thank you again Robin for your patience and effort you and others put into this forum.

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses micros() to manage timing to allow high step rates to be tested
// and illustrates a simple method for accleration and deceleration




#define rrdirection 3//switches the direction of the Rolling Ring (RR) Drive VIA pneumatic cylinder
#define ejector 4    //operates pneumatic cylinder that ejects the wire coil
#define step_pin 5    //Pin 5 connected to Steps pin on RR TB6600
#define dir_pin 6     //Pin 6 connected to RR Direction pin on TB6600 MOTOR DIRECTION HIGH = CCW AND LOW = CW WHEN VIEWED FROM THE SHAFT END
#define sendcommand 7 //led to indicate start command has been sent to the Shleuniger Wire Stripper (for debugging)
#define sleep_pin 8   //Pin 8 connected to RR SLEEP pin TB6600
#define home_switch 9 //Pin 9 connected to Home Switch (Inductive Prox)(will be changed to photo sensor)
#define rrphoto 10    //Pin 10 connected to Photosensor that detects RR location in the "winding zone"
#define home_led 12   //led output to indicate home sensor state (for debugging)

unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long slowMicrosBetweenSteps = 6000; // microseconds
unsigned long fastMicrosBetweenSteps = 750;
unsigned long stepIntervalMicros;
unsigned long stepAdjustmentMicros;
int numAccelSteps = 200; // 100 is a half turn of a 200 step motor
int numSteps = 32000;
int stepsToGo;

int home_count = 0;//used to break out of homing loop
int home_state = 0;//used to monitor state of home sensor
int home_lastval = 0;//records last value of home sensor
int commandcount = 0 ;//used to break out of send command loop
//int stepcount = 0;//not currently used
int rrphoto_count = 0;//used to break out of "Winding Zone"
int rrphoto_state = 0;//used to monitor the state of the photo sensor
int rrphoto_lastval = 0;//records the last value of the photo sensor
int step_count;
int step_delay = 1400;

void setup() {

  Serial.begin(115200);
  Serial.println("Starting Stepper Demo with acceleration");

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(sendcommand, OUTPUT);

  stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
  stepIntervalMicros = slowMicrosBetweenSteps;
  stepsToGo = numSteps;
  // digitalWrite(dir_pin, direction);//might not be beeded

  //********************************************************************* Homing (SETUP)**********************************************************
  digitalWrite(rrdirection, LOW);
  digitalWrite(ejector, LOW);
  Serial.println("Momma Im coming home... ");
  while (!digitalRead(home_switch)) { // Do this until the switch is not activated
    digitalWrite(dir_pin, HIGH);
    moveMotor();
  }

  delay(500);
  //****************************************************************** back off homing switch (slowly)********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                      
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }
  Serial.println("Luuucie I'm Home ");//debugging
  //****************************************************************************************************************************************
}
//******************************************************REQUEST A WIRE FROM STRIPPER (PULSE)******************************************
void loop() {

  if (commandcount == 0)  {
    Serial.println("Send Me A Wire ");//debugging
    digitalWrite (home_led, LOW);
    digitalWrite(sendcommand, HIGH);
    delay(3000);
    digitalWrite(sendcommand, LOW);
    commandcount = 1; // used to exit loop
  }
  //*****************************************************MOVE MOTOR TO THE WINDING ZONE****************************************************

  while (commandcount == 1)
  { for (; step_count <= 2000; step_count++)
    { digitalWrite (sleep_pin, HIGH);
      digitalWrite (home_led, LOW);
      digitalWrite (dir_pin, LOW);
      digitalWrite (step_pin, HIGH);
      delayMicroseconds(step_delay);
      digitalWrite (step_pin, LOW);
      delayMicroseconds(step_delay);
    }
    Serial.println("done 2000");
    commandcount = 2;
  }
  //********************************************************************* Homing **********************************************************

  if (home_count == 0)                        //HERE ARE THE CHANGES I MADE TO RESET THE VARIABLES.
  { stepsToGo = 32000;
    stepIntervalMicros = 6000;
    numAccelSteps = 200;
    fastMicrosBetweenSteps = 750;
    prevStepMicros = 0;
    stepIntervalMicros = slowMicrosBetweenSteps;
    Serial.println("Fingers Crossed.. ");//debugging
    while (!digitalRead(home_switch)) { // Do this until the switch is activated
      digitalWrite(dir_pin, HIGH);
      moveMotor();
    }
    Serial.println("Luuucie I'm Home Again ");//debugging
    home_count = 1 ;
  }



  //****************************************************************** back off homing switch ********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is not activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                       //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }
  //****************************************************************************************************************************************



}
void moveMotor() {
  if (stepsToGo > 0) {
    if (micros() - prevStepMicros >= stepIntervalMicros) {
      prevStepMicros += stepIntervalMicros;
      singleStep();
      stepsToGo --;
      if (stepsToGo <= numAccelSteps) {
        if (stepIntervalMicros < slowMicrosBetweenSteps) {
          stepIntervalMicros += stepAdjustmentMicros;
        }
      }
      else {
        if (stepIntervalMicros > fastMicrosBetweenSteps) {
          stepIntervalMicros -= stepAdjustmentMicros;
        }
      }
    }
  }

}

void singleStep() {

  digitalWrite(step_pin, HIGH);
  digitalWrite(step_pin, LOW);

}

ultratec:
I assumed you meant slowMicrosBetweenSteps and not slowIntervalMicros, if not please clarify.

You are correct - apologies for the confusion.

And if you want to use acceleration …

Can you please explain why this is, even for a short move? I don’t need the speed (therefor the acceleration) on short moves like backing off the home switch.

The answer is in the piece you quoted. If you don’t need acceleration you can do it any way you like. I did not know there were moves you wanted to make that do not need acceleration.

I reckon it would make your code easier to follow if you rename the function moveMotor() to stepMotorAccel() and then create another function called stepMotorConstSpeed() that does not use acceleration, Then, for example, this section of code

  while (commandcount == 1)
  { for (; step_count <= 2000; step_count++)
    { digitalWrite (sleep_pin, HIGH);
      digitalWrite (home_led, LOW);
      digitalWrite (dir_pin, LOW);
      digitalWrite (step_pin, HIGH);
      delayMicroseconds(step_delay);
      digitalWrite (step_pin, LOW);
      delayMicroseconds(step_delay);
    }
    Serial.println("done 2000");
    commandcount = 2;
  }

could become

    while (commandcount == 1)
  { for (; step_count <= 2000; step_count++)
    { 
        stepMotorConstantSpeed();
    }
    Serial.println("done 2000");
    commandcount = 2;
  }

…R

Thank you again for your response.

I have cleaned tidied up the code based on your recommendation. Thank you.

i am still unsure as to why the motor won’t slowly accelerate with the variables i have reset? can you provide some insight as to why that is or isnt happening?

Tidie

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses micros() to manage timing to allow high step rates to be tested
// and illustrates a simple method for acceleration and deceleration




#define rrdirection 3//switches the direction of the Rolling Ring (RR) Drive VIA pneumatic cylinder
#define ejector 4    //operates pneumatic cylinder that ejects the wire coil
#define step_pin 5    //Pin 5 connected to Steps pin on RR TB6600
#define dir_pin 6     //Pin 6 connected to RR Direction pin on TB6600 MOTOR DIRECTION HIGH = CCW AND LOW = CW WHEN VIEWED FROM THE SHAFT END
#define sendcommand 7 //led to indicate start command has been sent to the Shleuniger Wire Stripper (for debugging)
#define sleep_pin 8   //Pin 8 connected to RR SLEEP pin TB6600
#define home_switch 9 //Pin 9 connected to Home Switch (Inductive Prox)(will be changed to photo sensor)
#define rrphoto 10    //Pin 10 connected to Photosensor that detects RR location in the "winding zone"
#define home_led 12   //led output to indicate home sensor state (for debugging)

unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long slowMicrosBetweenSteps = 6000; // microseconds
unsigned long fastMicrosBetweenSteps = 750;
unsigned long stepIntervalMicros;
unsigned long stepAdjustmentMicros;
int numAccelSteps = 200; // 100 is a half turn of a 200 step motor
int numSteps = 32000;
int stepsToGo;

int home_count = 0;//used to break out of homing loop
int home_state = 0;//used to monitor state of home sensor
int home_lastval = 0;//records last value of home sensor
int commandcount = 0 ;//used to break out of send command loop
//int stepcount = 0;//not currently used
int rrphoto_count = 0;//used to break out of "Winding Zone"
int rrphoto_state = 0;//used to monitor the state of the photo sensor
int rrphoto_lastval = 0;//records the last value of the photo sensor
int step_count;
int step_delay = 1400;

void setup() {

  Serial.begin(115200);
  Serial.println("Starting Stepper Demo with acceleration");

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(sendcommand, OUTPUT);

  stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
  stepIntervalMicros = slowMicrosBetweenSteps;
  stepsToGo = numSteps;
  // digitalWrite(dir_pin, direction);//might not be beeded

  //********************************************************************* Homing (SETUP)**********************************************************
  digitalWrite(rrdirection, LOW);
  digitalWrite(ejector, LOW);
  Serial.println("Momma Im coming home... ");
  while (!digitalRead(home_switch)) { // Do this until the switch is not activated
    digitalWrite(dir_pin, HIGH);
    stepMotorAccel();
  }

  delay(500);
  //****************************************************************** back off homing switch (slowly)********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(2);                       //HOPING TO USE ACCELSTEPPER TO OPTIMIZE
    digitalWrite(step_pin, LOW);
    delayMicroseconds(1);
  }
  Serial.println("Luuucie I'm Home ");//debugging
  //****************************************************************************************************************************************
}
//******************************************************REQUEST A WIRE FROM STRIPPER (PULSE)******************************************
void loop() {

  if (commandcount == 0)  {
    Serial.println("Send Me A Wire ");//debugging
    digitalWrite (home_led, LOW);
    digitalWrite(sendcommand, HIGH);
    delay(3000);
    digitalWrite(sendcommand, LOW);
    commandcount = 1; // used to exit loop
  }
  //*****************************************************MOVE MOTOR TO THE WINDING ZONE****************************************************

  while (commandcount == 1)
  { for (; step_count <= 2000; step_count++)
    { digitalWrite (sleep_pin, HIGH);
      digitalWrite (home_led, LOW);
      digitalWrite (dir_pin, LOW);
      stepMotorConstSpeed();
    }
    Serial.println("done 2000");
    commandcount = 2;
  }
  //********************************************************************* Homing **********************************************************

  if (home_count == 0)                        //HERE ARE THE CHANGES I MADE TO RESET THE VARIABLES.
  { stepsToGo = 32000;
    stepIntervalMicros = 6000;
    numAccelSteps = 200;
    fastMicrosBetweenSteps = 750;
    prevStepMicros = 0;
    stepIntervalMicros = slowMicrosBetweenSteps;
    Serial.println("Fingers Crossed.. ");//debugging
    while (!digitalRead(home_switch)) { // Do this until the switch is activated
      digitalWrite(dir_pin, HIGH);
      stepMotorAccel();
    }
    Serial.println("Luuucie I'm Home Again ");//debugging
    home_count = 1 ;
  }



  //****************************************************************** back off homing switch ********************************************

  while (digitalRead(home_switch)) {  // Do this until the switch is not activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    stepMotorConstSpeed();
  }
  //****************************************************************************************************************************************



}
void stepMotorAccel() {
  if (stepsToGo > 0) {
    if (micros() - prevStepMicros >= stepIntervalMicros) {
      prevStepMicros += stepIntervalMicros;
      singleStep();
      stepsToGo --;
      if (stepsToGo <= numAccelSteps) {
        if (stepIntervalMicros < slowMicrosBetweenSteps) {
          stepIntervalMicros += stepAdjustmentMicros;
        }
      }
      else {
        if (stepIntervalMicros > fastMicrosBetweenSteps) {
          stepIntervalMicros -= stepAdjustmentMicros;
        }
      }
    }
  }

}

void singleStep() {

  digitalWrite(step_pin, HIGH);
  digitalWrite(step_pin, LOW);

}

void stepMotorConstSpeed() {
  digitalWrite (step_pin, HIGH);
  delayMicroseconds(step_delay);
  digitalWrite (step_pin, LOW);
  delayMicroseconds(step_delay);

}

d up code

Hello All

I am still trying to implement the code shared by @Robin2 in to my Wire Winder programming.

Here is a recap on my experiences:

My issue is that the first call for stepMotorAccel() accelerates and runs perfectly well to my home switch (proximity) and stops. (was not allowed to decelerate)

On my subsequent calls to stepMotorAccel() the motor sits and squeals until I give it a good spin and it then resumes.

I suspected the acceleration variables had changed and the motor is trying to start at “full speed” settings.

What I have done is to isolate the motor move portion from the rest of the program to better understand what is going on. At the end of the home switch move (no deceleration), I serial printed the variables that i think are required for the acceleration calculation to see what the values are.

I have a snap shot of the variable values commented out in the code.

I have also commented in the code what I think it is doing.

Can anyone explain why my “resetting” of the values isn’t having the expected result (which is for the motor to accelerate smoothly)

//I have noted this code in the way I think I understand its operation.

#define home_switch 9 //Pin 9 connected to Home Switch (Inductive Prox)(will be changed to photo sensor)
#define step_pin 5    //Pin 5 connected to Steps pin on RR TB6600
#define dir_pin 6     //Pin 6 connected to RR Direction pin on TB6600 MOTOR DIRECTION HIGH = CCW AND LOW = CW WHEN VIEWED FROM THE SHAFT END
unsigned long curMicros;//not used anywhere else in code
unsigned long prevStepMicros = 0;//duration of the last step
unsigned long slowMicrosBetweenSteps = 6000; // starting and stop duration between steps
unsigned long fastMicrosBetweenSteps = 750; //duration of steps at top speed
unsigned long stepIntervalMicros; //starts out the same value as slowMicroBetweenSteps
unsigned long stepAdjustmentMicros; // the value that provides acceleration for each step (6000-750)/200
int numAccelSteps = 200; // 100 is a half turn of a 200 step motor. This constant steps from stop to full speed and back down
int numSteps = 6000;  //number of steps of entire travel distance
int stepsToGo; //steps left to travel
int home_count = 0;//used to break out of homing loop


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Starting Stepper Demo with variable print");

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(home_switch, INPUT_PULLUP);

  stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
  stepIntervalMicros = slowMicrosBetweenSteps;
  stepsToGo = numSteps;
}

void loop() {


  if (home_count == 0)
  { Serial.println("Im coming home... ");
    { while (!digitalRead(home_switch)) // Do this until the switch is activated
      {
        digitalWrite(dir_pin, HIGH);
        stepMotorAccel();//this instance runs as expected
      }
      Serial.println("I'm Home ");//debugging
      Serial.print("Slow Micros:") ;
      Serial.println(slowMicrosBetweenSteps);
      Serial.print("Fast Micros:") ;
      Serial.println(fastMicrosBetweenSteps);
      Serial.print("Number of Accel Steps:") ;
      Serial.println(numAccelSteps);
      Serial.print("Previous Step Micros:") ;
      Serial.println(prevStepMicros);
      Serial.print("Step Interval Micros:") ;
      Serial.println(stepIntervalMicros);
      Serial.print("Step Adjustment Micros:") ;
      Serial.println(stepAdjustmentMicros);
      Serial.print("Steps To Go:") ;
      Serial.println(stepsToGo);


    }

    home_count = 1 ;
    Serial.print("Home Count:");
    Serial.println(home_count);
  }
  /* These values were printed to serial right after a home switch stop (no deceleration)
    Slow Micros:6000
    Fast Micros:750
    Number of Accel Steps:200
    Previous Step Micros:4716642
    Step Interval Micros:748
    Step Adjustment Micros:26
    Steps To Go:407*/

 // reset the variables
  prevStepMicros = 0;
  numSteps = 6000;
  stepsToGo = numSteps;
  if (home_count == 1)
  {
    Serial.println("");
    Serial.println("");
    Serial.print("Number of Steps:");
    Serial.println(numSteps);
    Serial.print("Previous Step Micros:") ;
    Serial.println(prevStepMicros);
    Serial.print("Steps To Go:") ;
    Serial.println(stepsToGo);
    home_count = 2;
  }
  /*These values were printed to serial right after declaring new values
    Number of Steps:6000
    Previous Step Micros:0
    Steps To Go:6000
  */
  if (home_count == 2)
  {
    digitalWrite(dir_pin, LOW);
    stepMotorAccel();//motor has a high sqeual and no movement
  }





}
void stepMotorAccel() {
  if (stepsToGo > 0) {
    if (micros() - prevStepMicros >= stepIntervalMicros) {
      prevStepMicros += stepIntervalMicros;
      singleStep();
      stepsToGo --;
      if (stepsToGo <= numAccelSteps) {
        if (stepIntervalMicros < slowMicrosBetweenSteps) {
          stepIntervalMicros += stepAdjustmentMicros;
        }
      }
      else {
        if (stepIntervalMicros > fastMicrosBetweenSteps) {
          stepIntervalMicros -= stepAdjustmentMicros;
        }
      }
    }
  }

}

void singleStep() {

  digitalWrite(step_pin, HIGH);
  digitalWrite(step_pin, LOW);

}

I seem to have missed your Reply #15 - apologies. I assume the code in reply #16 is the latest version.

Am I correct to think it is working up to the point where it gets to this code

 if (home_count == 2)
  {
    digitalWrite(dir_pin, LOW);
    stepMotorAccel();//motor has a high sqeual and no movement
  }

Is the motor stationary when that code is called?
What is the value of stepIntervalMicros before that code is called?
If the motor is stationary it should be the same as slowMicrosBetweenSteps

When you have a problem you print out all the relevant variables.

...R

Good Day!

Robin2 you are correct, the code works up until that point (the second call for stepMotorAccel())

1)the motor is stationary

2)stepIntervalMicros = 748 (close to the fastMicrosBetweenSteps at 750. I assume because the travel was interrupted at full speed and no decel was implemented)

I thought i had printed out all the variables were relevant (big chance im wrong :confused: )

Just a note, i modified the original stepMotorAccel (program you pointed me to) by deleting the reverse direction function.

micros() was in there and i don't know if that has a bearing on my problem.

Thank you for replying.

Mike

ultratec:
1)the motor is stationary

2)stepIntervalMicros = 748 (close to the fastMicrosBetweenSteps at 750. I assume because the travel was interrupted at full speed and no decel was implemented)

Then you need to change that to the slowMicros value before starting the move. Why would you think of accelerating from the fast speed?

...R