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).

 Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Collapse 16F PIC Examples16F PIC Examples
LED's
Switches
Keypads
LCD's
7 Seg Displays
ADC
DAC
Collapse MotorsMotors
DC Motors
Servo's
Bipolar Stepper
Unipolar Stepper
Expand ThermometersThermometers
DS1307 RTC Chip
DS275
EEPROM's
RF Modules
RGB LED's
Code Snippets
Expand Code SnippetsCode Snippets
Expand 18F PIC Examples18F PIC Examples
Expand Handy TipsHandy Tips