Hey all,
I am having a curious problem and hoping to get some advice here. I am running 2 Stepper Driver A4983s with an Arduino. Currently, the drivers are powered by their onboard voltage regulators, however I am sharing a common ground between the drivers and the Arduino. I also have the EN, STEP and DIR pins wired up to my digital pins 4, 5, 6 and 7, 8, 9.
I have quite a bit of code running but I will post the chunks which actually pertain to driving the two motor drivers.
/*
* Set up motor motion and control
*/
void executeG00(){
setDirection(DIRM1, rotationM1);
setDirection(DIRM2, rotationM2);
moveMotors(stepCountM1,stepCountM2);
}
/*
* moveMotors()
* inputs - steps
* outputs - none
* function - rotates stepper motors
*/
void moveMotors(unsigned int stepsM1, unsigned int stepsM2){
unsigned int x = stepsM1;
unsigned int y = stepsM2;
time1 = micros();
time2 = micros();
while(moving){
if(micros()>=time1+10000 && x>0){
time1 = micros();
digitalWrite(STEPM1, HIGH);
digitalWrite(STEPM1, LOW);
x--;
}
if(micros()>=time2+10000 && y>0){
time2 = micros();
digitalWrite(STEPM2, HIGH);
digitalWrite(STEPM2, LOW);
y--;
}
if(x<=0 && y<=0) moving = false;
}
}
/*
* setDirection()
* inputs - motor number, direction
* outputs - none
* function - sets rotation direction of motor
*/
void setDirection(int motor, boolean dir){
digitalWrite(motor, dir);
}
So, on to my problem. When I pass the stepCount variables on to my moveMotors function, all executes with no problems and the motors move the correct number of steps. However, when I submit my next set of values, which involves switching the direction of the second motor, the driver just doesnt seem to listen and only changes direction, halfway through my moveMotors function.
for example:
command: both motors CCW and 1000 steps.
result: both motors CCW and 1000 steps.
2nd command: both motors CW and 1000 steps
2nd result: one motor moves CW 1000 steps, second motor moves CCW 600 steps and CW 400 steps.
This whole wacky scenario does not occur if I have a volt meter attached to my DIR pin. This tells me that when the Arduino switches the pin to ground, the voltage present at that pin does not seem to dissipate until 3-4 whole seconds later.
So my question is. In the product diagrams and the 4983 data sheet, it is shown to connect the DIR, STEP and EN pins directly to the micro, but in reality is this the proper way to wire this up? And what exactly is the current draw on these pins? Any insight would be appreciated.