Specifications

44
applies to the motor to be run. The byte moved is between $00 and $FF and is the
percentage high time of the duty cycle of the pulse used to control the speed. A value of
$FF will be full time on, hence maximum speed, and $00 will be full time low, hence
not moving at all. The value $A0 has been chosen from physical observation to define
the desired speed as smooth but reasonable pace.
*************DRIVE FORWARDS*********************************************
DRFWD MOVB #$A0, PWDTY0 ;DUTY CYCLE FOR CHANNEL 0|
MOVB #$A0, PWDTY2 ;DUTY CYCLE FOR CHANNEL 2| **DRIVE
FORWARDS
RTS ;RETURN FROM SUBROUTINE
4.6.5 Turning subroutines
The subroutines used to turn in either the left or right direction are very similar and
hence only one subroutine will be detailed. The TURNL code is explained in the
following.
Before the robot will turn left, several sensors are checked to ensure the turn signal was
not generated by noise and also to ensure there are no objects in the direction of turn.
Firstly the front sensor is checked repeatedly to ensure it is definitely set and that the
signal was not generated by noise. This is done by loading a number into index register
X and then looping that number of times, checking the sensor and decrementing X each
loop. If at any time the sensor does not read triggered, the instruction to turn left will be
aborted and the program will return to the main loop. Once the loop has been executed
X times and is guaranteed to be a legitimate turn request, the left sensor is checked to
ensure there is room to turn. If the left sensor is clear the code proceeds with a left turn.
If not clear the code branches to the turn right subroutine.
In order to turn left, a duty cycle value is written to the left wheel PWDTY register in
order to turn it backwards. The odometer for motor A is cleared and watched in a tight
loop until it reaches the specified number of turns relative to a right angle turn. Running
the motors from an 11V power supply proved decimal 90 counts to be a 90 degree turn.
This takes into account the wind down time of the motor (the inertia continues the
wheel turning for a small time after voltage is turned off). Once the robot has come to a
halt after turning, it continues on a forward path. Between all of the direction changing