I'm using a repurposed MKS Gen L V1.0 board (arduino MEGA + RAMPS, basically) to control a pair of IR sensors and a NEMA 23 stepper with TB6600 driver.
The application is simple: raise and lower the end of a roller. Wait for a signal from the sensors, wait for a time to see if the issue fixes itself and if it doesn't, turn 300 revolutions CW to raise, CCW to lower; wait; if we still have an issue, turn 150; issue fixed, return to zero.
It all works the way I want it to, except for the speed and direction of the stepper. NOTE: this is with the motor not attached to anything. NO LOAD.
To test, I've loaded a very simple script:
// speed tests
for (int a = 650; a <= 1200; a += 50) {
Serial.println(a)
// do the thing a few times (for this test, once)
for (int y = 0; y <= 1; y++) {
// turn one revolution
for (int x = 0; x <= 200; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(a);
digitalWrite(stepPin, LOW);
delayMicroseconds(a);
}
}
delay(1000);
}
exit(0);
Any delayMicroseconds value below 650 or above 1200, the motor jitters or vibrates but doesn't turn. When it does spin, the motor changes direction between spins, and as we get near the top of bottom of the range, it'll even change direction mid-spin.
The driver is set to 200p/rev and 1.5a. (I played with microstepping and higher amperage, but it didn't make an appreciable difference.)
Before you enthusiastically recommend a library, I've worked with both AccelStepper and Stepper (the default Arduino library?), and neither were as reliable or predictable as the code above.
I would like to be able to use AccelStepper, but the ac/de-celeration ramps have the same symptoms as my simpler code: between 650 and 1150μs, everything's fine, anywhere outside that range is not.
What don't I know? What am I missing to be able to turn slower and/or faster than that narrow range? Why does it change direction mid-spin or between spins?