16F DC Motor Example

DC motors have great torque and can be used in many
applications such as RC cars/boats. One major aspect about DC
motors is their ability to draw a lot of
current, and a
PIC clearly cant drive on on its own. The
L298 chip however can drive DC motors with up to 2A, and
only requires digital inputs to control the windings.
Another aspect to consider is that its not healthy to abruptly
change direction with the motor. This causes a lot of EMF
feedback, and arcing/sparking internally. But the L298 helps to
compensate for this with its fast stopping feature. The chip can
control 2 coils (i.e. 2 DC motors like the one below, or one
bipolar stepper motor), and has control lines for each coil
(C1, D1, C2, D2), there are also 2 enable lines that control the
coils (E1, E2). The enable lines must be an active high to allow
the operation of the coils, and depending on the configuration
of the coil lines, will depend on the direction of drive.
Consider the table for control of one motor (C is IN3, D is IN4
Ven is ENB in diagram below),


Note the PIC's power supply/oscillator are not shown
Click
here to see this circuit in action!
For better reverse current protection on the H-Bridge, use
these diodes
Now its just a matter of making IN3 High and IN4 low for CW rotation
and IN3 low, IN4 High for CCW. But we must allow the motors to slow
down before switching directions, to do this IN3 has to be the same
state as IN4 (both high or both low).

 | Site Tutorial Index |
|  | 16F PIC Examples |
| |  | Motors |
| |  | Thermometers |
| |  | Code Snippets |
|  | 18F PIC Examples |
|  | Handy Tips |