Proton Tutorial - DC Motor


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




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

Proton Tutorial - DC Motor
Device = 16F877
XTAL = 4
Symbol IN3 = PORTA.0
Symbol IN4 = PORTA.1
Low IN3 ' Setup the output pins
 Low IN4 '
 High IN3 ' Begin CW rotation
  Low IN4
 DelayMS 5000 ' Delay for 5 seconds
 Low IN3 ' Begin CCW rotation
  High IN4 
 DelayMS 5000 ' Delay for 5 seconds
 Low IN3 ' Stop motor
  Low IN4 
 DelayMS 3000 ' Delay for 3 seconds 
 GoTo Program_Start 


Forum Activity

  • No posts to display.

Member Access