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));
}
}