Anda di halaman 1dari 54

GOKARAJU RANGARAJU INSTITUTE OF

ENGINEERING AND TECHNOLOGY (G.R.I.E.T)

LINE FOLLOWING ROBOT

MINIPROJECT DOCUMENTATION

1
TABLE OF CONTENTS

1. PROJECT INTRODUCTION
1.1 Introduction/Application areas
1.2 Required Components and Equipments.

2. DESIGN
2.1 Block Diagram and Description
2.2 Schematic
2.3 Board File

3. PROGRAMMING
3.1 Explanation of special pur pose registers
3.2 Code

4. TOOLS USED
4.1 AVR studio/Win AVR/AVRGCC
4.2 C Code
5. CONCLUSION

2
1. PROJECT INTRODUCTION

1.1 INTRODUCTION

What is a line follower?


Line follower is a machine that can follow a path. The path can be visible
like a black line on a white surface (or vice-versa) or it can be invisib le like
a magnetic field.

Why build a line follower?


Sensing a line and maneuvering the robot to stay on course, while constantly
correcting wrong moves using feedback mechanism forms a simple yet
effective closed loop system. As a programmer you get an opportunity to
‘teach’ the robot how to follow the line thus giving it a human-like property
of responding to stimuli.

APPLICATION AREAS:

Practical applications of a line follower :


1.Automated cars running o n roads with embedded magnets
2.Guidance system for industrial robots moving on shop floor

PREREQUISITES:

Knowledge o f basic digital and analog electronics.


(A course on Digital Design and Electro nic Devices & Circuits would be
helpful)
C Programming
Sheer interest, an inno vative brain and perseverance!

3
1.2 REQUIRED COMPONENTS AND EQUIPMENTS

The functional requirements o f t he project are:

Microcontroller Atmega 85 15

Roboco n Kit.

IR Sensors

RS-232 Cable.

Win AVR and AVR Studio software.

4
2. DESIGN

2.1 BLOCK DIAGRAM

SAMPLE TRACK

5
DESCRIPTION

INPUT SYSTEM:

Sensor Circuit:

General Description:

The TSOP-OBSD–Single is a general purpose proximit y sensor.


Here we use it for following a line. The module consist of a IR
emitter and TSOP receiver pair. The high precision TSO receiver
always detects a signal of fixed freq uency. Due to this, errors due to
false detectio n of ambient light are significantly reduced.
The mod ule consists of 555 IC, working in astable multivibrator
configuration. The output of TSOP is high whenever it receives a
6
fixed frequency and low otherwise. The on-board LED indicator
helps user to check status of the sensor without using any additional
hardware.The power consu mption of this module is low. It gives a digital
output and false detectio n due ambient light is low.

Functional Block Diagram /Schematic Diagram:

7
Overview of Schematic:

The 555 is used as a astable multivibrator. The frequency of the 555 is tuned
using the potentiometer. The outputof 555 is given to the IR transmitter.
TSOP detects a freq uency o f 38 KHz. The output of TSOP goes low when it
receives this frequency. Hence t he output pin is normally high because,
though the IR LED is co ntinuouslytransmitting, due to no white line,
nothing is reflected back to the TSOP. The indication LED is off.When an
white line is encountered, the output o f TSOP goes low, as the required
frequency is reflected fro m the white line. This o utput is connected to the
cathode of the LED, which then t urns ON.

INFRA-RED SENSOR

Introduction

8
An LED is usually a small area source, often with extra optics added
to the chip that shapes its radiation pattern. LED's are often used as small
indicator lights on electro nic devices and increasingly in higher power
applicatio ns such as flashlights and area lighting. The color of t he emitted
light depends o n the composition and condition of t he semiconducting

material used, and can be infrared (IR LED), visible, or near-ultraviolet. An


LED can be used as a regular household light source.

Use of 555 Timer:

The 555 timer is used as an astable multivibrator t hat generates a


pulse o utput with time period ‘T’.

Frequency, f = 1/(.693 x C1 x (R1 + 2 x R2))

Example:
R1 = 10K
R2 = 10k

C1 = 100uF
F = ~ 0.48 Hz
T= ~ 2 sec
This generates an outp ut pulse with a time period 2sec.

9
555IC as an AstableMultivibrator

TSOP Module

Pin Diagram of a TSOP Module

Description

The TSOP17.. – series are miniaturized receivers for infrared remote


control systems. PIN diode and preamplifier are assembled on lead frame,
the epoxy package is designed as IR filter. The demodulated output signal

