Is it possible to brake a DC motor with the Adafruit Motor Shield? I
gather the drivers in the original shield weren't up to it (according
to http://playground.arduino.cc/Main/AdafruitMotorShield). But what
about the v2 version of the shield?
Thanks
Braking a DC motor
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Braking a DC motor
There is no support for it built into the library. Braking has not been tested with the V2 shield.
-
- Posts: 5
- Joined: Thu Jun 05, 2014 6:32 pm
Re: Braking a DC motor
To brake a DC motor, just set the speed of both motors to zero:
lftMtr->setSpeed(0); rtMtr->setSpeed(0);
lftMtr->setSpeed(0); rtMtr->setSpeed(0);
-
- Posts: 5
- Joined: Thu Jun 05, 2014 6:32 pm
Re: Braking a DC motor
Forgot to mention that this works for the Adafruit Motor Shield version 2
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Braking a DC motor
Setting the speed to zero will cut power to the motor. That is not the same thing as braking. To brake a DC motor, you effectively create a short circuit through the H-bridge between the motor terminals. This can result in a large spike of current flowing through the bridge. If the bridge is not designed to handle braking in this way, damage can result.To brake a DC motor, just set the speed of both motors to zero:
-
- Posts: 5
- Joined: Thu Jun 05, 2014 6:32 pm
Re: Braking a DC motor
It might not technically be the same as braking, but setting the motors to zero speed makes my robot comes to a dead stop instead of coasting (which occurs if you use the RELEASE command–see code fragment below):
lftMtr->setSpeed(150); rtMtr->setSpeed(150);
lftMtr->run(FORWARD); rtMtr->run(FORWARD);
delay(3000);
lftMtr->setSpeed(0); rtMtr->setSpeed(0); // brake
// lftMtr->run(RELEASE); rtMtr->run(RELEASE); // coast
lftMtr->setSpeed(150); rtMtr->setSpeed(150);
lftMtr->run(FORWARD); rtMtr->run(FORWARD);
delay(3000);
lftMtr->setSpeed(0); rtMtr->setSpeed(0); // brake
// lftMtr->run(RELEASE); rtMtr->run(RELEASE); // coast
- Solar_Granulation
- Posts: 1
- Joined: Thu Jan 01, 2015 6:06 am
Re: Braking a DC motor
I realise it's been a few months but I think that this is with contributing. I hope nobody objects.
In the datasheet of the motor driver IC used in this shield the mode that roboteach describes is listed as "Short brake". It's probably not intended to prevent the motor from turning, due to the current spike mentioned by Bill, but can arrest motion under a light load. It's how speed is controlled.
In the same section of the datasheet a sperate Short brake mode is listed. Inputs 1 and 2 are set High, the PWM (speed) input may have any value. As Bill mentioned this has not been implemented in the shield library, but it would be a small hack to add it. A constant is defined, alongside FORWARD, BACKWARD, and RELEASE, for BRAKE mode but is not used in the run() switch block. If you decide to try it just add the following case statement.
Setting PWM to 0 is a precaution, probably unnecessary based on this from the datasheet:
DO NOT rely on electrical braking to resist outside force, be it momentum, gravity or a push. To provide breaking against these conditions you need a physical mechanism.
In the datasheet of the motor driver IC used in this shield the mode that roboteach describes is listed as "Short brake". It's probably not intended to prevent the motor from turning, due to the current spike mentioned by Bill, but can arrest motion under a light load. It's how speed is controlled.
In the same section of the datasheet a sperate Short brake mode is listed. Inputs 1 and 2 are set High, the PWM (speed) input may have any value. As Bill mentioned this has not been implemented in the shield library, but it would be a small hack to add it. A constant is defined, alongside FORWARD, BACKWARD, and RELEASE, for BRAKE mode but is not used in the run() switch block. If you decide to try it just add the following case statement.
Code: Select all
// I have not tested this code. It is provided as is, USE AT YOUR OWN RISK.
case BRAKE:
MC->setPWM(PWMpin, 0); // Probably not necessary but a good precaution
MC->setPin(IN1pin, HIGH);
MC->setPin(IN2pin, HIGH);
break;
This has the same result as roboteach's example, but allows greater flexibility in your sketch. With this method you can set speed while maintaining electrical braking.To prevent penetrating current, dead time … is provided in switching to each mode in the IC.
DO NOT rely on electrical braking to resist outside force, be it momentum, gravity or a push. To provide breaking against these conditions you need a physical mechanism.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Braking a DC motor
Good information.. thanks for posting! ;-)
- project_zero
- Posts: 86
- Joined: Tue Sep 10, 2013 11:22 pm
Re: Braking a DC motor
My apologies for bringing an old topic, but it seemed to make more sense than starting a new one.
Has anybody tested Solar Granulation's code for electrical braking? I need my motors to move to a certain orientation and then brake - as I need them to not be backdriven.
Has anybody tested Solar Granulation's code for electrical braking? I need my motors to move to a certain orientation and then brake - as I need them to not be backdriven.
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Braking a DC motor
I have not tested it. But electrical braking alone is not enough to stop a DC motor from being back-driven. The nature of electrical braking dictates that the braking force will be proportional to the speed. So, when the speed goes to zero - there is no more braking. If you have a fairly high-reduction gear-motor, there might be enough drivetrain friction to hold things. But you might be better off considering something like a stepper motor.
https://learn.adafruit.com/adafruit-mot ... -of-motors
https://learn.adafruit.com/adafruit-mot ... -of-motors
- project_zero
- Posts: 86
- Joined: Tue Sep 10, 2013 11:22 pm
Re: Braking a DC motor
Ah, I see. I was thinking that electrical braking could help hold a motor in place, but if I recall, dynamic braking is when current generated by the back EMF causes current to flow in a loop that resists the rotation of the motor. No speed, no back EMF, no braking. This is what you meant by electrical braking being proportional to the speed, yes?
I may consider stepper motors. Its true that moving them to a certain position and holding that position is much more suited to steppers, but I've found they're usually pretty weak and it's easy to overcome their coil-powered "hold" position by hand. Maybe I've been using the wrong steppers?
I may consider stepper motors. Its true that moving them to a certain position and holding that position is much more suited to steppers, but I've found they're usually pretty weak and it's easy to overcome their coil-powered "hold" position by hand. Maybe I've been using the wrong steppers?
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Braking a DC motor
That is correct. We are talking about a form of dynamic braking. The only other type of 'electrical' braking you could apply on a DC motor would be some electrically actuated friction brake.
Stepper holding torque (at least with simple drivers such as the shield) is generally stronger than the turning torque - unless you explicitly reduce the holding current. You can increase both by using a geared stepper.
Stepper holding torque (at least with simple drivers such as the shield) is generally stronger than the turning torque - unless you explicitly reduce the holding current. You can increase both by using a geared stepper.
- project_zero
- Posts: 86
- Joined: Tue Sep 10, 2013 11:22 pm
Re: Braking a DC motor
Thanks Bill. Another question about the motorshield -
I misplaced the power jumper. I want to run both the arduino and the robot from a DC power jack. Is it enough for me to connect those two pins together, say with a f/f jumper wire? I'm assuming that's what the power jumper does.
I misplaced the power jumper. I want to run both the arduino and the robot from a DC power jack. Is it enough for me to connect those two pins together, say with a f/f jumper wire? I'm assuming that's what the power jumper does.
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Braking a DC motor
Yes. A F/F jumper wire will work.
Please be positive and constructive with your questions and comments.