DC MOTOR INTERFACING WITH 8051 MICROCONTROLLER

DC MOTOR INTERFACING WITH 8051 MICROCONTROLLER



In many electronics projects you may need to control a DC Motor with the help of 8051 micro-controller. The maximum current that can be sourced or sunk from a 8051 micro-controller is 15 mA at 5v. But a DC Motor need currents very much more than that and it need voltages 6v, 12v, 24v etc, depending upon the type of motor used. Another problem is that the back emf produced by the motor may affect the proper functioning of the micro-controller. Due to these reasons we can’t connect a DC Motor directly to a micro-controller.
To overcome these problems you may use a H-Bridge using transistors. Freewheeling diodes or Clamp diodes should be used  to avoid problems due to back emf. Thus it requires transistors, diodes and resistors, which may make our circuit bulky and difficult to assembly.

WORKING OF H-BRIDGE

H-bridge can also be made with the help of transistors and MOSFETs etc. It will be cheap but they increase the size of the design and circuit board which is mostly not required, so a small 16 pin IC is preferred for this purpose. Actually, the name “H-Bridge” is derived from the shape of the switching circuit which controls the motion of the motor. It is also known as “Full Bridge”. Basically there are four switching elements in the H-Bridge as shown in the figure below.
As we can see in the figure that there are four switching elements named as:
 High side left
High side right
 Low side right
Low side left

When these switches are turned on in pairs, the motor changes its direction accordingly. If we switch on “High side left” and “Low side right”, then motor will rotate in forward direction, as current from Power supply flows through the motor coil and goes to ground through switch low side right. This is shown in the figure below.

Similarly, when we switch on low side left and high side right, the current flows in opposite direction and motor rotates in backward direction. This is the basic working of H-Bridge. We can also make a small truth table according to the switching of H-Bridge explained above.
High Left
High Right
Low Left
Low Right
Description

On

Off

Off

On

Motor runs clockwise

Off

On

On

Off

Motor runs anti-clockwise

On

On

Off

Off

Motor stops or decelerates

Off

Off

On

On

Motor stops or decelerates
So we have seen that using simple switching elements we can make our own H-Bridge. Other option is to use IC based H-bridge driver. Obviously, we will use Driver IC otherwise heat sinks will be used for MOSFETs etc.

To overcome this problem the L293D driver IC is used. It is a Quadruple Half H-Bridge driver and it solves the problem completely. You needn’t connect any transistors, resistors or diodes. We can easily control the switching of L293D using a micro-controller. There are two IC’s in this category L293D and L293. L239D can provide a maximum current of 600mA from 4.5V to 36V while L293 can provide up to 1A under the same input conditions. All inputs of these ICs are TTL compatible and clamp diodes is provided with all outputs. They are used with inductive loads such as relays solenoids, motors etc.
L293D contains four Half H Bridge drivers and are enabled in pairs. EN1 is used to enable pair 1 (IN1-OUT1, IN2-OUT2) and EN2 is used to enable pair 2 (IN3-OUT3, IN4-OUT4). We can drive two DC Motors using one L293D, but here we are using only one. You can connect second DC Motor to driver pair 2 according to your needs.
Circuit Diagram


The DC Motor is connected to the first pair of drivers and it is enabled by connecting EN1 to logic HIGH (5V).  VSS pin is used to provide logic voltage to L293D. Here 8051 micro-controller, which works at 5v is used to control L293D, hence the logic voltage is 5. The motor supply is given to Vs pin of the L293D.

Keil C Program

#include<reg52.h>
 void delay(void);
 sbit motor_pin_1 = P2^0;
sbit motor_pin_2 = P2^1;
void main()
{
  do
  {
    motor_pin_1 = 1;
    motor_pin_2 = 0; //Rotates Motor Anit Clockwise
    delay();
    motor_pin_1 = 1;
    motor_pin_2 = 1; //Stops Motor
    delay();
    motor_pin_1 = 0;
    motor_pin_2 = 1; //Rotates Motor Clockwise
    delay();
    motor_pin_1 = 0;
    motor_pin_2 = 0; //Stops Motor
    delay();
  }while(1);
}
 
void delay()
{
  int i,j;
  for(i=0;i<1000;i++)
  {
    for(j=0;j<1000;j++)
    {
    }
  }
}

Comments

Popular posts from this blog

Embedded MCQ Questions

8051 INTERRUPT