I have a Pololu Dual VNH5019 Motor Driver Shield for Arduino and noticed M2 was not fully turning-off when setting setM2Speed(0).
I checked the DualVNH5019MotorShield lib and there appears to be an issue in the setM2Speed method. See below. I made the changes and am now geting the behavior I expect on M2.
Regards,
Aaron
// Set speed for motor 2, speed is a number betwenn -400 and 400
void DualVNH5019MotorShield::setM2Speed(int speed)
{
unsigned char reverse = 0;
if (speed < 0)
{
speed = -speed; // make speed a positive quantity
reverse = 1; // preserve the direction
}
if (speed > 400) // Max
speed = 400;
#if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
OCR1B = speed;
#else
analogWrite(_PWM2,speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
#endif
if (speed == 0)
{
//BUG HERE. Should not be controlling motor 1 from a method for motor 2.
//digitalWrite(_INA1,LOW); // Make the motor coast no
//digitalWrite(_INB1,LOW); // matter which direction it is spinning.
//Should be this:
digitalWrite(_INA2,LOW); // Make the motor coast no
digitalWrite(_INB2,LOW); // matter which direction it is spinning.
}
else if (reverse)
{
digitalWrite(_INA2,LOW);
digitalWrite(_INB2,HIGH);
}
else
{
digitalWrite(_INA2,HIGH);
digitalWrite(_INB2,LOW);
}
}