A4988RobotV2.txt (3383Bytes)
EDIT: Some speed control, new code example and video added 21.2.2014 See below " SOME IDEAS" section for more information.
I ordered some well known pololu style A4988 stepper driver modules for a project. However it came to my mind that could one use these very cheap, small and nice modules to drive DC motors too?
I remembered the times i started playing with arduinos PICAXEs and stuff and for a poor hobbyist it seemed to be very wasteful to use two h-bridges to drive one stepper motor when one can drive two DC-motors as well. Now I know better the steppers have some use two but nevertheless DC motors are nice choise for a small nice wandering robot.
I googled around and was told not to try it. Reading the datasheet of A4988 reveled that there isn't any reason why it shouldn't work. When two motors are plugged to A4988 module (instead of steppers coils) they can be driven by manipulating stepping sequency.
Pros for using A4988 as dual h-bridge:
- Cheap and widely available ( 1.4 $, ebay FEB, 2015)
-small
-2A, (many modules can't do that really, depends on heatsinking and current sense resistors)
- Only 3 datalines needed (or only two)
-small voltage drop comapred to many older h-bridges
-current limit that can be adjusted
- Speed control possible without external pwm
-Sleep mode
-Controlled decay modes for coil current reversing and crossover protection.
- Ability to run DC motors above their rated voltage and get some benefits of it
Cons
-Not so easy logic
-Harder to control speed of individual motors (but not impossible)
-something i didn't realize
-needs 7.5-8v motor supply
Steppers are driven by pulsing step pin and direction is changed by setting dir pin hig or low. Every time use pulse step, current in one of the coils chnages its direction. This is picture from ST micoelectronics application note.
I made a little code that makes right number of steps to right direction depending on current state of motors. Its nothing very fine and optimal but works as you can see in the video. I had no ready platform to try this out and improvised this little fellow. My 6-years old daughter made the cardboard boxes as I promised to show them here :)
Schematic is so obvious that I only refer to pololu minimal setup quide:
https://www.pololu.com/product/1182
Only differences are that arduino pin 8 is connected to enable and motor windings are in separate motors. I couldn't find in datasheet whats the undervoltage lockout limit for module but I run motors wit 7.4lipo which is under the recomnded 8v but worked fine (besides the motors are rated 12V so they run little slow). I think with current limit you can run motor with voltage above its rated, what gives faster response and even better torque in startup?
Some guts:
SOME IDEAS:
This code doens't show it but i tried also control speed of motor by pulsing enable (its won't affect stepping translator) and it seemed to work fine. I plan to try individual motor speed control by changing to half-step sequency and changing fast between two coil ON and one coil OFF. I found that A4988 has internal pwm to set different current levels in microstepping modes. These modes can be used to control speed of motors independetly. Example video uses 8-step-mode.
As you can see both motors have 70% of maximum current when in starting position. When another motors current increases, ohters decreases.This may be handy when you only need to make motors run same speed and they have little difference when both have same current. (quite common situation)
If you want to only slow another motor down you can set currentlimit with potentiometer so that 70% of it is you motors max current. So motorB speed won't increase when you slow motorA down.
Best resolution would be achieved in 16-step mode. How ever any speed combination of motors is possible when PWM on enable pin is combined to this approach.
I realized that my example code is crappy. It would be more reliable and easy to use reset to put motors in known state before telling them to change direction. Now there is a new code and video with PWM speed control and reset of states. Also DIR pin isn't needed anymore so it could be only tied to VCC.
Also it came to my mind that one could get away with only two data lines by pulling DIR pin low/high and making proper amount of steps in one direction. If you don't want to stop your motors but only change the direction, then pulsing step-pin is enough. Quite minimal setup :)
Next project to make minibot with these 3-5v wormgear motors and a pro mini.
https://www.youtube.com/watch?v=cuA9Yujp5E0