10
can directly be decoded by a microprocessor. TSOP17..is the standard IR
remote contro l receiver series, supporting all major transmission codes.

Block Diagram

Block Diagram of TSOP Module

Circuit Diagram of IR Sensor

11
Working of IR Sensor

12
PROCESSING SYSTEM:

Micro Controller:

Micro-contro ller kit is constructed with ATMEGA 8515 Micro -


controller chip. The ATMEGA 8515 is a low power, high performance

CMOS 8-bit microco ntroller with 8 K bytes of flash memory. Its high density
non-volatile memory compatible with standard AVR instruction set makes
it a powerful controller that pro vides highly flexible and cost effective
solutio n to contro l app licatio ns.Micro -cont roller wo rks according to the
program written in it. Micro-contro llers are “embedded” inside some other
device so that they can control the features or actions of the prod uct.
Anot her name for a micro -controller therefore is “embedded controller”.

Micro-co ntrollers are dedicated to o ne task and run one specific pro gram.

Pin config uration of Atmega8515

13
Features

• High-performance, Low-p ower AVR® 8-bit Microcontroller

• RISC Architecture
– 130 Powerful Instructions – Most Single Clock Cycle Execution
– 32 x 8 General Purp ose Working Registers
– Fully Static Operation
– Up to 16 MIPS Throughput at 16 MHz
– On-chip 2-cycle Multiplier

• Nonvolatile Program and Data Memories


– 8K Bytes of In-System Self-programmable Flash
Endurance: 10,000 Write/Erase Cycles
– Optional Boot Code Section with Independent Lock bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
– 512 Bytes EEPROM
Endurance: 100,000 Write/Erase Cycles
– 512 Bytes Internal SRAM
– Up to 64K Bytes Optional External Memory Space
– Pro gramming Lock for Software Security

• Peripheral Features
– One 8-bit Timer/Counter with Separate Prescaler and Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and
Capture mode
– Three PWM Channels
– Pro grammable Serial USART
– Master/Slave SPI Serial Interface
– Pro grammable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analo g Comparator

• Special Microcontro ller Features


– Power-on Reset and Pro grammable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrup t Sources
– Three Sleep Modes: Idle, Power-down and Standby
• I/O and Packages
14
– 35 Programmable I/O Lines
– 40-pin PDIP, 44-lead TQFP, 44-lead PLCC, and 44-pad QFN/MLF

• Operating Voltages
– 4.5 - 5.5V for ATmega8515

• Speed Grades
– 0 - 16 MHz for ATmega8515

MOTOR OUTPUT SYSTEM :


Introduction

Motor Drivers are the ICs used to drive motors when interfaced with
Microcontrollers. These ICs give a higher voltage output ranging from 4.5V
to 36V for logic 1 input. The mo tor driver ICs generally used L293D,
ULN2003 series, etc.

These ICs are used to drive bot h DC mo tors and stepp er motors.

L293D IC

The L293 and L293D are quadrup le high -current half-H drivers. The
L293 is designed to pro vide bidirectio nal drive currents of up to 1 A at

voltages from 4.5 V to 36 V. The L293D is designed to provide bidirectional


drive currents of up to 600-mA at vo ltages from 4.5 V to 36 V. Bot h devices
are designed to drive inductive loads such as relays, solenoids, dc and
bipolar stepping motors, as well as other high -current/high-vo ltage loads in
positive-supply applications.

15
All inp uts are TTL compatible. Each output is a complete totem-po le
drive circuit, with a Darlington transistor sink and a pseudo-Darlingto n
source. Drivers are enabled in pairs, with drivers 1 and 2 enabled b y 1,2EN
and drivers 3 and 4 enabled by 3,4EN. When an enable input is high, the
associated drivers are enabled and their outputs are active and in phase with

their inputs. When the enable input is lo w, those drivers are disabled and
their outputs are off and in the high-impedance state. With the proper data
inputs, each pair of drivers forms a full-H (or brid ge) reversible d rive
suitable for solenoid o r moto r applications. On the L293, external high -
speed output clamp diodes should be used for inductive transient
suppression. A VCC1 terminal, separate from VCC2, is provided fo r the
logic inputs to minimize device power dissipation. The L293 and L293D are

characterized for operation from 0°C to 70°C.

16
Pin Diagram

Block Diagram

Block Diagram of a Motor Controller

17
Circuit Diagram

