Changing microstepping with FlexyStepper library

I am using a library, FlexyStepper to help control my stepper motors. In order to Increase resolution and reduce vibration, I am aiming to microstep at lower speeds and when coming to a stop. As speed increases, I transition to full steps to reach higher speeds. When I use the FlexyStepper, I change my microstepping but when I change the steps per mm to match the stepping resolution, it also scales the speed with it. For example, in the following code, it goes increments normally from 0-5mm/s, then jumps to 20mm/s upon transitioning from 1/16 to 1/4 step, then after 1 step it transitions again from quarter to full step at 80mm\s.

I tried to adjust set the speed before and after updating the steps per mm with no difference in results. How would I have a smooth acceleration while changing microsteps?

while(!stepper[i].motionComplete() ) {
    if(stepper[i].getCurrentVelocityInMillimetersPerSecond() > 20 ){
      digitalWrite(MSPins[i][0], LOW);  // Full step
      digitalWrite(MSPins[i][1], LOW); 
      digitalWrite(MSPins[i][2], HIGH);
      stepper[i].setStepsPerMillimeter(15.75);
            stepper[i].setSpeedInMillimetersPerSecond(85);

      Serial.println("FULL");
    }
    else if(stepper[i].getCurrentVelocityInMillimetersPerSecond() < 5){
      digitalWrite(MSPins[i][0], HIGH); // 1/16 step
      digitalWrite(MSPins[i][1], HIGH); 
      digitalWrite(MSPins[i][2], LOW);
      // If setspeed is called after the steps are scaled, the speed is scaled and then it has to deccelerate to the set speed
      stepper[i].setStepsPerMillimeter(15.75*16);  // Scale for microstep
            stepper[i].setSpeedInMillimetersPerSecond(85/16); // change speed so its scaled when steps/mm is changed

      Serial.println("SIXTEENTH");
    }
    else if(stepper[i].getCurrentVelocityInMillimetersPerSecond() < 20){
      digitalWrite(MSPins[i][0], LOW);  // 1/4 step
      digitalWrite(MSPins[i][1], HIGH); 
      digitalWrite(MSPins[i][2], HIGH);
      stepper[i].setStepsPerMillimeter(15.75*4);  // Scale for microstep
            stepper[i].setSpeedInMillimetersPerSecond(85/4);

      Serial.println("QUARTER");
    }
    
    // Step
    stepper[i].processMovement();
    Serial.println(stepper[i].getCurrentVelocityInMillimetersPerSecond());
  } 

  delay(1000);
  stepper[i].setTargetPositionInMillimeters(50);

Have you got the solution? I have also the same problem, Let me know as well.

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