setBrake function on Dual VNH5019 causing current overdraw

Hello,

I am building a robot that has a Lynxmotion Aluminum 4WD1 Rover Kit for the base. It has 4 brushed 12VDC motors. I am using the Pololu Dual VNH5019 motor driver board and the associated Arduino library. I am using a Arduino Mega for controller. The motors are wired so that the 2 on left are hooked to M1 and the 2 on right are hooked to M2. Demo code seems to work fine. Problem arrises when the motors are moving using the setSpeeds() or setMxSpeed() functions and i call setBrake(). When setBrake is called, the over current protection on my power supply trips (7.5A). Currently the only way have been able to stop motors is to call setSpeeds(0, 0) and coast to a stop. Any ideas on what i am missing? I have seen plenty of code examples online of people calling setSpeeds(100, 100) right after setBrakes(0, 0). I am using speed of 400, too fast?

Any help would be greatly appreciated.

Hello.

I am confused about your problem description. The first part of your post makes it sound like the problem occurs when you call setBrake() while the motors are driving, but this line:

makes it sound like the problem occurs when you try to drive the motors after braking. Can you clarify which scenario is causing the problem and post the simplest program that demonstrates it (along with a description of exactly what happens when the program is running)? Also, what is the stall current of your motors at 12 V?

- Ben

Ben,

Sorry for the typo. I called myself editing that but doesnt seem to have taken. Problem occurs when motor are turning and the setBrakes function is called. Simple example of code would be:

wheels.setSpeeds(400, 400);
delay(3000);
wheels.setBrakes(0, 0);

setBrakes causes no problem if motors arent turning. Motor specs can be found here:

lynxmotion.com/images/data/ghm01.pdf

I am not running them at full power right now, only 8VDC. The chassis is also up on blocks so that the wheels are just free spinning in air. A code example that doesnt use setBrake that works fine would be:

#include "DualVNH5019MotorShield.h"

DualVNH5019MotorShield wheels;

void stopIfFault()
{
  if (wheels.getM1Fault())
  {
    Serial.println("M1 fault");
    while(1);
  }
  if (wheels.getM2Fault())
  {
    Serial.println("M2 fault");
    while(1);
  }
}

void setup()
{
  Serial.begin(9600);
  Serial.println("Dual VNH5019 Motor Shield");
  wheels.init();
}

void loop()
{
  for (int i = 0; i <= 400; i++)
  {
    wheels.setSpeeds(i, i);

    stopIfFault();
    if (i%200 == 100)
    {
      Serial.print("M1 current: ");
      Serial.println(wheels.getM1CurrentMilliamps());
	  Serial.print("M2 current: ");
      Serial.println(wheels.getM2CurrentMilliamps());
    }

    delay(2);
  }
  
  for (int i = 400; i >= -400; i--)
  {
    wheels.setSpeeds(i, i);
    
    stopIfFault();
    if (i%200 == 100)
    {
      Serial.print("M1 current: ");
      Serial.println(wheels.getM1CurrentMilliamps());
	  Serial.print("M2 current: ");
      Serial.println(wheels.getM2CurrentMilliamps());
    }

    delay(2);
  }
  
  for (int i = -400; i <= 0; i++)
  {
    wheels.setSpeeds(i, i);

    stopIfFault();
    if (i%200 == 100)
    {
      Serial.print("M1 current: ");
      Serial.println(wheels.getM1CurrentMilliamps());
	  Serial.print("M2 current: ");
      Serial.println(wheels.getM2CurrentMilliamps());
    }

    delay(2);
  }
}

Ramping the speed all the way up and back down and back up…seems to work fine with no problems. Current never exceeds 300mA per side (2motors)

The code examples you provided aren’t so helpful since the first one is only a fragment and the second one doesn’t produce the problem. For example, if that snippet inside of the Arduino loop() function, then you effectively are calling setMotors() right after setBrakes(), and it’s hard to know which one is causing the current spike.

Do you get a current spike when you run the following program?

void setup()
{
  int i;
  for (i = 1; i < 400; i++)
  {
    setMotors(i, i);
    delay(1);
  }
  delay(1000);
  setBrakes(400, 400);
}

void loop()
{ }

Also, when you post code, please surround it in [ code ] [ /code ] tags (without the spaces) so that it displays nicely.

- Ben

Ben,
Your code works. I tested it a couple of times. Seems the problem is if i use a brake value lower than full brake (400) then i get the current spike. This is a non-issue since more than likely a hard stop would be preferred if not i will just lower speed to (0) cause a coast. Thank you for your help resolving this matter