My shield works fine for about 10 minutes, then stops responding to commands.
The issue seems to arise immediately after switching from forward to reverse.
The program continues to run and my debug shows it is sending the motor control commands.
But the shield is not executing them.
It doesn't happen every time. But once it does the shield will not execute any new commands.
I suspect the instantaneous switch in polarity is causing some kind of back emf that knocks out the shield communication.
To reestablish motor control, I have to remove all power to the system and then restart.
I have already checked all the solder joints.
Because the motors are reversable I can't use diodes.
I think I remember something about soldering capacitors on the motors. Would this help resolve the issue.
Alternatively, do I need to issue a stop motors / delay / restart in reverse.
Here is the snippet of code that seems to initiate the issue (there are equivilant ones for "turn right" and for "reverse")
Code: Select all
case 'a'://Turn Left
neopixel(150,0,150);
leftspeed = 150;
rightspeed = 150;
mtr_4_dir = "BACKWARD";
mtr_3_dir = "FORWARD";
motor4->run(BACKWARD);
motor3->run(FORWARD);
motor_ctrl ();
targetHeading = targetHeading - 90;
if (targetHeading < 0)
{ targetHeading = targetHeading + 360; }
readCompass();
while(errDir > 5 )
{ readCompass();
chkClient();
delay(300); //needed for read errors??
}
// reset to forward
mtr_3_dir = "FORWARD";
mtr_4_dir = "FORWARD";
motor3->run(FORWARD);
motor4->run(FORWARD);
neopixel(0,150,150);
break;
return;
} // end of switch case
// update controls with command received
motor_ctrl ();
setServo(panservo, angle);
//**** Motor control subroutine ****
void motor_ctrl()
{
motor4->setSpeed(leftspeed);
motor3->setSpeed(rightspeed);
//*
Serial.print(" Left: ");
Serial.print(leftspeed);
Serial.print(" Right: ");
Serial.println(rightspeed);
//*/
} // end of motor control ************************************/
Any suggestions?