I have a breakout board like this one in the picture.
I can control the output voltage with my PWM signals from the Arduino okay.
What I can't work out how to do is control the fast stop and free running stop functionality. I have read the data sheet (also attached) and can see on page six, figure 6 that this can be controlled but I can't match the data sheet for the L298 to the breakout board. I'm sure it's straight forward but as usual the brain is fading...
I've not used that exact board boards but similar ones. On the board I use there is are jumpers for enabling the drive labelled ENA and ENB. From reading the data sheets with these jumpers in it will fast stop when both inputs are the same. With the jumper removed it free running stop. Not very useful for driving it as removing the jumper will stop all control. Could you replace the enable jumper with another lead from the Arduino and enable/disable it within the code, ie enable for running and fast stop, disable for free running stop? Not tried this!
nickjb:
I've not used that exact board boards but similar ones. On the board I use there is are jumpers for enabling the drive labelled ENA and ENB. From reading the data sheets with these jumpers in it will fast stop when both inputs are the same. With the jumper removed it free running stop. Not very useful for driving it as removing the jumper will stop all control. Could you replace the enable jumper with another lead from the Arduino and enable/disable it within the code, ie enable for running and fast stop, disable for free running stop? Not tried this!
IE lose the jumpers and use a 6-way cable to the headers, then you have full control.
enable low = free-running
enable high, both in's low = hard brake
enable high, both in's high = hard brake
MarkT:
IE lose the jumpers and use a 6-way cable to the headers, then you have full control.
enable low = free-running
enable high, both in's low = hard brake
enable high, both in's high = hard brake
That sounds the way to go controlling the jumpers with Arduino but I didn't quite understand the example.
Currently I have only one motor attached. The jumper for 'A' is enabled an I send PWM between 0-255 to IN1 with IN2 at 0 for 'forward' and PWM between 0-255 to IN2 with IN1 at zero for reverse with the PWM value setting the speed.
Do I need to enable low both A and B for free running or just the A channel that I'm using? Obvious question but just want to make sure
When A is enabled (as it is now with the jumper) I can imagine that this would give me hard braking (or at least something different to when the jumper is not enabled) when both PWM INs are set to zero.
However it seems strange to enable A and then set both INs to a high value (255 or any non zero value??) for braking to also occur! My expectation would be that any non-zero on both INs at the same time should drive the motor...
Perhaps someone has the data sheet for this breakout or a link to it?
acboother:
However it seems strange to enable A and then set both INs to a high value (255 or any non zero value??) for braking to also occur! My expectation would be that any non-zero on both INs at the same time should drive the motor...
... or is it?!
Maybe balanced INs values should be expected to set the degree of fast stop braking. A larger value means more braking... but then there's that pesky enable switch to set :~
I strongly recommend you read the 298 datasheet, and make use of all three (IN1, IN2, EN) pins for each motor channel.
EN=0 => freewheel
else EN=1
IN1=1, IN2=0 => power forward
IN1=0, IN2=1 => power backward
IN1=IN2=1, or IN1=IN2=0 => power braking (motor is shorted through either the high-side or low-side transistors)
So you have two options for controlling power:
constant IN1/IN2, PWM on EN => power control (including braking control) with fast current decay
constant IN1/EN, PWM on EN => power control with slow current decay
Which option you choose will depend on the speed the motor is running at, its inductance, back-EMF, etc. Have a google for "fast current decay" and "slow current decay" as how they pertain to motor control, and where the different current paths lie through the H-bridge in the different braking modes; you will need to understand the difference in order to choose what to PWM and why it behaves like it does.
Thanks for this info. I'm slowly getting there. I had a go with the datasheet but found it tricky to tie the info about the 'naked' L298 to the breakout board for which I still haven't found a datasheet for.
Didn't think/realise about PWM on EN. I'll put some more thoughts into that as well.
constant IN1/EN, PWM on EN => power control with slow current decay
In the above did you mean that or as you say constant EN and PWM on EN?
sorry, copy/paste error on that last one; should have said:
constant IN1/IN2, PWM on EN => power control (including braking control) with fast current decay
constant IN1/EN, PWM on IN2 => power control with slow current decay
And it's possible I got the modes backwards; I didn't read the 298 datasheet too carefully. Consider the voltage across the inductance of the motor, which will define the rate of change of current. Say you induce a current in the inductor and then place a perfect short across it (braking mode is an approximation of this). The only voltage present in that loop will be resistive losses, so the current will decay very slowly. If you instead have an open circuit, the voltage will spike very high until some insulation breaks down and the current will cease very quickly.
With EN off, the transistors are all off so the motor current will pass through the catch diodes and into the power supply, so the voltage across the coil is the supply voltage plus a couple of diode drops, which reduces the current much faster than would occur if the coil were shorted.
Fast decay mode is required to implement fast stepping with very large/inductive steppers. Since you're driving a DC motor and don't need the current to drop off quickly, you probably want slow decay mode.
For super-confusion factor, fast-decay mode is free-running stop and vice-versa. Unless I misunderstood something.
If you have a CRO that you can use to observe the motor current with (eg through a small series sense-resistor) in different control modes, it will probably be very enlightening.
Hi friends. I also have the same board as in the picture. I tried my best to attain a fast brake using arduino. But the motor is not stopping very fastly. I gave value of ena. In1 and in2 LOW. But the motor is not stopping suddenly. I think my code is bad. Can anynody write a code???. I didnt quiet undestood what is the deal with the jumpers. Can anybody explain in simple language about the jumpers.???
lukhmansquare:
Hi friends. I also have the same board as in the picture. I tried my best to attain a fast brake using arduino. But the motor is not stopping very fastly. I gave value of ena. In1 and in2 LOW. But the motor is not stopping suddenly. I think my code is bad. Can anynody write a code???. I didnt quiet undestood what is the deal with the jumpers. Can anybody explain in simple language about the jumpers.???
"""IE lose the jumpers and use a 6-way cable to the headers, then you have full control.""""
What is mean by this. Giving high.to ena is quiet understandable. But didnt get what is meant by the 6way headers. There is two connnection in enA(like this '| | '). Should I have to connect the both the connections of the enA to arduino?. Do you ever tried this braking function? Thennplease share the code....
Is it having no effect? The amount of braking depends on the motor, small motors have less torque
so brake less.
Try setting both inputs low and enable low, then twist the motor shaft and feel the resistance.
Repeat with enable high - there should be a difference.
Note that the L298 is a darlington driver so you will only get braking down to a certain lower
speed limit when the forward-voltage of the darlington outputs matches the back-EMF - any slower
than that and there is no braking.
Use a MOSFET H-bridge for much better performance.