To drive the dual bidirectional motors on my small robot project, I
originally used an opto-isolated H-bridge motor controller. When attempting to
run the robot on a medium pile carpet, the robot slowed down considerably.
Checking the voltage across the motors I found that the H-bridge circuit,
composed of Darlington-pair power transistors, was lowering the 6 Volt drive
voltage to slightly over 3 Volts. In addition, the tell-tale warmth of the
power transistors indicated a larger inefficiency than I desired for a battery
powered device.
To correct these problems, I designed a motor controller that uses a
silicon relay for power controls, a latching relay for motor directions, and a
PIC16LC620 microcontroller to translate the input lines to motor direction,
time the latching relay coil energization, and activate the silicon relays.
Using this system, output voltage went up to 4.2 Volts, and both the 6 Volt
power and 5 Volt control efficiencies improved dramatically.
The factors considered in the design included low quiescent power, high
efficiency, low part count, easy digital control, and upgradable to serial
control or pulse-width-modulation (PWM) speed control in future versions. As
always, cost was also a consideration.
Relays would keep the voltage drop low and have an excellent efficiency
(on the motor supply side), and to keep a low quiescent power and improve
control side efficiency, latching relays can be used. However, mechanical
relays have a limited switch lifetime and a large switching time, which makes
them unsuitable for PWM modulation for speed control. It was therefore decided
to use a mechanical latching relay for direction control and a silicon relay
for power on-off. The power draw and voltage drop of the silicon relay is
still less than the H-Bridge system.
To convert the digital control signals to relay actions, time the latching
relay energization, and make software upgrades to serial control and
pulse-width-modulation, a microcontroller would be used. To stay with the
design guidelines of low power and low part count, the PIC16LC620 was chosen.
At low frequencies, this chip will draw less than 50 A of current, but can
source and sink 25 mA per I/O line (but with limitations on total current draw
for a port). When paired with the chosen latching relay, the Aromat TQ2-L-5V,
which uses 5V and 20 mA to drive a single bidirectional relay coil no other
components or drivers are needed for relay activation.
An RC oscillator was chosen to keep cost down and the frequency low,
thereby reducing power used by the microcontroller. A balance was struck
between the desire for lower power (increasing the resistance R), and timer
stability (increasing the capacitance C), while pushing for a clock frequency
between 20 and 30 kHz. The 100k resister (maximum recommended by Microchip)
and 0.00033 F capacitor result in a frequency of about 24 kHz on my board,
making the instruction execution speed 6 kHz, which is fast enough for the
current system without serial control or PWM. If either of these options were
to be added, the RC oscillator should be replaced by a low power crystal
oscillator configuration.
Besides the PIC, the resistor-capacitor for the RC oscillator, the
latching relays, and the silicon relays, only a few other components are
needed. A 47 k resistor ties the reset (MCLR) line to approximately 4.7
Volts, limiting current use as much as possible without lowering the voltage
below the threshold for the line. Two 220 resistors limit current to the
silicon relays while keeping the control voltage well above the 3 Volt
threshold for the relays used. And finally a .1 F capacitor across the 5
Volt supply line for the PIC smooths power draw when the latching relay coils
are energized, preventing a brown-out reset being performed by the PIC. Only
connectors, PC board, and connecting wire are needed to complete the circuit.
The schematic for the circuit can be found on the
Schematics
Page.
Control is provided by three digital input lines that specify the overall
direction of the two motor system. The following table shows the eight
possible states of the input lines and the system and motor directions for each
of the combinations.
Command | Direction | Left Motor | Right Motor |
0 | Stop | Off | Off |
1 | Forward Right | Forward | Off |
2 | Forward Left | Off | Forward |
3 | Forward | Forward | Forward |
4 | Back Left | Reverse | Off |
5 | Sharp Right | Reverse | Forward |
6 | Sharp Left | Forward | Reverse |
7 | Reverse | Reverse | Reverse |
Each of the two motors can be in one of three states; forward, reverse, or
off. With two motors this gives 3 X 3 combinations, or 9 possible states.
Since only three control lines were used, one of the possible states was left
out. One of the reverse turns was chosen, the back-right direction by an
arbitrary decision.
The PIC microcontroller initializes the directional latching relays to a
known position, both motors in the forward direction. It then will energize
the relay coils only when necessary. For example, when the control command
changes from 3 to 2 (Forward to a Forward Left turn), the no direction changes
are needed, only the left motor power silicon relay state is changed. By
having the microcontroller remember the state of the latching relays and
changing them only when required, average response time is improved and power
efficiency is enhanced.
The latching relays have a maximum switching time of 3 milliseconds. To
account for variance in the RC timing used, the software is set up to energize
the relays for a calculated time of about 4 milliseconds. If a large number of
direction changes are expected the timing parameters can be adjusted closer to
the 3 millisecond mark to further reduce average current use.
The software algorithm used is relatively simple. After initializing the
system by setting the port directions, turning off both silicon relays, and
setting the directional latching relays to an initial forward state, the
program goes into a tight loop looking for a change in the three control lines.
When a new command is received, the program determines if directional relays
need to be changed. If not, the required motor on-off states are sent to the
port pins that control the silicon relays and the program branches back to wait
for another command change. If latching relay changes are required, the motors
are turned off, the appropriate port setting for the latching relay coil
energizations is put onto the port, the coil timer is set, and the program
again branches back to wait for a new command. When the coil timer expires, an
interrupt is generated. The interrupt handling routine de-energizes the
latching relay coils and turns on the required motor or motors, and returns
back to wait for another command change.
To view the software listing,
click here.
To
download a text only version of the source code,
click here.
To
download the MacPIC project for the controller,
click here.
The results for energy savings are considerable. The following table shows the current use for the 5 volt control rail, the voltage motor drive output, and the battery to motor power efficiency. The current is measured for three conditions, quiescent current, current with 1 motor on, and current use with both motors on. One note on testing, since an actual motor made the voltage noisy due to commuter switching, a 16.5 fixed resistor was used as the load for the motor controller circuit. Comparison is with the MondoTronics Maxi H-Bridge Motor Controller.
Parameter | H-Bridge | PIC Motor Controller |
Iquiescent | 7.45 mA | 407 µA |
I1 | 11.1 mA | 6.4 mA |
I2 | 14.6 mA | 12.2 mA |
Vmotor | 3.25 V | 4.20 V |
efficiency | 63 % | 89.5 % |
From the data in the above table it can be seen that the motor controller meets the design goals of higher motor voltage and improved efficiency by a significant margin. On a less quantitative level, my robot runs quite will on carpeted surfaces now!
I will provide a diagram for a PC board that I created for this project very
soon. I drew it in ClarisWorks 4.0, so if anyone has that program and wants the
file, just email me.
For those of you without a PIC programmer, I can
provide programmed PIC16C620 chips for this project. The price is $10 for a OTP
(one-time programmable) version, or $15 for EPROM (Erasable Programmable
Read-Only Memory) versions, with applicable shipping costs added to both. For
more information or to order a programmed chip, email me at
MacRobotics@MacRobotics.com