motor interfacings


L293D Dual H-Bridge Motor Driver

L293D is a dual H-Bridge motor driver, So with one IC we can interface two DC motors which can be controlled in both clockwise and counter clockwise direction and if you have motor with fix direction of motion the you can make use of all the four I/Os to connect up to four DC motors. L293D has output current of 600mA and peak output current of 1.2A per channel. Moreover
 for protection of circuit from back EMF ouput diodes are included within the IC. The output supply(VCC2) has a wide range from 4.5V to 36V, which has made L293D a best choice for DC motor driver.

A simple
 schematic for interfacing a DC motor using L293D is shown below.

#include <AT89X51.H>
#define L293D_A P2_0         //Positive of motor
#define L293D_B P2_1         //Negative of motor
#define L293D_E P2_2         //Enable of L293D

// Function Prototypes
void rotate_f(void);         //Forward run funtion
void rotate_b(void);         //Backward run function
void breaks(void);           //Motor stop function
void delay(void);            //Some delay

void main(){                 //Our main function
    
while(1){                //Infinite loop
                rotate_f
();          //Run forward
                delay
();             //Some delay
                breaks
();            //Stop
                delay
();             //Some delay
                rotate_b
();          //Run Backwards
                delay
();             //Some delay
                breaks
();            //Stop
                delay
();             //Some delay
        
}                        //Do this infinitely
}
void rotate_f(){
        L293D_A 
= 1;             //Make positive of motor 1
        L293D_B 
= 0;             //Make negative of motor 0
        L293D_E 
= 1;             //Enable L293D
}
void rotate_b(){
        L293D_A 
= 0;             //Make positive of motor 0
        L293D_B 
= 1;             //Make negative of motor 1
        L293D_E 
= 1;             //Enable L293D
}
void breaks(){
        L293D_A 
= 0;             //Make positive of motor 0
        L293D_B 
= 0;             //Make negative of motor 0
        L293D_E 
= 0;             //Disable L293D
}
void delay(){                //Some delay...
    
unsigned char i,j,k;
    
for(i=0;i<0x20;i++)
        
for(j=0;j<255;j++)
                
for(k=0;k<255;k++);
}
Connecting Unipolar Stepper Motor

There are actually many ways you can interface a stepper motor to your controller, out of them the most used interfaces are:
  1. Interface using L293D - H-Bridge Motor Driver
  2. Interface using ULN2003/2004 - Darlington Arrays

We will dicuss both connection techniques one by one. The above mentioned methods need 4 controller pins for interface.
as you see in the circuit below the four pins "Controller pin 1",2,3 and 4 will control the motion and direction of the stepper motor according to the step sequece programmed in the controller.

Connecting Unipolar stepper using L293D



Connecting Unipolar stepper using ULN2003/2004


2-wire connection for Unipolar Stepper Motor
We have seen the generally used 4-wire connection method for interfacing unipolar stepper motor, but we can simplify the design to make controller use less pins with the help of 2-wire connection method. The circuit for 2-wire connection is shown below.


Connecting Bipolar Stepper Motor
As we have studied that, Bi-polar stepper motors has 2 different coils. The step sequence for Bipolar stepper motor is same as that of unipolar stepper motors. The driving circuit for this require an H-Bridge as it allows the polarity of the power applied to be controlled independently. This can be done as shown in the figure below:


Now we have seen the methods for connecting stepper motors with your microcontroller. So keeping these circuits in mind,we will now look at the programming of microcontroller to control stepper motors. This is discussed in the next section of the tutorial. 
#include <REG2051.H>.
#define stepper P1
void delay();

void main(){
        
while(1){
                stepper 
= 0x0C;
                delay
();
                stepper 
= 0x06;
                delay
();
                stepper 
= 0x03;
                delay
();
                stepper 
= 0x09;
                delay
();
        
}
}

void delay(){
        
unsigned char i,j,k;
        
for(i=0;i<6;i++)
                
for(j=0;j<255;j++)
                        
for(k=0;k<255;k++);
}