ABLab
Solutions
PWM Based DC Motor Driver
Interfacing With ATmega16
(L293D)
1
ABLab
Solutions
Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005
Website: www.ablab.in | E-m...
ABLab
Solutions
Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005
Website: www.ablab.in | E-m...
ABLab
Solutions
Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005
Website: www.ablab.in | E-m...
ABLab
Solutions
Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005
Website: www.ablab.in | E-m...
ABLab
Solutions
Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005
Website: www.ablab.in | E-m...
ABLab
Solutions
Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005
Website: www.ablab.in | E-m...
ABLab
Solutions
Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005
Website: www.ablab.in | E-m...
Upcoming SlideShare
Loading in …5
×

Pwm based dc motor driver interfacing with avr atmega16 microcontroller(l293d) Circuit diagram and C program/ C code ablab solutions

7,298 views
6,875 views

Published on

Published in: Technology, Business

Pwm based dc motor driver interfacing with avr atmega16 microcontroller(l293d) Circuit diagram and C program/ C code ablab solutions

  1. 1. ABLab Solutions PWM Based DC Motor Driver Interfacing With ATmega16 (L293D) 1
  2. 2. ABLab Solutions Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005 Website: www.ablab.in | E-mail: info@ablab.in | Ph: 91-674-6573832 Table of Contents Project Description........................................................................................................3 Hardwares Required......................................................................................................3 Softwares Required.......................................................................................................3 C Program......................................................................................................................4 Connection Guide..........................................................................................................7 Update Yourself.............................................................................................................8 2
  3. 3. ABLab Solutions Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005 Website: www.ablab.in | E-mail: info@ablab.in | Ph: 91-674-6573832 Project Description In this project, we will interface a PWM Based DC Motor Driver (L293D) with ATmega16 microcontroller to drive a robot in different speeds. Here the DC Motor Driver will help the robot to move forward with different voltages. The direction of the robot depends on the connection of Robot Connector with the Output Header of the DC Motor Driver. Hardwares Required  AVR Trainer Board-100-1pcs  AVR USB Programmer-1pcs  12V DC Adapter-1pcs  DC Motor Driver-1pcs  1 to 1 Connector-3pcs  10 to 10 FRC Female Connector-2pcs  Robot-1pc  USB AM-AF Cable (Optional)-1pcs Softwares Required  AVR Studio 4  WinAVR -2010  SinaProg Hex Downloader  USBasp Driver 3
  4. 4. ABLab Solutions Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005 Website: www.ablab.in | E-mail: info@ablab.in | Ph: 91-674-6573832 C Program //**************************************************************// //Microcontroller :ATmega16 //System Clock :1MHz //Project :PWM Based DC Motor Driver Interfacing With ATmega16 (L293D) //AVR Compiler :AVR-GCC 4.3.2 //Author :ABLab Solutions // :www.ablab.in // :info@ablab.in //Date :1st January 2012 //**************************************************************// #include<avr/io.h> /*Includes io.h header file where all the Input/Output Registers and its Bits are defined for AVR microcontroller*/ #define F_CPU 1000000 /*Defines a macro for the delay.h header file. F_CPU is the microcontroller frequency value for the delay.h header file. Default value of F_CPU in delay.h header file is 1000000(1MHz)*/ #include<util/delay.h> /*Includes delay.h header file which defines two functions, _delay_ms (millisecond delay) and _delay_us (microsecond delay)*/ #include<avr/timercounter0.h> /* Includes timercounter0.h where all the functions for timer/counter0 of AVR microcontroller are defined*/ #include<avr/timercounter2.h> /* Includes timercounter2.h where all the functions for timer/counter2 of AVR microcontroller are defined*/ 4
  5. 5. ABLab Solutions Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005 Website: www.ablab.in | E-mail: info@ablab.in | Ph: 91-674-6573832 void main(void) { DDRB=0x08; /* PB3 pin of PORTB is declared output */ DDRD=0x80; /* PD7 pin of PORTD is declared output */ DDRC=0x0f; /*PC0,PC1,PC2,PC3 pins of PortC are declared output ( Input header of DC Motor Driver is connected )*/ set_timercounter0_mode(3); /* set the Fast PWM mode for timer/counter0 */ set_timercounter0_prescaler(1); /* set the prescaler value as 1 for timer/counter0 */ set_timercounter0_output_mode(2); /* set the output mode as set on compare match for timer/counter0 */ set_timercounter2_mode(3); /* set the Fast PWM mode for timer/counter2 */ set_timercounter2_prescaler(1); /* set the prescaler value as 1 for timer/counter2 */ set_timercounter2_output_mode(2); /* set the output mode as set on compare match for timer/counter2 */ /*Start of infinite loop*/ while(1) { set_timercounter0_compare_value(180); /* set the compare value as 180 for timer/counter0 */ set_timercounter2_compare_value(180); /* set the compare value as 180 for timer/counter2 */ 5
  6. 6. ABLab Solutions Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005 Website: www.ablab.in | E-mail: info@ablab.in | Ph: 91-674-6573832 PORTC=0x09; /*robot will move forward*/ _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); /*4000ms delay*/ set_timercounter0_compare_value(215); /* set the compare value as 215 for timer/counter0 */ set_timercounter2_compare_value(215); /* set the compare value as 215 for timer/counter2 */ _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); /*4000ms delay*/ set_timercounter0_compare_value(255); /* set the compare value as 255 for timer/counter0 */ set_timercounter2_compare_value(255); /* set the compare value as 255 for timer/counter2 */ _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); 6
  7. 7. ABLab Solutions Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005 Website: www.ablab.in | E-mail: info@ablab.in | Ph: 91-674-6573832 _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); /*4000ms delay*/ } } /*End of program*/ Connection Guide The step-by-step procedure for PWM based DC Motor Driver interfacing with ATmega16 (L293D) are as follows:  Insert the DC Pin of 12V DC Adapter to the DC Socket of AVR Trainer Board-100.  Connect PORTC Header of AVR Trainer Board-100 with the Input Header of DC Motor Driver with a 10 to 10 FRC Female Connector.  Connect the ISP Header of AVR Trainer Board-100 with AVR USB Programmer Header with a 10 to 10 FRC Female Connector.  Connect the PWM1, PWM2, 12V pins of PWM & Motor Voltage Header of DC Motor Driver with the PB3, PD7, and 12V pins of AVR Trainer Board-100 with 1 to 1 Connectors respectively.  Connect the Robot connector to the Output Header of the DC Motor Driver.  Switch On the Mode Switch.  Connect the AVR USB Programmer to the PC/Laptop's USB Port.  Switch on the power with the help of Power Switch of AVR Trainer Board-100.  Download the PWM based DC Motor Driver interfacing with ATmega16 (L293D) Hex file to AVR Trainer Board-100.  See the result. 7
  8. 8. ABLab Solutions Sneha Palace, Plot No.60,Laxmi Vihar, Near Appolo Hospital, Bhubaneswar-751005 Website: www.ablab.in | E-mail: info@ablab.in | Ph: 91-674-6573832 Update Yourself For more Softwares, Tutorials, Sample Codes, Installation Guides, User Guides, User Manuals, Videos, Products & Components and Updates, Please Visit us at: www.ablab.in Mail us at: Info@ablab.in View us at: www.youtube.com/ablabsolutions Like us at: www.facebook.com/ablab.in Join us at: www.facebook.com/groups/ablabsolutions 8

×