How to use L293D with PIC Microcontroller

Microcontroller Topics
Post Reply
User avatar
Shehani
Lieutenant
Lieutenant
Posts: 61
Joined: Mon Aug 19, 2013 2:11 pm

How to use L293D with PIC Microcontroller

Post by Shehani » Mon Sep 16, 2013 12:07 pm

This tutorial explains ” How to interface DC Motor with PIC Microcontroller ? “.
DC Motor and L293D
1.png
1.png (10.46 KiB) Viewed 2665 times
We can’t drive a DC Motor (depends) directly with a Microcontroller, as DC Motors requires high current and high voltage than a Microcontroller can handle. Microcontrollers usually operates at +5 or +3.3V supply and it I/O pin can provide only up to 25mA current. Commonly used DC Motors requires 12V supply and 300mA current, moreover interfacing DC Motors directly with Microcontrollers may affect the working of Microcontroller due to the Back EMF of the DC Motor. Thus it is clear that, it not a good idea to interface DC Motor directly with Microcontrollers.

The solution to above problems is to use H-bridge circuit.
Basic H-Bridge DC Motor Driving
Basic H-Bridge DC Motor Driving
2.gif (11.63 KiB) Viewed 2665 times
It is a special circuit, by using the 4 switches we can control the direction of DC Motor. Depending upon our power requirements we can make our own H-bridge using Transistors/MOSFETs as switches. It is better to use ready made ICs, instead of making our own H-bridge.

L293D and L293 are two such ICs. These are dual H-bridge motor drivers, ie by using one IC we can control two DC Motors in both clock wise and counter clockwise directions. The L293D can provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V while L293 can provide up to 1A at same voltages. Both ICs are designed to drive inductive loads such as dc motors, bipolar stepping motors, relays and solenoids as well as other high-current or high-voltage loads in positive-supply applications. All inputs of these ICs are TTL compatible and output clamp diodes for inductive transient suppression are also provided internally. These diodes protect our circuit from the Back EMF of DC Motor.
PIN Diagram of L293D
PIN Diagram of L293D
3.jpg (35.9 KiB) Viewed 2665 times
In both ICs, drivers are enabled in pairs, with drivers 1 and 2 are enabled by a high input to 1,2EN and drivers 3 and 4 are enabled by a high input to 3,4EN. When drivers are enabled, their outputs will be active and in phase with their inputs. When drivers are disabled, their outputs will be off and will be in the high-impedance state.
Function Table of L293D
Function Table of L293D
4.png (7.4 KiB) Viewed 2665 times
Interfacing with PIC Microcontroller

Circuit Diagram
Interfacing DC Motor with PIC Microcontroller and L293D Circuit Diagram
Interfacing DC Motor with PIC Microcontroller and L293D Circuit Diagram
5.png (68.84 KiB) Viewed 2665 times
Note: VDD and VSS of the pic microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND.

We can drive two DC Motors with one L293D, in this example we are using only the first pair of drivers to drive one DC Motor. First pair of drivers are enabled by connecting EN1 to Logic HIGH. IN1 and IN2 are connected to RB0 and RB1 of PIC Microcontroller respectively which are used to provide control signal to the DC Motor. DC Motor is connected to OUT1 and OUT2 of the L293D.

MikroC Source Code

Code: Select all

void main()
{
 CMCON = 0x07; // To turn off comparators
 ADCON1 = 0x06;// To turn off ADC
 TRISB = 0; // PORT B as output port
 PORTB = 1; // Set RB0 to high
 do
 {
   //To turn motor clockwise
   PORTB.F0 = 1;
   Delay_ms(2000);//2 seconds delay

   //To Stop motor
   PORTB = 0; // or PORTB = 3 
   Delay_ms(2000);//2 seconds delay

   //To turn motor anticlockwise direction
   PORTB.F1 = 1;
   Delay_ms(2000);//2 seconds delay

   //To Stop motor
   PORTB = 0; // or PORTB = 3 (3 = 0b00000011)
   Delay_ms(2000); // 2 seconds delay

 }while(1);
}
Control Signals and Motor Status
1.png
1.png (5.58 KiB) Viewed 2665 times
Article courtesy of electrosome.com
Post Reply

Return to “Microcontrollers”