Introduction: Reversing a Motor
Once you can control the speed of a large motor in one direction, the next step is to control its speed in the opposite. On the smaller end of the 'large motor' scale this is an easy thing to do and require little to no additional hardware. However, as you will see, when dealing with very large motors, this requires some additional hardware and design considerations. While this might seem intimidating at first, it actually is not that complicated once you get the hang of it.
The Parallax DHB-10 Motor Controller and the Cytron MD30C R2 motor controller are both designed with H-bridges on-board and allow for the reversal of motor direction using code. Put simply, this makes reversing the motors incredibly easy. However, due to the nature of how each is controlled, this is handled slightly differently in the code.
The circuit for reversing the Parallax motor controller is exactly the same as the circuit for making it spin in just one direction. The difference is in the code. Rather than use values below the "servo" motor's neutral point, we are going to use values above it. As you can see from the following code, it is really that simple:
To reverse the Cytron board we need to make one additional wire connection. The white wire connected to the "DIR" (direction) pin needs to be connected to Digital Pin 2 on the Arduino. Setting this pin high or low using a digital write command toggles whether the motor is spinning forwards or backwards. This is demonstrated using the following code:
When reversing a motor's direction using a microcontroller, it is important to slow the motor down to zero speed before reversing the motor direction. If you rapidly reverse the motor without doing this, there will be a sudden current surge as the motor's coil quickly switches polarity. Also, the motor will violently jerk as it rapidly switches direction, which is likely something you want to avoid.
An easy way to deal with this is to write code which (relatively) slowly ramps down the motor speed, and then ramps it back up in the opposite direction.
What follows is a simple program for the Cytron motor controller to ramp up and down the motor's speed in one direction, and then the other:
The Alltrax controller handles currents so large, it cannot effectively and safely use a solid state H-bridge to reverse motor direction. Thus, motor reversal is not built into the motor controller itself. Instead, the Alltrax controller is designed to work in conjunction with an external reverse contactor.
A reverse contactor is essentially a very large electromechanical switch that toggles the (output) polarity of its input voltage depending on which of the two coils are energized. In a way, it is a bit like a DPDT switch wired to work as an H-bridge (such as seen in this Instructable) that is being toggled by a solenoid.
Before we can begin wiring up the reverse solenoid, we need to make a few minor changes. To begin, we are going to need to attach 1N4004 snubber diodes on each coil. The coils can be found by locating the sets of small terminals on each side of the reverse contactor. Each set is a single coil.
Even though there are four terminals for each coil, there are only two real connections. The top two terminals are one pair, and the bottom two are another pair. We are going to designate this our positive side. This, by default, is going to become our ground connection.
Thus, the anode of one of the 1N4004 diodes should go to of the bottom pairs of terminals for one coil, and the cathode should go to the top pair. This should be repeated for both sides.
Also, while we are at it, we may as well connect together the ground terminals between each coil. Simply solder a wire bridging the two pairs of bottom terminals. This will prevent having to attach additional wires later, as both coils need to be grounded.
Starting with a typical high current wiring setup, we connect the cables from the Alltrax controller that would normally go to the motor to the power inputs of the reverse contactor. The Alltrax's M- terminal is connected to the reverse contactor's high current ground terminal, and the Alltrax's B+ terminal is connected to the V+ terminal on the reverse contactor.
The output terminals from the reverse contactor are then directly connected to the motor terminals. It does not matter which goes to which. These are going to be reversed back and forth.
Connecting a reverse switch to the coils is a little bit trickier, and requires more additional components. As you can see from the schematic, we need to add two additional diodes. Each throw (outer terminal) of the switch not only goes to a coil on the reverse contactor, but also passes through a diode to the KSI terminal on the motor controller. The diodes prevent the signal to the KSI terminal from crossing over and powering both reverse contactor terminals at once.
If this is confusing to you, check out the official wiring diagram, which does not use a circuit board for signal routing.
Engaging both terminals on the reverse contactor at the same time is bad and can result in a high current electrical short. This could potentially cause a current spike which destroys the reverse contactor or motor controller. It could also potentially spot weld the connections inside of the reverse contactor together. What this means is that it will forever lock the state of the motor in a single direction, and no longer able to reverse.
It is therefore important to prevent a state in which both reverse contactor coils can be energized at the same time. As already mentioned, the diodes are there to help prevent this. Beyond that, it also important to make sure that the switch can never be in both states at once. The best way to do this is with a SPDT toggle switch with a "center off" position. This means that when the switch is toggled to the center, all connections are definitively broken. This prevents a situation in which both of the outside connections can be on at once as the switch is toggled back and forth.
To clean up the control circuit, I went ahead and designed my own circuit board to keep all of the wiring nice and tidy. Again, designing and manufacturing a PCB is not necessary. You can build the circuit on a proto board if pressed for time. However, should you be inspired to design your own PCB, you can use this custom "Large Motor" Eagle library that includes a footprint for a 5A fuse, and one suitable for SPST and SPDT relays. If you have never designed a PCB before, check out my Circuit Board Design Class for instructions (or a refresher).
For this interface circuit interface you will need the following materials:
(x1) 6A2 6A diode
(x2) 1N4004 diode
(x1) 5A / 58VDC fuse
(x1) Fuse holder
(x3) 2-pin 3.5mm terminal block
(x1) 3-pin 3.5mm terminal block
Once the interface circuit is built, the signal should first pass through the 5A fuse and a 6A reverse protection diode to the KSI switch.
From the KSI switch, it should then go to the center pole of the reverse switch.
The output poles of the reverse switch should, in turn, both go to one of the coils of the reverse contactor, and also pass through a 1N4004 diode to both the main contactor coil and the KSI input pin.
To be a little more clear, the outside poles of the SPDT switch should each go to a respective positive coil connection on the reverse contactor. In other words, each wire should go to one of the upper set of terminals on each side of the reverse contactor. These connections are what changes the polarity of the current flowing through the reverse contactor and only one coil should ever be powered up at any given time.
Finally, once all of the switch connection are made, it is time to connect a throttle. In this example, I am connecting a 0-5K throttle. Regardless of which throttle you select, remember to configure it correctly in the Alltrax Toolkit software (as shown in the Controlling Motor Speed Lesson).
To go a step further and reverse the motor using an Arduino, once again building an additional circuit is required. Fundamentally, both the SPDT on/off/on (direction) toggle switch and the SPST on/off (KSI) toggle switch need to be replaced with equivalent relays. Put another way, the SPDT switch needs to be replaced with a SPDT relay, and the SPST switch with an SPST relay. The relays should have 5V (activation) coils and be rated for more than 28V DC on their contact.
Once again, the relays in the circuit requires TIP120 transistors, resistors, and diodes to interface with the Arduino. In addition, this circuit includes the two 1N4004 diodes used for simultaneously activating the KSI switch and the reverse contactor coils. Last but not least, the circuit also has the obligatory 5A fuse and 6A diode which are used to protect against current and reverse voltage surges, respectively.
For this circuit, I once more designed my own circuit board and sent the files out for manufacturing. You don't have to do it this way, and can easily build a similar circuit with a proto board. However, should you wish to go down this road, let me mention one last time that my Circuit Board Design Class is a great place to start. If you are inspired to go down this road, don't forget to download the "Large Motors" Eagle library that has footprints suitable for the relays and the fuse holder.
(x1) SPST Relay
(x1) SPDT Relay
(x2) TIP120 transistor
(x1) 6A2 6A diode
(x4) 1N4004 diode
(x2) 1K resistor
(x1) 5A / 58VDC fuse
(x1) Fuse holder
(x4) 2-pin 3.5mm terminal block
(x1) 3-pin 3.5mm terminal block
After you have gathered all of the parts, simply build the circuit board as specified in the schematic.
The next step is to connect the inputs of 12V power converter to the high current input terminal of the main contactor, and the B- terminal of the Alltrax controller. Connect the 12V outputs to the input jack on the Arduino. On many models of Arduino (such as the pictured Arduino Uno), this requires attaching a barrel plug.
Now is time to wire up the circuit board and Arduino as represented in the schematic above. While the wiring may look intimidating, it is really not so complicated.
Should that still be confusing, what follows is a slightly more Arduino-specific diagram (to our particular wiring configuration) of the connections that need to be made:
Once that you are sure all of the circuit connections have been made, here is some code to test out controlling the motor both forwards and backwards:
One last thing I would be remiss in not mentioning while discussing reversing a motor using the Alltrax Controller is the Reverse Speed pin. This input on the controller limits the motor to a slower speed when it is going in reverse. This is a safety feature meant for commercial vehicles like golf carts and is used rarely when building a DIY system.
To enable the reverse speed pin, simply wire the pin to the positive input of the secondary coil on the reverse contactor. This is the one which reverses the motor when activated. When this coil is pulled high, the reverse pin on the controller will simultaneously be set to high as well which will enable 1/2 speed mode.
If you are still confused about this wiring, pay careful notice to the extra-thick orange line above.
The actual reverse speed settings can be adjusted in the Alltrax Toolkit software. This is adjusted using the Max Reverse Motor Speed slider under the "Controller Settings" tab that we ignored in the previous lesson. The default value is 50% of full speed, but you can set this to whatever you desire.
While you may never use this safety feature, it is just one of many that you will find in the Alltrax Toolkit if you dig a little deeper. In the upcoming Further Considerations lesson, we will briefly discuss some additional Alltrax Toolkit features as well as review some general design considerations for working with large motors.
Share a photo of your finished project with the class!
Nice work! You've completed the class project