0% found this document useful (0 votes)
168 views

AVR Programming For DC Motor Interfacing

This document discusses interfacing a DC motor with a microcontroller using an H-bridge circuit. It describes how an H-bridge allows controlling the direction of a DC motor by switching the motor connections. An H-bridge can be made with transistors or with an integrated circuit like the L293D dual H-bridge driver. The document provides code examples in C for interfacing a DC motor with an L293D using a microcontroller to control the motor direction and speed.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views

AVR Programming For DC Motor Interfacing

This document discusses interfacing a DC motor with a microcontroller using an H-bridge circuit. It describes how an H-bridge allows controlling the direction of a DC motor by switching the motor connections. An H-bridge can be made with transistors or with an integrated circuit like the L293D dual H-bridge driver. The document provides code examples in C for interfacing a DC motor with an L293D using a microcontroller to control the motor direction and speed.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

DC Motor interfacing with Microcontrollers tutorial: Introduction

Introduction
Whenever a robotics hobbyist talk about making a robot, the first thing comes to his mind is making the robot move on the ground. And there are always two options in front of the designer whether to use a DC motor or a stepper motor. When it comes to speed, weight, size, cost... DC motors are always preffered over stepper motors. There are many things which you can do with your DC motor when interfaced with a microcontroller. For example you can control the speed of motor, you can control the direction of rotation, you can also do encoding of the rotation made by DC motor i.e. keeping track of how many turns are made by your motors etc. So you can see DC motors are no less than a stepper motor. In this part of tutorial we will learn to interfacing a DC motor with a microcontroller. Usually H-bridge is preffered way of interfacing a DC motor. These days many IC manufacturers have H-bridge motor drivers available in the market like L293D is most used H-Bridge driver IC. H-bridge can also be made with the help of trasistors and MOSFETs etc. rather of being cheap, they only increase the size of the design board, which is somtimes not required so using a small 16 pin IC is preffered for this purpose.

Working Theory of H-Bridge


The name "H-Bridge" is derived from the actual shape of the switching circuit which control the motoion 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 you can see in the figure above 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 motor changes its direction accordingly. Like, if we switch on High side left and Low side right then motor rotate in forward direction, as current flows from Power supply through the motor coil goes to ground via switch low side right. This is shown in the figure below.

Similarly, when you 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. Truth Table High Left High Right Low Left Low Right On Off Off On Off On On Off On On Off Off Off Off On On

Description Motor runs clockwise Motor runs anti-clockwise Motor stops or decelerates Motor stops or decelerates

As already said, H-bridge can be made with the help of trasistors as well as MOSFETs, the only thing is the power handling capacity of the circuit. If motors are needed to run with high current then lot of dissipation is there. So head sinks are needed to cool the circuit. Now you might be thinkin why i did not discuss the cases like High side left on and Low side left on or high side right on and low side right on. Clearly seen in the diagra, you don't want to burn your power supply by shorting them. So that is why those combinations are not discussed in the truth table. So we have seen that using simple switching elements we can make our own H-Bridge, or other option we have is using an IC based H-bridge driver. Both of them are discussed in the next section of the tutorial.
Previous Page | Next Page

DC Motor Tutorial Index


DC Motor Introduction BJT Based H-Bridge Interfacing L293D Programming for DC Motor

Google Search

for Microcontrollers! Submit search

Enter your search terms form


Search

Web

8051projects.net

This work is licensed under a Creative Commons Attribution-Noncommercial 2.5 India License.

Rickey's World Disclaimer

DC Motor interfacing with Microcontrollers tutorial: BJT Based H-Bridge for DC motors

BJT H-Bridge
A simple H-bridge can be made with the help of Power BJTs like TIP31 and TIP32. An example and a working demo of this circuit is shown in the figure below.

BJT H-Bridge Demo

Previous Page | Next Page P

DC Moto or interfacing g with Micro ocontrollers tutorial: L29 93D H-Bridg ge interfacin ng

L293 3D Dual H-Bridge Motor Drive er


L293D is s a dual H-B Bridge motor r driver, So wi ith one IC we w can interfa ace two DC motors m whic ch can be co ontrolled in both b clockw wise and coun nter clockwise direction and if you have h motor wi ith fix direct tion of motio on the you ca an make use e of all the fo our I/Os to connect up to o four DC motors. L293D L has output o curren nt of 600mA A and peak ou utput curren nt of 1.2A per channel. Moreove er for protect tion of circui it from back k EMF ouput t diodes are included i wit thin the IC. The T output su upply (VCC2 2) has a wide e range from m 4.5V to 36V V, which ha as made L293D a best ch hoice for DC motor m driver. e schematic for f interfacin ng a DC mot tor using L2 293D is show wn below. A simple

C pro ogramming g
CODE: #inclu ude <AT89 9X51.H>#d define L2 293D_A P2 2_0 //Pos sitive of f motor #defin ne L293D_ _B P2_1 / //Negativ ve of mot tor #defin ne L293D_ _E P2_2 / //Enable of L293D D

// Function Prototypes void rotate_f(void); void rotate_b(void); void breaks(void); void delay(void); void main(){ while(1){ rotate_f(); delay(); breaks(); delay(); rotate_b(); delay(); breaks(); delay(); } } void rotate_f(){ L293D_A = 1; L293D_B = 0; L293D_E = 1; } void rotate_b(){ L293D_A = 0; L293D_B = 1; L293D_E = 1; } void breaks(){ L293D_A = 0; L293D_B = 0; L293D_E = 0; }

//Forward run funtion //Backward run function //Motor stop function //Some delay //Our main function //Infinite loop //Run forward //Some delay //Stop //Some delay //Run Backwards //Some delay //Stop //Some delay //Do this infinitely

//Make positive of motor 1 //Make negative of motor 0 //Enable L293D

//Make positive of motor 0 //Make negative of motor 1 //Enable L293D

//Make positive of motor 0 //Make negative of motor 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++); }
Previous Page | Next Page

As you can see in the circuit, three pins are needed for interfacing a DC motor (A, B, Enable). If you want the o/p to be enabled completely then you can connect Enable to VCC and only 2 pins needed from controller to make the motor work. As per the truth mentioned in the image above its fairly simple to program the microcontroller. Its also clear from the truth table of BJT circuit and L293D the programming will be same for both of them, just keeping in mind the allowed combinations of A and B. We will discuss about programming in C as well as assembly for running motor with the help of a microcontroller.

You might also like