Question about brake code in vnh5019 source code

Hello,

I was reading the motor driver source code at github.com/pololu/dual-vnh5019- … Shield.cpp

and I noticed the code for brake:

void DualVNH5019MotorShield::setM1Brake(int brake)
{
  // normalize brake
  if (brake < 0)
  {
    brake = -brake;
  }
  if (brake > 400)  // Max brake
    brake = 400;
  digitalWrite(_INA1, LOW);
  digitalWrite(_INB1, LOW);
  #if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__)
  OCR1A = brake;
  #else
  analogWrite(_PWM1,brake * 51 / 80); // default to using analogWrite, mapping 400 to 255
  #endif
}

This code will put both INA and INB low, putting the motor to brake mode. But the code also applies a PWM - as given to the parameter to the function.

From what I know once both INA and INB is LOW, the PWM input would not matter.

I am wondering why this code is written this way? Are we applying a power function to the brakes? if we brake a motor with setM1Brake(350) would that be any different then setM1Brake(0) ?

Best regards,
C.

Hello.

Sending 0 to setM1Brake is different than sending 350. 0 corresponds to full coast, and 400 corresponds to full brake, which is mentioned in the README.textfile on the library’s GitHub page.

It might be helpful to look at the truth table under the “Using the Driver in Single-Channel Mode” section of the Pololu Dual VNH5019 Motor Driver Shield User’s Guide. If you set both IN pins to LOW and toggle PWM (between HIGH and LOW), it allows the motor driver to alternate between coast and brake.

- Amanda