Circuit Diagram for Motor Controller (L293D

NOTE

Here the inp ut pins 2, 7 and their respective output p ins 3, 6 are enabled by
enabling EN1 i.e. giving vcc to pin 1

Similarly, t he input pins 10, 5 and their respective p ins 11, 4 are enabled by
enabling EN2 i.e. giving vcc to p in 9.

18
SERIAL COMMUNICATION:

RS-232 is simp le, universal, well understoo d and supported but it


has some serious shortcomings as a data interface. The standards to 256kbps
or less and line lengths of 15M (50 ft) or less but today we see high speed
ports o n our ho me PC running very high speeds and with high q uality cable
maxim distance has increased greatly. The rule of thumb for the length a
data cable depends on speed o f the data, quality of the cable

This is a standard 9 pin cable layout for async data on


a PC AT serial cable

19
20
USART:

The Universal Synchronous and Asynchronous serial Receiver and


Transmitter
(USART) is a highly flexib le serial communication device.

The main features are:


•Full Duplex Operation (Independent Serial Receive and Transmit

Registers).
• Asynchronous or Synchronous Operation.
• Master or Slave Clocked Synchro nous Operatio n.
• High Resolution Baud Rate Generator.
• Suppo rts Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits.
• Odd or Even Parity Generation and Parit y Check Supported by Hardware.

• Data Overrun Detection.


• Framing Error Detection.
• Noise Filtering Includes False Start Bit Detection and Digital Low Pass
Filter.
• Three Separate Interrupts on TX Complete, TX Data Register Empty, and
RX
Complete.

• Multi-p rocessor Communication Mode.


• Double Speed Asynchro no us Communication Mode.

21
AVR USART vs. AVR UART –Compatibility:

The USART is fully compatible with t he AVR UART regarding:


• Bit locatio ns inside all USART Registers
• Baud Rate Generation
• Transmitter Operatio n
• Transmit Buffer Functio nalit y
• Receiver Operation

However, the receive buffering has two impro vements that will affect
the compatibility in some special cases like

•A second Buffer Register has been added. The two Buffer Registers
operate as acircular FIFO b uffer. Therefore the UDR must o nly be read once

for eachincoming data. More important is the fact that the Error Flags (FE
and DOR) and the ninth data bit (RXB8 ) are buffered wit h t he data in the
receive b uffer. Therefore the status b its must always be read before the UDR
Register is read. Otherwise the erro r status will be lost since the buffer state
is lost.
•The Receiver Shift Register can now act as a third b uffer level. This is done
byallowing the received data to remain in t he serial Shift Register (see

Figure 64) if the Buffer Registers are full, until a new start bit is detected.
The USART is therefore more resistant to Data Overrun (DOR) error
cond itions.

The following control bits have changed name, but have same functionality
and register location:
22
• CHR9 is changed to UCSZ2
• OR is changed to DOR

Internal Clock Generation – The Ba ud Rate Generator:

Internal clock generation is used fo r the asynchronous and the

synchronous master modes o f operation. The USART Baud Rate Register


(UBRR) and the down-co unter connected to it function as a programmable
presale or baud rate generator. The down-counter, running at system clock
(FOSC), is loaded with the UBRR value each time the counter has counted
down to zero o r when the UBRRL Register is written. A clock is generated
each time the counter reaches zero. This clock is the baud rate generator
clock output (= FOSC/(UBRR+1)) . The Transmitter divides the baud rate

generator clock output b y 2, 8, or 16 depend ing on mode. The baud rate


generator output is used direct ly by the Receiver’s clock and data recovery
units. However, the recovery units use a state machine t hat uses 2, 8, or 16
states depending o n mode set by the state of the UMSEL , U2X , and
DDR_XCK bits.

Table: 2.5.2 Calculation of baud rate and UBRR value as per Operating modes
23
Note: 1. The baud rate is defined to be the transfer rate in bit per second
(bps).
BAUD Baud rate (in bits per second, bps)
fOSC System Oscillator clock frequency
UBRR Co ntents of the UBRRH and UBRRL Registers, (0 -4095)

POWER SUPPLY UNIT:

The req uired dc power supply for the proper operat io n o f


microcontroller and its circuitry is derived from the power supply module.
This power supply unit consists of a adapter fo r the step -down o f voltage to
12V from 230 vo lts. Rectifier circuit is used for converting this 12 V AC
into 12 V DC. Regulator circuit is used fro regulating the obtained DC. Input

to this b lock is fed fro m one phase 230V AC 50 Hz mains line.

24
BOARD DIAGRAM:

Block Diagram of 8515 Microcontroller Board

25
2.2 SCHEMATIC:

26
2.3 BOARD:

Board Diagram of the designed 8515 Microcontroller board


27
3. SOFTWARE DETAILS

3.1 EXPLANATION OF SPECIAL PURPOSE REGISTERS :

USART Control a nd Status Register A - UCSRA

Bit 7 RXC : receive comp lete ; bit is set when unread data is in receiver
buffer
Bit 5 UDRE: UART Data Register Empty

USART Control a nd Status Register A – UCSRB

Bit 4 RXEN : Receiver Enable bit


Bit 3 TXEN : Transmitter Enable bit

USART Control a nd Status Register A – UCSRC

28
The UCSRC Register shares the same I/O locatio n as the UBRRH Register.

3.2 AT90S8515(AVR) Instruction set:

The Assembler accepts mnemonic


instruct ions fro m the instruction set A
summary of the instruction set mnemonics
and their parameters is given here. For a
detailed description of the instruction set,
refer to the AVR Data Book.

Arithmetic and Logic Instructions

Mnemonic Operands Description Operation Flags Cycles


ADD Rd,Rr Add without Carry Rd = Rd + Rr Z,C,N,V,H,S 1
ADC Rd,Rr Add with Carry Rd = Rd + Rr + C Z,C,N,V,H,S 1
ADIW Rd, K Add Immediate To Word Rd+1:Rd,K Z,C,N,V,S 2
SUB Rd,Rr Subtract without Carry Rd = Rd - Rr Z,C,N,V,H,S 1
SUBI Rd,K8 Subtract Immediate Rd = Rd - K8 Z,C,N,V,H,S 1
SBC Rd,Rr Subtract with Carry Rd = Rd - Rr - C Z,C,N,V,H,S 1
SBCI Rd,K8 Subtract with Carry Immedtiate Rd = Rd - K8 - C Z,C,N,V,H,S 1
AND Rd,Rr Logical AND Rd = Rd · Rr Z,N,V,S 1
ANDI Rd,K8 Logical AND with Immediate Rd = Rd · K8 Z,N,V,S 1
OR Rd,Rr Logical OR Rd = Rd V Rr Z,N,V,S 1
ORI Rd,K8 Logical OR with Immediate Rd = Rd V K8 Z,N,V,S 1
EOR Rd,Rr Logical Exclusive OR Rd = Rd EOR Rr Z,N,V,S 1
COM Rd One's Complement Rd = $FF - Rd Z,C,N,V,S 1
NEG Rd Two's Complement Rd = $00 - Rd Z,C,N,V,H,S 1
SBR Rd,K8 Set Bit(s) in Register Rd = Rd V K8 Z,C,N,V,S 1
CBR Rd,K8 Clear Bit(s) in Register Rd = Rd · ($FF - K8) Z,C,N,V,S 1

29
INC Rd Increment Register Rd = Rd + 1 Z,N,V,S 1
DEC Rd Decrement Register Rd = Rd -1 Z,N,V,S 1
TST Rd Test for Zero or Negative Rd = Rd · Rd Z,C,N,V,S 1
CLR Rd Clear Register Rd = 0 Z,C,N,V,S 1
SER Rd Set Register Rd = $FF None 1
SBIW Rdl,K6 Subtract Immediate from Word Rdh:Rdl = Rdh:Rdl - K 6 Z,C,N,V,S 2

Branch Instructions:

Mnemonic Operands Description Operation Flags Cycles


RJMP k Relative Jump PC = PC + k +1 None 2
IJMP None Indirect Jump to (Z) PC = Z None 2
STACK = PC+1, PC = PC +
RCALL k Relative Call Subroutine None 3/4*
k+1
ICALL None Indirect Call to (Z) STACK = PC+1, PC = Z None 3/4*
RET None Subroutine Return PC = STACK None 4/5*
RETI None Interrupt Return PC = STACK I 4/5*
CPSE Rd,Rr Compare, Skip if equal if (Rd ==Rr) PC = PC 2 or 3 None 1/2/3
CP Rd,Rr Compare Rd -Rr Z,C,N,V,H,S 1
CPC Rd,Rr Compare with Carry Rd - Rr - C Z,C,N,V,H,S 1
CPI Rd,K8 Compare with Immediate Rd - K Z,C,N,V,H,S 1
if(Rr(b)==0) PC = PC + 2 or
SBRC Rr,b Skip if bit in register cleared None 1/2/3
3
if(Rr(b)==1) PC = PC + 2 or
SBRS Rr,b Skip if bit in register set None 1/2/3
3
Skip if bit in I/O register if(I/O(P,b)==0) PC = PC + 2
SBIC P,b None 1/2/3
cleared or 3
if(I/O(P,b)==1) PC = PC + 2
SBIS P,b Skip if bit in I/O register set None 1/2/3
or 3
if(SREG(s)==0) PC = PC +
BRBC s,k Branch if Status flag cleared None ½
k+1
if(SREG(s)==1) PC = PC +
BRBS s,k Branch if Status flag set None ½
k+1
BREQ k Branch if equal if(Z==1) PC = PC + k + 1 None ½
BRNE k Branch if not equal if(Z==0) PC = PC + k + 1 None ½
BRCS k Branch if carry set if(C==1) PC = PC + k + 1 None ½
BRCC k Branch if carry cleared if(C==0) PC = PC + k + 1 None ½
BRSH k Branch if same or higher if(C==0) PC = PC + k + 1 None ½
BRLO k Branch if lower if(C==1) PC = PC + k + 1 None ½
30
BRMI k Branch if minus if(N==1) PC = PC + k + 1 None ½
BRPL k Branch if plus if(N==0) PC = PC + k + 1 None ½
Branch if greater than or equal
BRGE k if(S==0) PC = PC + k + 1 None ½
(signed)
BRLT k Branch if less than (signed) if(S==1) PC = PC + k + 1 None ½
BRHS k Branch if half carry flag set if(H==1) PC = PC + k + 1 None ½
Branch if half carry flag
BRHC k if(H==0) PC = PC + k + 1 None 1/2
cleared
BRTS k Branch if T flag set if(T==1) PC = PC + k + 1 None ½
BRTC k Branch if T flag cleared if(T==0) PC = PC + k + 1 None ½
BRVS k Branch if overflow flag set if(V==1) PC = PC + k + 1 None ½
Branch if overflow flag
BRVC k if(V==0) PC = PC + k + 1 None ½
cleared
BRIE k Branch if interrupt enabled if(I==1) PC = PC + k + 1 None ½
BRID k Branch if interrupt disabled if(I==0) PC = PC + k + 1 None ½

Data Transfer Instructions:

Mnemonic Operands Description Operation Flags Cycles


MOV Rd,Rr Copy register Rd = Rr None 1
LDI Rd,K8 Load Immediate Rd = K None 1
LDS Rd,k Load Direct Rd = (k) None 2*
LD Rd,X Load Indirect Rd = (X) None 2*
LD Rd,X+ Load Indirect and Post-Increment Rd = (X), X=X+1 None 2*
LD Rd,-X Load Indirect and Pre-Decrement X=X-1, Rd = (X) None 2*
LD Rd,Y Load Indirect Rd = (Y) None 2*
LD Rd,Y+ Load Indirect and Post-Increment Rd = (Y), Y=Y+1 None 2*
LD Rd,-Y Load Indirect and Pre-Decrement Y=Y-1, Rd = (Y) None 2*
LDD Rd,Y+q Load Indirect with displacement Rd = (Y+q) None 2*
LD Rd,Z Load Indirect Rd = (Z) None 2*
LD Rd,Z+ Load Indirect and Post-Increment Rd = (Z), Z=Z+1 None 2*
LD Rd,-Z Load Indirect and Pre-Decrement Z=Z-1, Rd = (Z) None 2*
LDD Rd,Z+q Load Indirect with displacement Rd = (Z+q) None 2*
STS k,Rr Store Direct (k) = Rr None 2*
ST X,Rr Store Indirect (X) = Rr None 2*
ST X+,Rr Store Indirect and Post-Increment (X) = Rr, X=X+1 None 2*

31
ST -X,Rr Store Indirect and Pre-Decrement X=X-1, (X)=Rr None 2*
ST Y,Rr Store Indirect (Y) = Rr None 2*
ST Y+,Rr Store Indirect and Post-Increment (Y) = Rr, Y=Y+1 None 2
ST -Y,Rr Store Indirect and Pre-Decrement Y=Y-1, (Y) = Rr None 2
ST Y+q,Rr Store Indirect with displacement (Y+q) = Rr None 2
ST Z,Rr Store Indirect (Z) = Rr None 2
ST Z+,Rr Store Indirect and Post-Increment (Z) = Rr, Z=Z+1 None 2
ST -Z,Rr Store Indirect and Pre-Decrement Z=Z-1, (Z) = Rr None 2
ST Z+q,Rr Store Indirect with displacement (Z+q) = Rr None 2
LPM None Load Program Memory R0 = (Z) None 3
IN Rd,P In Port Rd = P None 1
OUT P,Rr Out Port P = Rr None 1
PUSH Rr Push register on Stack STACK = Rr None 2
POP Rd Pop register from Stack Rd = STACK None 2

Bit and Bit-test Instructions:

Mnemonic Operands Description Operation Flags Cycles


LSL Rd Logical shift left Rd(n+1)=Rd(n), Rd(0)=0, C=Rd(7) Z,C,N,V,H,S 1
LSR Rd Logical shift right Rd(n)=Rd(n+1), Rd(7)=0, C=Rd(0) Z,C,N,V,S 1
Rotate left through Rd(0)=C, Rd(n+1)=Rd(n),
ROL Rd Z,C,N,V,H,S 1
carry C=Rd(7)
Rotate right through Rd(7)=C, Rd(n)=Rd(n+1),
ROR Rd Z,C,N,V,S 1
carry C=Rd(0)
ASR Rd Arithmetic shift right Rd(n)=Rd(n+1), n=0,...,6 Z,C,N,V,S 1
Rd(3..0) = Rd(7..4), Rd(7..4) =
SWAP Rd Swap nibbles None 1
Rd(3..0)
BSET s Set flag SREG(s) = 1 SREG(s) 1
BCLR s Clear flag SREG(s) = 0 SREG(s) 1
SBI P,b Set bit in I/O register I/O(P,b) = 1 None 2
CBI P,b Clear bit in I/O register I/O(P,b) = 0 None 2
Bit store from register
BST Rr,b T = Rr(b) T 1
to T
Bit load from register to
BLD Rd,b Rd(b) = T None 1
T
SEC None Set carry flag C =1 C 1
CLC None Clear carry flag C=0 C 1
SEN None Set negative flag N=1 N 1

32
CLN None Clear negative flag N=0 N 1
SEZ None Set zero flag Z=1 Z 1
CLZ None Clear zero flag Z=0 Z 1
SEI None Set interrupt flag I=1 I 1
CLI None Clear interrupt flag I=0 I 1
SES None Set signed flag S=1 S 1
CLN None Clear signed flag S=0 S 1
SEV None Set overflow flag V=1 V 1
CLV None Clear overflow flag V=0 V 1
SET None Set T-flag T=1 T 1
CLT None Clear T-flag T=0 T 1
SEH None Set half carry flag H=1 H 1
CLH None Clear half carry flag H=0 H 1
NOP None No operation None None 1
SLEEP None Sleep See instruction manual None 1
WDR None Watchdog Reset See instruction manual None 1

The Assembler is not case sensitive.

The operands have the following forms:


Rd: Destination (and source) register in the register file.
Rr: Source register in the register file.
b:Constant (0-7), can be a constant expression.
s:Constant (0-7), can be a constant expression.
P: Constant (0-31/63 ), can be a constant expressio n.
K6: Constant (0 -63), can be a constant expression.

K8: Constant (0 -255), can be a constant expression.


k:Constant, value range depending on instructio n .Can be a constant
exp ression.
q: Constant (0-63), can be a constant expression.
Rdl: R24, R26, R28, R30. For ADIW and SBIW instructions.
X,Y,Z: Indirect address registers (X=R27 :R26, Y=R29:R28, Z=R31:R30).

33
4.TOOLS USED:

4.1 AVR studio/Win AVR/AVRGCC

Introduction to AVR

AVR studio is an Integrated Develop ment Enviro nment (IDE) fo r


writing and deb ugging AVR applications. Currently as a code writing
environment, it sup ports the included AVR Assembler and any external

AVR GCC compiler in a complete IDE environment. AVR Studio supports


the complete range of ATMEL AVR too ls and each release will always
contain the latest updates for both the tools and supp ort o f new AVR
devices. AVR Studio 4 has a modular architecture which allows even more
interaction wit h 3rd party software vendors.

ATMEL , the company that makes the AVR microcontrollers also


provides a utility called AVR Studio which will help you to d o all these

tasks.

Using AVR Studio as an IDE gives you 2 main advantages:

1. Edit and debug in the same application windows. Faster error


track ing.
2. Breakpoints are saved and restored between sessio ns, even if

code are edited

34
Save and Open Projects

All projects are saved with yo ur selected name with the ending APS .
When the user wants to reopen a pro ject, this can be done under the file
menu and the recent ly used file list, or under the project menu, open project.

Project output view

After build ing, assembling o r compiling the project, the build output

window prompts with messages. If any errors occur, the user can double-
click on the message, and the marker will show correct position in the source
window.

Startup wizard

The startup wizard is displayed every t ime yo u start AVR Studio 4.


Fro m within this dialog you can quickly reopen the latest used projects,
change debug platform/device setup or create a new pro ject. Just double-

click on the wanted project and it will automatically open and restore to its
last settings.

New project

Doub le-click on the AVR Studio icon on your Desktop

35
The following screen opens up:

36
Click on New Project tab in the pop-up windo w and the following screen
opens up.

37
Click on AVR GCC in Project .

The following screen opens up. Type in the name of your project –
myleds. Check the boxes ‘Create file’ and ‘Create Folder’. Creating
separate folders for d ifferent pro jects will help you maintain them properly.
Since the folder does not exist, AVR Studio will pro mpt you saying, the
folder does not exist and it will create a new folder. Say ‘yes’ to this prompt.

Click on Finish .
38
Device selection
We have to select which device we are going to use , in this project
we use AVR Simulator as debug platform and AT mega 8515 as device.

39
AVR Stud io creates a folder called myleds in the path specified by
you and a project named myleds.aps and a source file named myleds.c

Key in t he blinking.c program. Click o n the File Save icon. Now you
have written Ccode, you need to compile the p rogram. For this, you need to
select the microcontroller and the sp eed at which it works. The
microcontroller we are using is ATmega8515 and the speed at which it is
working is 8MHz .These two parameters are set as follows in the Project
Options in Device and Frequency optio ns.

40
The Project Options screen opens up by clicking on the Edit Current
ConfigurationOptions ico n.

41
Now, that we have set the Project Options, we will comp ile it. This can be
done by clicking on the Build Active Configuration icon.

Or yo u can go t he Build option under the Build tab.

When the Build is successful, you are intimated that the Build has gone
through with 0 warnings. This display will be in the Build Window.

42
If there are errors, you will need to correct those and do a Build again. The

Build will create many files, but the one we are interested in will be the
.hex file. This is a file whichcan be downloaded to the GRIET trainer kit and
executed

Generally the program for the required application is written in edit plus and
stored with ‘.c’ extension. The WINAVR cd provides some example
programs. Fro m that copy any one o f the bat file (generally they are with

.bat extension).
Let the program written by us be name.c .Now copy any one of bat file
provided in WINAVR cd and replace its name by name.bat. Now editing has
to be done by rep lacing led by name and now the batch file looks like
AVR-gcc-g-oc-mmcu=atmega85 15 -c-name.c
AVR-gcc-g--mmcu=atmega8515-c-o name.out,name.o
AVR-objcopy-j.text-O ihex name.outname.hex

The batch file created can be run by doub le clicking it and thereb y we find
3 files name.hex,name.out,name.o. Now o pen the AVRstudio software and
click o n the tools b utton as shown in the figure above (only after connecting
the b oard to the cpu). The AVRPROG soft ware comes with one o f the tools
supplied with AVRstud io.
If the board is

not connected
properly we wil
receive a
message as
follows:

43
This message ind icates
that the board is not
detected. Check once
again the connector and
reset the IC properly (the
IC can be reset by

click ing simultaneously


SW1 switch and power
slid ing switch). Next
click the AVRPROG
executable file, now we
can see the window as
shows:

Click on the Browse


button and select the hex
file name.hex. Click the
program button to load the program onto the target device box shows the
target controller to which the AVRPROG selected to advanced optio ns can
be viewed but the user is not allowed to change the settings, which damage

the Boot loader.


Now the pro gram is loaded in to the target.
To run the program in the contro ller, power off the controller and switch it
on after some seconds (say 2 seconds) and hence after the microcontroller
works on t he required app lication present in name.c.

44
Program to toggle the LEDs

/* Program to toggle the LEDs


The two LEDs are connected to portd pins pd6 and pd7
The LED1 is switched on first and after sometime LED2 is switched on */

#include<avr/io.h>

void main()
{
inti,j;
DDRD=0xff; //to make port d o utput for LEDs
PORTD=0xff; //making all LEDs Off
while(1)
{

PORTD=0x7f; //LED1 is switched on and LED2 o ff


for(i=0;i<500;i++)
for(j=0;j<2500;j++); //delay
PORTD=0xbf; //LED1 is o ff and LED2 is on
for(i=0;i<500;i++)
for(j=0;j<2500;j++);

}
}

45
Program for Buzzer

/* pro gram to so und the b uzzer


buzzer is connected to p in pd4 of po rtd*/

#include<avr/io.h>

void main()
{
unsigned char status;
inti,j;
DDRD=0xff; //making as output for buzzer
PORTD=0Xff; //internal pull ups
while(1)

{
PORTD=0xef; //buzzer switched off
for(i=0;i<200;i++)
for(j=0;j<200;j++);// delay
PORTD=0xff; //buzzer on
for(i=0;i<200;i++)

for(j=0;j<200;j++);
}
}

46
Program for Motor

/* pro gram for driving the motor in forward and reverse directions
motor1 are connected to portb p ins 0 and 1
differential input to the pins causes the motor to rotate*/

#include<avr/io.h>
void main()
{
inti,j;
DDRB=0xff; //for driving the motors making the portb as outp ut.
PORTB=0xff; //internal pull ups
while(1)

{
PORTB=0 xaa; //mak ing motor turn in forward directio n
for (i=0; i<10000;i++)
for(j=0;j<10000;j++); //delay
PORTB=0 x55; //making motor turn in reverse direction
for (i=0; i<10000;i++)

for(j=0;j<10000;j++);
}
}

47
Program for Sensors

Program for IR Sensor

/* IR sensor interfacing with LEDs


IR sensor ret urns logic 0 when obstacle is detected

Program t o switch on the LEDs if anything is detected by the IR senso r


sensors are connected to port a and leds are connected to portd pins pd6
adn pd7 */

#include<avr/io.h>
void main()
{

unsigned char status;


DDRA=0x00; // making port a inp ut for taking sensor status
DDRD=0xff; //making portd output to switch o n the leds
PORTD=0xff; //making all leds off
PORTA=0xff; //for internal pullups
while(1)

{
status=PINA;
PORTD=0xff; //making LEDs off
if((status&(0x07))==0x00)
PORTD=0x3f; //making LEDs on
}
}

48
Programs to interface sensor and motors

/* pro gram to interface sensors and to drive motors depending on sensor


status
Port a is used to interface sensors and port b to drive the motors */

#include<avr/io.h>
#include<avr/delay.h>
void delay();
void main()
{
DDRB=0xff;
DDRA=0x00;

DDRD=0xff; //making portd as output to glow LEDs and


buzzer
PORTA=0xff;
PORTB=0xaa;
delay();
while(1)

{
if((PINA&0x01)==0x00)
{
PORTD=0x3f;//leds and buzzer on
PORTB=0 x11;//left
delay();
PORTB=0xaa;//forward

49
delay();
PORTB=0 x22;//right
delay();
PORTB=0 xaa;//forward
delay();
PORTD=0xef;//leds and b uzzer off

}
else PORTB = 0xaa;
}
}

void delay()
{

int i,j;
for(i=0;i<6000;i++)
for(j=0;j<6000;j++);
}

50
4.2 C CODE:

/* LINE FOLLOWING ROBOT


PortA : 0 0 0 0 0 0 s2 s1
PortB : R R L L 0 0 0 0
PortC : Switch Pin2
PortD : L1 L2 0 B 0 0 0 0 */

#include<avr/io.h>
int main()
{
DDRA=0x00; //Sensor Input
DDRB=0xff; //Motor Output
DDRC=0x00; //Switches Input
DDRD=0xff; //Leds,Buzzer Output

PORTA=0xff;
PORTC=0xff;

while(1)
{
if(!(PINC&0x02))
{
51
goto x;
}
}

x: while(1)
{
while((PINA&0x03)==0x03) //STRAIGHT
{
{
PORTB=0x50;
}
}

while((PINA&0x03)==0x00) //STOP
{
{
PORTB=0x00;
}
}

if((PINA&0x03)==0x01) //RIGHT
{
PORTD=0x10; //Buzzer ON
52
while((PINA&0x03)==0x01)
{
PORTB=0x40;
}
PORTD=0xC0; //Buzzer OFF
}

if((PINA&0x03)==0x02) //LEFT
{
PORTD=0x10; //Buzzer ON
while((PINA&0x03)==0x02)

{
PORTB=0x10;
}
PORTD=0xC0; //Buzzer OFF
}
}
}

53
CONCLUSION:

It has been a great learning experience working o n our project - The Line
Follower. In this new age where the effort o f man is min imized by using
machines, the emergence of robo ts has helped improve many facets of life.
The line follower is one of those simple
yet efficient robots which are extensively used in developed industries in
transporting goods to and fro along a specific path which inturn lessens the
burden of the workers and improves the working of the ind ustry.
The main aim of o ur project was to
develo p a miniature linefollower in which we have succeeded. We look
forward to develop an industry oriented line follower where it can help
increase the efficiency of the industry.

54

Anda mungkin juga menyukai