programming a robot using
DESCRIPTION
This is the presentation covers many concepts about programming the microcontrollers.TRANSCRIPT
![Page 1: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/1.jpg)
PROGRAMMING A ROBOT USING
ICC AVR Ver 7.5
![Page 2: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/2.jpg)
ICC AVR ver 7.5
ICC AVR is a tool used to program Atmel microcontrollers.
It uses a C compiler to compile the high level code into a low level code.
ICC AVR then converts this low level code into HEX code.
It also has built in tools to program the flash memory of the microcontroller.
![Page 3: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/3.jpg)
HOW TO INSTALL ICC AVR ver 7.5
![Page 4: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/4.jpg)
ICC AVR ver 7.5 is not a freeware and thus you have to purchase it.
But 45 days trial versions are available on the net and they give almost the same features.
Thus download the setup of the trial version from the site : http://www.imagecraft.com/
Run the setup and install ICC AVR ver 7.5
![Page 5: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/5.jpg)
HOW TO USE ICC AVR ver 7.5
![Page 6: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/6.jpg)
![Page 7: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/7.jpg)
![Page 8: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/8.jpg)
![Page 9: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/9.jpg)
![Page 10: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/10.jpg)
![Page 11: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/11.jpg)
![Page 12: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/12.jpg)
![Page 13: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/13.jpg)
![Page 14: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/14.jpg)
![Page 15: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/15.jpg)
H BRIDGE PIN-OUT
![Page 16: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/16.jpg)
ATMEGA 16
PC2
PC3
PC4
PC5
PC6
PC7
L293D
IN1
IN2
EN1
IN3
IN 4
EN2
OUT1
OUT2
OUT3
OUT4
![Page 17: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/17.jpg)
![Page 18: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/18.jpg)
![Page 19: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/19.jpg)
![Page 20: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/20.jpg)
![Page 21: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/21.jpg)
![Page 22: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/22.jpg)
![Page 23: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/23.jpg)
![Page 24: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/24.jpg)
IMPORTANT STUFF….
![Page 25: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/25.jpg)
Input Output PORTS
• Four, 8 bit I/O ports- PORT A,B,C,D• All I/O ports pins are bidirectional and can beconfigured individually• Input pins can be configured to utilizeinternal pullups.
• Data Direction Register , DDRn
• Port Driver Register, PORTn
• Port Pin Register, PINn
![Page 26: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/26.jpg)
Data Direction Register, DDRn
• Determines the direction of individual pins ofports• If the bit of the DDR is set the corresponding pinof the port is configured as output pin• If the bit of the DDR is cleared thecorresponding pin of the port is configured asinput pin
• DDRA = 0xF0;• 4 MSB pins of PORTA are output pins• 4 LSB pins of PORTA are input pins
![Page 27: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/27.jpg)
Port Pin Register, PINn
• Reading the input pins of port is done byreading PIN register• Temp = PINA;• Read the PORTA input and store in temp variable
![Page 28: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/28.jpg)
Port Drive Register, PORTn
• For pins configured as input(DDRn[x] = 0) microcontroller connects ainternal pull up register if thecorresponding bit of PORTn is set• If the PORTn bit is cleared, pin is Tristated
• DDRA = 0x00;• PORTA = 0xF0
![Page 29: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/29.jpg)
Buzzer On / OFF
• PORT B pin 7• Pin is configured as output• DDRB= 0x80;• To turn on the buzzer output high• PORTB = 0x80;• To turn off the buzzer output low• PORTB = 0x00;
![Page 30: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/30.jpg)
Buzzer Function
void Buzzer_ON(void){PORTB = 0x80;}void Buzzer_OFF(void){PORTB = PORTB & 0x7F;}
![Page 31: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/31.jpg)
LED DISPLAY
8 bit LED display is connected to PORTD.
To display any bit combination on the LED display, we use…
PORTD=0xXX;
![Page 32: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/32.jpg)
CODE FOR LED DISPLAY
void main(void){ init_devices();
while(1) { PORTD=0xFF; }}
![Page 33: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/33.jpg)
Analog To Digital Converter• 10 bit resolution• 8 channels• PORTA(0 – 7)• Disable internal pull up• ADCH & ADCL – Data Register• ADMUX- Channel Select Register• ADCSR – Control & Status Register
![Page 34: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/34.jpg)
![Page 35: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/35.jpg)
unsigned char ADC_conversion (unsigned char ADC_channel_number) { unsigned int i = 0; ADCH = 0x00; i = ADC_channel_number & 0x0F; // keeping the loweat nibbel ADMUX = i | 0x20; //upper nibbel of 0x20 indicates the result is left adjusted (8 bit ADC conversion) ADCSR |= 0x40; for (i = 1; i < 255; i++); //delay of 93.2 uS
i = ADCH; return (i);}
void main(void){ unsigned char I, value[3];; for(i=0;i<3;i++) { value[i]=ADC_conversion(i); }}
![Page 36: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/36.jpg)
HOW TO COMPILE AND BUILD YOUR CODE
![Page 37: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/37.jpg)
![Page 38: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/38.jpg)
![Page 39: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/39.jpg)
![Page 40: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/40.jpg)
![Page 41: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/41.jpg)
![Page 42: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/42.jpg)
![Page 43: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/43.jpg)
![Page 44: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/44.jpg)
![Page 45: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/45.jpg)
![Page 46: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/46.jpg)
![Page 47: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/47.jpg)
![Page 48: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/48.jpg)
![Page 49: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/49.jpg)
![Page 50: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/50.jpg)
![Page 51: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/51.jpg)
![Page 52: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/52.jpg)
![Page 53: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/53.jpg)
After you program your robot, it is ready to run the code written onto the microcontroller.
So just power on the microcontroller and it will start the execution of the code.
![Page 54: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/54.jpg)
MOTION CONTROL AND LINE FOLLOWING
![Page 55: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/55.jpg)
PORT CONFIGURATION
PORTA is ADC port. 3 white line sensors are connected to
pin1, pin2, pin 3 of PORTA.
PORTC is connected to the H-bridge.
![Page 56: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/56.jpg)
CODE FOR MOTION
void delay(int time) { int i,j;
for(i=0;i<time;i++) for(j=0;j<500;j++);}
void backward(void) // subroutine for backward motion{ PORTC=0xB4; delay(100);}
void right(void) // subroutine for right motion{ PORTC=0xB8; delay(100);}
void left(void) // subroutine for left motion{ PORTC=0xD4; delay(100);}
void forward(void) // subroutine for forward motion{ PORTC=0xD8; delay(100);}
void stop(void) // subroutine for stop motion{ PORTC=0xFF; delay(100);}
//void main(void){ init_devices(); //insert your functional code here...
forward(); delay(1000); left(); delay(100); forward(); delay(1000); right(); delay(100); backward(); delay(1000); stop(); delay(100);
}
![Page 57: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/57.jpg)
CODE FOR LINE FOLLOWER
unsigned int ADC_conversion (unsigned int ADC_channel_number) { unsigned int i = 0; ADCH = 0x00; i = ADC_channel_number & 0x0F; // keeping the loweat nibbel ADMUX = i | 0x20; ADCSR |= 0x40; for (i = 1; i < 255; i++); //delay of 93.2 uS
i = ADCH; return (i);}
void forward(void){ PORTC=0xD8;}
void left(void){ PORTC=0xB8;}
void right(void){ PORTC=0xD4;}
void backward(void){ PORTC=0xB4;}
//void main(void){unsigned char value[3];unsigned char i; init_devices(); while(1) { for(i=0;i<3;i++) { value[i]=ADC_conversion(i); }
if (value[1] < 50) { forward(); } else { if(value[2] > 90) { left(); } else { if (value[0] > 90) { right(); } else { backward(); }} } } }
![Page 58: Programming A Robot Using](https://reader035.vdocuments.net/reader035/viewer/2022062319/554a4a76b4c905863d8b579a/html5/thumbnails/58.jpg)
THANK YOU…