Documente Academic
Documente Profesional
Documente Cultură
Project Description
The project may be divided into three main parts. Each of these parts
will then be explained in detail.
2. Interface Circuitry
3. Algorithm/Program
1. Robot Hardware:
The robot’s body was constructed using two hard plastic sheets which
were cut into circular plates. The two plates where then mounted on top of
each other using stand-off’s, creating gap in between them, which was used
to mount the battery. Two motors with gear box were used to drive the robot
using a differential wheel arrangement. The wheels were mounted on the
gear box and then entire assembly was fixed on the lower plate.
The HCS12 evaluation board was mounted on the top plate and all
circuits were designed on the prototype board provided along with the
evaluation board. Three sensors were mounted on the right hand side of the
top plate, which would help in following the right wall and one sensor was
mounted in the front to detect a wall in the front.
A picture of the robot is shown in Fig 1.
2. Interface Circuitry:
b. IR Sensor Circuit
Interface
Evaluation
Upper
Right
Lower
Battery
Motor Driver Circuit: The motor driver circuit was used to act as a
buffer between the microcontroller port and the high current motors. The IC
used as a motor driver is L293D. The pin diagram of the IC along with the
connections is shown in Fig 3. The digital control signal provided by HCS12
does not deliver sufficient current to drive the motor. Hence, a driver circuit,
which is capable of changing the direction of motor using the logic signals
and is capable of being driven at high current, is used. The IC is capable of
driving motor with voltage up to 36V.
In the above circuit, Vin is the supply voltage for the IC as well as for
the motor. D1 and D2 are the inputs which are used to control the direction
of the motor. Both D1 and D2 are TTL logic level inputs. The table below
(Table 1) shows the different combinations of D1 and D2, with its effect on
motor’s operation,
Algorithm:
START: if A<x then
{
Turn left 90 degrees
else
go to CHECK1
}
CHECK1: if C=B
{
if C=D
{
Move front
}
else
go to CHECK2
}
CHECK2: if C>B
{
Tilt Left
else
if C>D
{
Tilt Right
}
else
go to CHECK_U
CHECK_U: if A>y
{
if B>y
{
if C>y
{
if D>y
{
Perform U turn operation
}
}
}
}
else
go to START
x= optimal value derived by trial and error to define least distance of the
sensor from wall
y= optimal value derived by trial and error to define farthest distance of
the sensor from wall
Based on the algorithm defined above, the program has been written
in ALP for controlling the robot and is given in the next section,
Program:
#include reg9s12.h ; include register equates
ORG $1000
JSR openAD0 ; initialize and configure ATD0
JSR openlcd ; initialize and configure LCD
MOVB #$0F, DDRA ; Set Port A as output port
;****************************************************************************************
***********
;Check if button is pushed
;****************************************************************************************
***********
JSR START
JMP Forever
;****************************************************************************************
**********
;Algorithm Starts ....
; F -Sens1 (Front sensor)
; A -Sens2 (1st on right)
; B -Sens3 (Middle)
; C -Sens4 (Last)
;****************************************************************************************
**********
START LDD #900 ; Check if Front wall is present
CPD Adr00h
BHI Front_Detect ; If present then perform left by 90
degree operation
JSR Front ; If not present go Front
JMP Check1
Front_Detect JSR Brake
JSR Back
JSR Lefta
JSR Front
RTS
;****************************************************************************************
***********
;MOTOR DIRECTION CONTROL SUBROUTINES
;****************************************************************************************
***********
Front MOVB #$0A,PORTA
LDAA #$80 ; set DDRAM address to 0000000
JSR cmd2lcd
LDX #Front_msg ; point to 1st message character
JSR puts2lcd
LDX #85 ; Load X with 5 for counting purposes gives
460ms
JSR hlfsec
RTS
;****************************************************************************************
*************
;0.5 sec delay
;****************************************************************************************
*************
hlfsec LDY #60000 ; (60000 X 4)/24 = 10 ms
mlsec DEY
BNE mlsec
DBNE X,hlfsec
RTS
;****************************************************************************************
*************
;Reading Sensor values
;****************************************************************************************
*************
sens_ad LDD Adr00h ; get result of conversion
LDY #10 ; multiply result by 10 to be
EMUL ; able to divide it by 2046
LDX #2000 ; note! result only sitting in D
IDIV ; integer part of the result is in X
XGDX ; D has the remainder, swap them
ADDB #$30 ; make it ASCII
STAB sens1
RTS
;****************************************************************************************
***
;INITIALIZE A to D
;****************************************************************************************
***
openAD0 MOVB #$E0,ATD0CTL2
LDY #120 ; 120 X 4 / 24 = 20 us
;****************************************************************************************
***
;LCD SUBROUTINE
;****************************************************************************************
***
ad0lp DEY
BNE ad0lp
count1 RMB 1
count2 RMB 1
sens1 RMB 1
FCC ' A:'
sens2 RMB 1
FCC ' B:'
sens3 RMB 1
FCC ' C:'
sens4 RMB 1
DB 0
Front_msg FCC 'GOING FRONT '
DB 0
Back_msg FCC 'GOING BACK '
DB 0
Right_msg FCC 'GOING RIGHT '
DB 0
Left_msg FCC 'GOING LEFT '
DB 0
Uturn_msg FCC 'U TURN '
DB 0
Push_Button_msg FCC 'PUSH TO START'
DB 0
END