Hi…friends , welcome back..! I am again here with some
embedded systems stuff , this time we will learn how to control motor using AVR
MCUs. Motors are very important for almost every ROBOTICS projects and other
electronics projects as well ,and using microcontroller with motors makes is very
easy. So lets have a look , how it happens..??
Introduction
As we know we can generate different output signal from our
MCU, which are used to drive the motors but the signal generated by the MCU is
not strong enough to drive the motor , so we need something else to drive the
motor as per the instruction of MCU, and this something else is a motor drive ,
there are many motor drivers available , like ULN200X family ICs , L293D and
L298 etc. here we are going to use L293D.
I will suggest you to go through my article
Before reading this article as I have discussed almost
everything in that article about L293D. ROBOTICS TUTORIAL 1- HOW TO USE L293D MOTOR DRIVER IC
Now we are pretty much clear about our task, we have to
drive a simple DC motor using AVR MCU and L293D motor driver.
Connections
So first of we have to prepare connections . just implement
this simple circuit for that. Things we are going to need are-
2 MOTORs
L293D IC
ATmega 16
And some connecting wire and power supply.
Source code
Here is sample code. The code is written to rotate two motors
in clockwise direction for some time ,then to stop one motor and rotate other
one in clockwise direction for some time and again rotate second motor in
clockwise direction and stop first one for some time ,then to rotate one motor in clockwise
direction and other one in anticlockwise direction and finally stop both the
motor. Code is self explanatory still if you are facing any problem just let me
know..:)
/*
* DRIVING_MOTOR_WITH_AVR.c
*
* Created: 2/2/2013 10:04:53 PM
* Author: ABHILASH
*/
#include <avr/io.h>
#include <util/delay.h>
void main()
{
DDRC=0b00001111; //declaring pin 0-3 of PORTC as output pins
while(1)
{
PORTC=0b00000101; // both motor in clockwise direction
_delay_ms(3000); // delay for some time
PORTC=0b00000001; // only one motor rotating in clockwise direction
_delay_ms(3000); // delay for sometime
PORTC=0b00000100; // second motor rotating in clockwise direction
_delay_ms(3000); // delay for some time
PORTC=0b00001001; // one motor in clockwise direction other one in anticlockwise
_delay_ms(3000); // delay for some time
PORTC=0b00000000; // stop
_delay_ms(3000); // delay for some time
}
}
That all now burn your microcontroller with this program and
power up the circuit and you will things going on..and you can see how easy is it to control a motor with AVR MCU.
You can download source code , .hex file and proteus design file here-
I hope this article was helpful for you guyz, in case of any
query. Doubt or critical view just leave a comment.
THNX..:)
No comments:
Post a Comment