Hi all,
SUMMARY:
I want to drive two A4988 stepper drivers with my arduino, however I have the problem that one of the motors is not stepping correctly, when using the EN pin to frequently turn on/off the motors.
SOFTWARE:
//Simple stepper driver class
class Stepperdriver
{
int stepPin;
int directionPin;
int enablePin;
public:
Stepperdriver(int step, int dir, int en)
{
//assign selected pins
stepPin = step;
directionPin = dir;
enablePin = en;
//disable stepper right at the start
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
pinMode(stepPin, OUTPUT);
pinMode(directionPin, OUTPUT);
digitalWrite(stepPin, LOW);
digitalWrite(directionPin, LOW);
}
void Rotate(int steps, int direction)
{
//enable stepper driver
digitalWrite(enablePin, LOW);
//set turn direction
digitalWrite(directionPin, direction);
delay(20);
for(int i = 0; i < steps; i++)
{
//pulse is long enough for stepper driver
digitalWrite(stepPin, HIGH);
delayMicroseconds(200);
digitalWrite(stepPin, LOW);
delayMicroseconds(200);
//controls turning speed
delay(5);
}
//disable stepper driver
digitalWrite(enablePin, HIGH);
}
};
This is my simple stepper driver class.
//Stepper
const int Sdir1 = A0;
const int Sstep1= A1;
const int SEN1 = A2;
const int Sdir2 = A3;
const int Sstep2= A4;
const int SEN2 = A5;
Stepperdriver stepper1(Sstep1, Sdir1, SEN1);
Stepperdriver stepper2(Sstep2, Sdir2, SEN2);
void setup() {
}
void loop() {
stepper1.Rotate(100,1);
delay(1000);
stepper2.Rotate(100,0);
delay(1000);
This is my sketch.
HARDWARE:
- Both steppers turn, they are of the Nema 8 type. Current is limited to 200mA per motor (of 600mA max for these types). Motor power supply is a bench top PSU, nur running into the current limit.
- Driving this is an Arduino MKR WiFi 1010, powerd via USB, only runnning the stepper class (see above).
- RST and SLP are connected to each other. A4988 logic power comes from the arduinos VCC (+3.3V).
- MS1-3 are not connected → full step mode
- EN/dir/step are connected to arduinos A0-A5 for the two drivers.
PROBLEM:
- In my code I am enabling the a4988 No.1, waiting 20ms, stepping 100 steps (half turn) and again disabling the driver. Then doing the same for driver No.2. The problem is now that one of the drivers will loose a few steps on every move, like a small jitter at the beginning of the movement. This is not chip-related, I switched them and the problem was with the same stepper, however it varies, sometimes stepper2 will misstep, sometimes stepper1. The other one will run perfect… I have no idea what could cause this…
P.s. I have scoped the step-signal from the arduino, and the pulses seem well-shaped and evenly spaced… no obvious malformations… (pretty square wave…)