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.