Need a diferent aproach on programing a closed loop stepper motor as a lathe spindle

I recently purchased a closed loop stepper motor rated at 12.5nm torque that came as a set with a driver and i wrote a pulsing program and mapped some buttons with arduino.
The program and the buttons work as i intend them to with my motor reaching 1360 rpm but the motor has no torque (i can hold the attachment i have on the motor shaft with my hands and it stalls) if i go over 600 rpm.
i would really appreciate some suggestions and help in taking a different programing approach as i am pretty new to all this, my goal is to reach 1000 to 1300 rpm and keep a high torque.

Below is my code and specks the motor is a nema 34 model 86H250165-156B my driver is HBS860H tuned at 200 microsteps and i am supplying 54v dc 10 a


const int stepPin = 7;
const int dirPin = 6;
const int potPin = A0;
int reverseSwitch = 2;  // Push button for reverse
int currentSpeed = 0;
int targetSpeed = 0;
int maxSpeed = 1450;
int minSpeed = 150;
const int powerUpDelay = 9000; // 3 second delay on power up
const int startSpeed = 0; // initial speed on power up
bool setdir = LOW;

int buttonState = HIGH;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 5;

void setup() {
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(reverseSwitch, INPUT_PULLUP);
}

void loop() {
  // Read current state of button and debounce it
  int reading = digitalRead(reverseSwitch);
  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading == LOW && buttonState == HIGH) {
      // Toggle direction of motor
      setdir = !setdir;
    }
    buttonState = reading;
  }
  lastButtonState = reading;

  targetSpeed = map(analogRead(potPin), 1, 1023, minSpeed, maxSpeed);

  // Gradually increase or decrease speed towards target speed
  if (currentSpeed < targetSpeed) {
    currentSpeed += 10;
  } else if (currentSpeed > targetSpeed) {
    currentSpeed -= 10;
  }

  // Set direction based on setdir variable
  digitalWrite(dirPin, setdir);

  // Step motor and delay based on current speed
  for (int i = 0; i < 70; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000000 / (currentSpeed * 22));
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000000 / (currentSpeed * 22));
  }
}

  • not sure why you describe this as a "closed loop"? don't see a measurement of the actual speed

  • why only 70 steps / iteration? why not use a timer to control the step rate

  • i thought micro-stepping was intended to precision positioning. is it needed for speed control

  • not sure of the purpose for adjusting the current speed? adjustment rate depends on currentSpeed

  • why is there a need to change the direction of a lath spindle?

  • button code can be simpler

  • should there be an "Off" button?

Torque is ALWAYS a function of current. So your motor power supply is limiting the current to the motor. It does that by reducing the voltage. Measure the motor voltage while in operation and holding motor shaft.

This is the closed-loop stepper-motor

The stepper-driver does already "close the loop" you just give the stepper-driver the new position and the driver will drive the motor to the new position.
Such closed-loop-systems can be adjusted in many ways.

12.5 Nm is a high torque. Really high torque. I'm using 3 Nm open-loop steppermotors on my CNC-mill. I will rather broke a 8mm shaft-cutter than loosing steps on X-,Y- or Z-axle.

Did you read in the manual of the servodriver about all the adjustements that can be made?

best regards Stefan

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