Hello friends,
I have recently run into an issue where my stepper motor starts skipping and sort of jumping between steps when at low speeds (presumably at higher speeds as well but it's not visible) with microstepping enabled. This just seems incredibly odd to me and I honestly can't explain it. Full, half, and 1/4 steps work just fine even at low speeds. But whenever I go to 1/8 steps microstepping or smaller it starts making weird noises and stopping at times to then proceed to make a jump. (I'll try to get a video showing this properly ASAP). This all occurs both with the stepper in the assembly (actually moving things) and when it is on it's own.
The components I am using are:
- Arduino Uno
- DRV8825 (Google it I am sadly limited to just two links)
- 42BYGH47-401A Nema 17 Stepper Motor
- Arduino CNC Shield
- 12V 12.5A Power supply
I measured and set the Vref of the driver at a bit under 0.75V since the maximum current of the motor is 1.5A.
Although I don't believe the code to be the issue here it is, I copied it off someone else on the forum. Looking at it myself I can't see this being the issue but I wouldn't know. This is the code I am using right now, I modified it to run at different speeds when pressing the end switches so I could test at what speed it happens:
byte directionPin = 6;
byte stepPin = 3;
unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long slowMicrosBetweenSteps = 312; // microseconds
unsigned long fastMicrosBetweenSteps = slowMicrosBetweenSteps;
unsigned long stepIntervalMicros;
unsigned long stepAdjustmentMicros;
int numAccelSteps = 100; // 100 is a half turn of a 200 step mmotor
long numSteps = 1000000000;
long stepsToGo;
byte direction = 1;
long speeds[] = {500000, 50000, 5000, 2500, 1250, 625, 312, 156, 78, 39};
int index = 0;
void setup() {
Serial.begin(115200);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
//stepIntervalMicros = slowMicrosBetweenSteps;
stepIntervalMicros = speeds[index];
stepsToGo = numSteps;
digitalWrite(directionPin, direction);
}
void loop() {
moveMotor();
}
void moveMotor() {
stepIntervalMicros = speeds[index];
if (stepsToGo > 0) {
if (micros() - prevStepMicros >= stepIntervalMicros) {
prevStepMicros += stepIntervalMicros;
singleStep();
stepsToGo --;
}
}
else {
direction = ! direction;
digitalWrite(directionPin, direction);
// next two lines just for the demo
delay(2000);
Serial.println("Changing direction");
stepsToGo = numSteps;
prevStepMicros = micros();
}
if(digitalRead(9)) {
if(index < (sizeof(speeds)/sizeof(speeds[0]))) {
index++;
Serial.print("Now running at ");
Serial.print(speeds[index]);
Serial.println(" micros between steps");
} else {
digitalWrite(8, HIGH);
}
while(digitalRead(9)) delay(10);
}
if(digitalRead(10)) {
digitalWrite(8, HIGH);
}
}
void singleStep() {
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);
}
I would link to where I found this specific code but I can't seem to find it anymore.
I want to believe I somewhat understand how stepper motors work and I just can't explain what is happening here. I suspect it's me being stupid.
What I already checked:
- Wiring (extensively and by other people)
- Programming (I tried everything on the internet I could find that mentioned stepper motors and microstepping)
- CNC shield, this shouldn't be the issue since I have had the issues since before I bought it. I bought it to fix this issue actually because I thought it was down to my bad soldering skills at first.
I suspect it to be an issue related to the power supply or the components just not being compatible for my purpose.
Let me know please if you need more information, I'll try to get a clear video of it as soon as I get home from work.
Thanks in advance, I really hope this is fixable with the hardware I have available.
EDIT: video of what happens at the moment when I enable microstepping above 1/8 steps:
I can't send the link due to the link limit, I posted it in the comments below.