I have ordered two Dual VNH2SP30 motor controllers from two different suppliers. Both of them seem to show the same issue whether used as a shield on an Uno or via a nano with jumper leads.
Each controller has two drivers and two outputs. One motor driver will work very well turning a motor at full speed, then half speed clockwise then alternate and do the same counter clockwise at half and full speed. The issue appears to be with the second driver - it will only turn clockwise but won’t go counter clockwise, the direction LED just flickers a faint red - with or without motors connected.
I’m using a 2C lipo and separate supply for the arduinos which have a common ground in each configuration.
I would really appreciate some advice as I am close to binning both of these chips and searching out a different chip altogether. The motors I am using are 1) a test motor which draws 500mA @ 6V and 2) a pair of Dagu Wild Thumper motors connected in parallel.
Code sample:
[code]
#define CW 0 // Clockwise motor direction
#define CCW 1 // Clockwise motor direction
#define BREAK_GND 2 // Break motor to GND
#define BREAK_VCC 3 // Break motor to GND
#define MOTOR1 0 // Used to select motor output 1 (A1-B1)
#define MOTOR2 1 // Used to select motor output 2 (A2-B2)
#define INA1 7 // DIO pin used for motor A1 control
#define INB1 8 // DIO pin used for motor B1 control
#define INA2 4 // DIO pin used for motor A2 control
#define INB2 9 // DIO pin used for motor B2 control
#define PWM1 5 // DIO pin used for motor 1 PWM speed control
#define PWM2 6 // DIO pin used for motor 1 PWM speed control
void setup()
{
/* Set control pins to outputs */
pinMode(INA1, OUTPUT); // Motor 1 control A
pinMode(INB1, OUTPUT); // Motor 1 control B
pinMode(INA2, OUTPUT); // Motor 2 control A
pinMode(INB2, OUTPUT); // Motor 2 control B
pinMode(PWM1, OUTPUT); // Motor 1 PWM speed control
pinMode(PWM2, OUTPUT); // Motor 2 PWM speed control
/* Set both motor outputs to stop */
MotorState(MOTOR1, BREAK_GND);
MotorState(MOTOR2, BREAK_GND);
}
/* Main program */
void loop()
{
MotorState(MOTOR1, CW); // Set motor to clockwise direction
MotorSpeed(MOTOR1, 128); // Set motor 1 to half speed
delay(500);
MotorSpeed(MOTOR1, 255); // Set motor 1 to full speed
delay(500);
MotorSpeed(MOTOR1, 128); // Set motor 1 to half speed
delay(500);
MotorState(MOTOR1, BREAK_GND); // Stop the motor
delay(500);
MotorState(MOTOR1, CCW); // Set motor to counter clockwise direction
MotorSpeed(MOTOR1, 128); // Set motor 1 to half speed
delay(500);
MotorSpeed(MOTOR1, 255); // Set motor 1 to full speed
delay(500);
MotorSpeed(MOTOR1, 128); // Set motor 1 to half speed
delay(500);
MotorState(MOTOR1, BREAK_GND); // Stop the motor
delay(500);
MotorState(MOTOR2, CW); // Set motor to clockwise direction
MotorSpeed(MOTOR2, 128); // Set motor 1 to half speed
delay(500);
MotorSpeed(MOTOR2, 255); // Set motor 1 to full speed
delay(500);
MotorSpeed(MOTOR2, 128); // Set motor 1 to half speed
delay(500);
MotorState(MOTOR2, BREAK_GND); // Stop the motor
delay(500);
MotorState(MOTOR2, CCW); // Set motor to counter clockwise direction
MotorSpeed(MOTOR2, 128); // Set motor 1 to half speed
delay(500);
MotorSpeed(MOTOR2, 255); // Set motor 1 to full speed
delay(500);
MotorSpeed(MOTOR2, 128); // Set motor 1 to half speed
delay(500);
MotorState(MOTOR2, BREAK_GND); // Stop the motor
delay(500);
}
/* Sets the state of one of the motors where Motor is either
MOTOR1 or MOTOR2 and State is one of 4 options:
CW = Motor turns in clockwise direction
CCW = Motor turns in counter clockwise direction
BREAK_GND = Breaks the motor to GND
BREAK_VCC = Breaks the motor to VCC */
void MotorState(byte Motor, byte State)
{
switch(State)
{
case CW:
digitalWrite(Motor ? INA2 : INA1, HIGH);
digitalWrite(Motor ? INB2 : INB1, LOW);
break;
case CCW:
digitalWrite(Motor ? INA2 : INA1, LOW);
digitalWrite(Motor ? INB2 : INB1, HIGH);
break;
case BREAK_GND:
digitalWrite(Motor ? INA2 : INA1, LOW);
digitalWrite(Motor ? INB2 : INB1, LOW);
break;
case BREAK_VCC:
digitalWrite(Motor ? INA2 : INA1, HIGH);
digitalWrite(Motor ? INB2 : INB1, HIGH);
break;
}
}
/* Sets the motor speed where Motor is either MOTOR1 or MOTOR2
and Speed is a number between 0 and 255 where 0 = stopped
and 255 = full speed. */
void MotorSpeed(byte Motor, byte Speed)
{
if (Motor)
{
analogWrite(PWM2, Speed);
}else
{
analogWrite(PWM1, Speed);
}
}[/code]