The Programmable VESTA Microcontroller Board
Introduction:
The Vesta SBC88A is a microcontroller board which uses an Intel 8088 processor. You will
be using it to control your LegoBot. Add-on hardware designed by Nate Myers is provided
with the microcontroller to drive the motors and to provide easy-to-use input ports for
the sensors. Since the microprocessor on the board is an i8088, the assembly language is
the same as that for the desktop PCs. Therefore, you may use any compiler (such as
Microsoft C) or any assembler (such as MASM) on your PC to develop programs for the
microcontroller. Here are some relevant specifications on the Vesta SBC88A:
| Processor:
| Intel 8088
|
| Speed:
| 4 MHz
|
| EPROM:
| 8K bytes
|
| RAM:
| 24K bytes
|
| Digital inputs:
| Two 8-bit ports (10H and 20H)
|
| Digital Outputs:
| Two 8-bit ports (10H and 20H)
|
| Bit-addressable inputs:
| Seven bits (OH through 6H)
|
| Bit-addressable Outputs:
| Seven bits (OH through 6H)
|
| Analog inputs:
| Eight channels, 8-bit resolution
|
| Serial Communications:
| One RS-232 port, 110-4800 baud, software UART
|
| Size:
| 5.5" x 4.5"
|
| Power Requirements:
| +5V
|
The add-on hardware has enough circuitry to support the following input and output devices:
3 DC motors
1 servo motor
2 infrared receivers
2 phototransistors (light sensors)
4 reflective object sensors
2 potentiometers
4 DIP switches
4 microswitches (bump sensors)
The remainder of this document describes how to use the microcontroller to control the
motors and receive input from the sensors.
Connecting Devices to the Microcontroller
Figure 1
shows a top-view diagram of the microcontroller board. Use this diagram to plug
the motors and sensors into the correct ports. All of the ports are either 2-pin, 3-pin,
or 4-pin ports. Ports where one of the pins is highlighted are directional, and one
should take care to plug the device in correctly. The highlighted pin denotes pin 1;
the devices also have some sort of marking to denote pin 1.
In the early stages of your design, try to place the microcontroller in an easily
accessible location on the robot since you will be modifying the connections often.
Also try to place the microcontroller as close to the center of the robot as you
possibly can so that the length of the wires which reach out to the sensors and motors
can be kept at a minimum. Keep in mind that your robot must be large enough and
sturdy enough to support the microcontroller, the motor battery pack, and the
AA battery pack.
Reading the Value of a Digital Sensor
Digital sensors return either 0 or 1. Each digital sensor is connected directly to a
single bit of one input port. To read data in from a digital input port, one should
use [inp] in C language or [in] in Assembly language. Then one must mask out the
appropriate bits. When using [inp] in C language one should data types of insigned char.
The following snippets of code demonstrate how to read the status of microswitch
(bump sensor) #3, which is located on port 20H, bit 6.
In C language:
unsigned char bump3;
bump3 = inp (0X20)
// 0x means hexadecimal notation
if ((bump3 & 0x40) == 0) // 0x40 = bit 6 0100 0000
// microswitch #3 is depressed
else
// microswitch #3 not depressed
In Assembly language:
IN AL, 20h
AND AL, 01000000b
; ^ particular switch to look at
CMP AL, 0
JNE MS1
MS0: ;microswitch depressed
JMP EXIT
MS1: ;not depressed
EXIT: ;...
Reading the Value of an Analog Sensor
Analog sensors return a voltage between 0V and 5V. This voltage is converted by an
analog-to-digital (A/D) converter to a byte value between 0 and 255. The Vesta
microcontroller has eight analog input channels. Reading the value of an analog is
slightly more complicated. We must first write to port 10H to "tell the microcontroller
which channel we wish to read from (only the least 3 significant cant bits are important).
Then we must write a 0 to port 30H to initiate the conversion. Approximately
200 microseconds later, the digital byte can be read from port 30H. To write a value
to a port, one should use [outp] in C language or [out] in Assembly language. When using
[outp] in C language, one should data types of unsigned char. Notice that when one writes
to port 10H, the motor speeds of DC motors 1 and 2 will be affected. So it will be
important to set output port 10H back to its original value after the analog read is
complete. The following snippets of code demonstrate how to read the current position
of potentiometer #2, located on analog channel 3.
In C language:
unsigned char pot2;
int delay;
outp (0x10, 3); // channel 3
outp (0x30, 0); // init
for (delay = 0; delay < 10; delay++); // short delay
pot2 = inp (0x30); // get value
// pot2 now has a value between 0 and
// 255 depending on the position of
// potentiometer #2.
In Assembly language:
; set channel 3
MOV AL, 3
OUT 10h, AL
; initiate conversion
MOV AL, 0
OUT 30h, AL
; wait cycles
MOV CX, 30
DELAY: LOOP DELAY
; get value
IN AL, 30h
; register AL now has a value
; between 0 and 255 depending
; on the position of
; potentiometer #2
Writing to the Motor Ports
Each DC motor is controlled by a combination of two ports. One of the ports is used to
control the speed of the motor, and the other is used to control the direction of the
motor. The speed of each DC motor is a 4-bit value, with 0 being the slowest speed
(essentially off) and 15 being the fastest speed. The direction is a single bit value
with 0 being forward and 1 being reverse. The following snippets of code demonstrate
how to set the speed of DC motor 1 to about 50% (speed value = 7) and set it running
forward. The speed of motor 1 is located on port 10H, bits 0-3. The direction of motor 1
is located on port 0H.
In C language:
outp ( 0x10, 0x07 );
// notice that we have simultaneously
// set DC motor 2 (which is Iocated at
// port 10H, bits 4-7) to a speed of 0.
outp (0x00, 0); // motor forward
In Assembly language:
; set speed
MOV AL, 07h
OUT 10h, AL
; set direction
MOV AL, 0
OUT 00h, AL
The servo motor is controlled by a 4-bit value which is directly proportional to the
desired angle. Using this microcontroller, the servo motor has a total of approximately
90 degrees of rotation. One cannot control the speed of the servo motor; it moves at a
fixed low speed with hign torque. The following snippets of code demonstrate how to set
the servo motor to roughly 45-degrees. The servo will move there slowly and stop
automatically when it gets there. The servo is located on port 20H, bits 4-7.
In C language:
outp (0x20, 0x70);
// notice that we have simultaneously
// set DC motor 3 (which is located
// at port 20H, bits 0-3 to a speed of 0.
In Assembly language:
MOV AL, 70h
OPT 20h, AL
Downloading Your Program to the Microcontroller
Once you have written your program in C language or Assembly language, you will need
to compile it or assemble it into an executable file. This file gets downloaded to
the RAM in the microcontroller through a serial cable using a program called RDEB.
A step-by-step process is given below it is recommended that you create batch files
for steps 2 and 3 as you will be performing these two steps frequently.
1) Make sure that your PATH environment variable contains the following directories:
C:\C600\BIN
C:\C600\BINB
C:\CTR20\BIN
Also make sure that your LIB environments variable contains these directories:
C:\C600\LIB
C:\CTR20\LIB
There is a program called SETENV.BAT in the C:\CTR20 directory which sets these
variables for you.
2) If you have written in a C language program called mp6.c, compile and link it:
(cl /zi /Od /c mp6.c)
link st+mp6,mp6,,sctr_m /map /co /noe;
The file st.obj must be in the current directory for this to work. It has been
placed in the C:\CTR20 directory for your convenience.
If you have written an Assembly language program called mp6.asm assemble and link it:
masm mp6.asm;
3) Turn the power for the microcontroller on (reset it if power was already on), and make
sure the serial cable is connected between the microcontroller serial port and the COM1
port of the PC. If you are using an HP Vectra 386 machine, run the RDEB software by
typing the following command:
rdeb /BP=0 /sbc=2000 /com1 /B4800 mp6
If you are using a Pentium machine, type the following command:
rdeb /BP=0 /sbc=FFFF /com1 /B4800 mp6
4) Begin downloading your code by typing the following command within RDEB
load mp6
5) When the code is done downloading, type g to run the program on the microcontroller.
At this point, you may disconnect the serial cable unless your program uses the
serial port to communicate with the PC (i.e. printf) To quit out of RDEB,
press and type q
6) To save on batteries, turn the microcontroller off whenever it is not in use
(i.e. when you are editing your code).
Serial communication
Since the robots you are building must be entirely autonomous, there is actually no
need for any kind of serial communication once the program is running on the robot's
microcontroller. However, for debugging purposes, it might be useful to be able to
communicate with the PC (assuming you leave the serial cable still connected even after
you are done downloading your program). There are a few ways to communicate with the PC:
1) If you are writing your program in C language, then you may use the standard printf
subroutine to send output to the computer monitor, even if the code is running on the
microcontroller. The reason this works is that the standard printf routine is replaced
by another routine which sends the output through the serial port of the Vesta to the PC.
As long as RDEB is still running on the PC, the output will appear on the monitor.
The following snippet of C code demonstrates how one might use printf:
unsigned char reflective1;
while (1) {
reflective1 = get_reflective sensor (l);
// This subroutine would, of course
// have to be written.
printf ("The reflective value is %d\n",
reflective1);
}
2) Another way to send data out from the Vesta to the PC is by using interrupt 10H.
This technique will not work with RDEB running on the PC. Therefore, after you
have downloaded your program to the microcontroller, you must exit RDEB and run
a terminal program such as PROCOMM or TELIX or another program which can receive
data from the serial port. However, if the serial cable is still connected when
you try to quit RDEB, Then RDEB will try to "kill" the program running on the
microcontroller. So here are the steps you must follow: connect the serial cable,
run RDEB, download your code, type g, disconnect the serial cable, quit RDEB
( and q), run PROCOMM, and reconnect the serial cable. The program running
on the PC (i.e. PROCOMM) should be set to send/receive at 4800 baud. The following
snippets of code demonstrate how to send the character '*' through the serial port
from the Vesta to the PC using interrupt 10H.
In C language
union REGS regs;
regs.h.al = (unsigned char) '$';
regs.h.ah = 14;
int86 (0X10, ®s, ®s);
In Assembly language:
MOV AL, '$'
MOV AH, 14
INT 10h
3) Finally, one can also receive characters from the PC keyboard by using interrupt 16H.
Again, this will not work with RDEB running; there must be a terminal program or
other software running on the PC which can transmit characters through the serial port
at 4800 baud. The following snippets of code demonstrate how to read in a character
from the PC keyboard:
In C language:
union REGS regs;
regs.h.ah = 0;
int86 (0X16, ®s, ®s);
// regs.h.al now contains the
// ASCII code of the key pressed
if (regs.h.al == 'F')
robot_forward ();
if (regs.h.al == 'B')
robot_backward ();
In Assembly language:
MOV AH, 0
INT 16h ; AL now contains
; the ASCII code
; of key pressed
CMP AL, 'F'
JE FORWRD
CMP AL, 'B'
JE BAKWRD
The Potentiometers
A potentiometer is used to measure rotation. The shaft of the potentiometer can be
interfaced directly to a gear on your robot to perhaps measure the position of an arm.
It is an analog sensor which will return a value of 0 at one extreme and 255 at the other.
The microcontroller has two potentiometer ports which can be read from analog input
channels 3 and 5.
The Reflective Object Sensors
The reflective object sensor, OPB730F, can measure how reflective a surface is in the
infrared range. For example, you could use this sensor to detect when your robot is over a
black surface am opposed to an orange surface since the orange surface reflects more. This
sensor is an analog sensor which returns approximately 45 for complete reflection and 255
or zero reflection. In order for the sensor to work it must placed approximately
1/16" to 1/8") from the surface you are trying to measure. The distance from the surface
WILL affect the reading, so the separation must be made consistent. The reflective object
sensors are mounted on red and blue Lego pieces. The microcontroller has four reflective
object sensor ports which can be read from analog input channels 0, 2, 4, and 6.
The Phototransistors
The phototransistors, MRD370, can measure the intensity of visible light reaching it.
They are highly directional (they must be pointed directly at the light source to
detect it). One possible use for the phototransistor is to place a light bulb (which
is always lit) directly across from it, and use the sensor to detect when an object
(e.g. a ping-pong ball) has come in the way. The phototransistor is an analog sensor
which reads 0 when no light reaches it and higher values (up to 255) depending on the
amount of light reaching it. The microcontroller has two phototransistor ports which
can be read from analog ports 1 and 7.
The Infrared Receivers
The infrared receivers detect light only in the infrared range at 40kHz. They can receive
from a wide range of directions, and so they may need to be shielded with some type of
a tunnel-shaped device around it. They are digital sensors which return 1 when not
receiving IR and 0 when receiving IR. The microcontroller has two IR receiver ports
which can be read from digital port 10H, bits 4 and 6.
The DIP switches
The DIP switches, which are mounted directly on your microcontroller can be used to
set options or modes for your robot. They return digital values of 0 when closed and 1
when open. The microcontroller has four DIP switches which you can use as inputs. They can
be read from digital port 20H, bits O, 1, 2, and 3.
The Microswitches
The microswitches, or bump sensors, are simply low-force switches which are excellent for
detecting collisions with obstacles. They return digital values 0 depressed and 1 when
depressed. The microcontroller has four microswitch ports which can be read from digital
port 20H, bits 4, 5, 6, and 7.
The Hexadecimal Display
The hexadecimal display is mounted directly on the microcontroller, and can be used for
debugging purposes or however you see fit. It can display hexadecimal values from 0 to F.
To display a hexadecimal number, you must do four separate writes to ports 3H, 4H, 5H,
and 6H. The following table summarizes how this works:
| Port 6H
| Port 5H
| Port 4H
| Port 3H
| Hex Display
|
| 1
| 1
| 1
| 1
| 0
|
| 1
| 1
| 1
| 0
| 1
|
| 1
| 1
| 0
| 1
| 2
|
| 1
| 1
| 0
| 0
| 3
|
| 1
| 0
| 1
| 1
| 4
|
| 1
| 0
| 1
| 0
| 5
|
| 1
| 0
| 0
| 1
| 6
|
| 1
| 0
| 0
| 0
| 7
|
| 0
| 1
| 1
| 1
| 8
|
| 0
| 1
| 1
| 0
| 9
|
| 0
| 1
| 0
| 1
| A
|
| 0
| 1
| 0
| 0
| B
|
| 0
| 0
| 1
| 1
| C
|
| 0
| 0
| 1
| 0
| D
|
| 0
| 0
| 0
| 1
| E
|
| 0
| 0
| 0
| 0
| F
|
To save on batteries, you may turn the hexadecimal display off when you are not using it
by flipping one of the DIP switches located on the microcontroller
(see Figure 1).
The DC Motors
The microcontroller supports three DC motors and can drive them forward or backward at
any of sixteen different speeds. A speed of 0 will essentially turn the motor off, and a
speed of 15 will turn the motor on at its top speed.
The Servo Motor
The microcontroller supports one high-torque servo motor. A servo motor can be commanded
to go to any angle (within its range). It will start moving towards that position at a
fixed speed and will stop automatically when it gets there. Setting the servo port to 0
will send it to one extreme, and setting it to 15 will send the servo to the other extreme.
The two extremes are approximately 90 degrees apart.
Resources
The following resources are available for your use if you have questions, comments,
suggestions, or problems. They are also quite useful if you would like to explore certain
topics m greater detail.
Spring 1995 LegoBot staff:
Dennis Culley, Doug Gerwitz, Rajeev Goel, Matt Merten, Nate Myers, John Knapowski,
Jonathan Kua
ECE291 7A 's
Dennis Culley, Joseph Gebis, John Knapowski, Brandon Long, Nate Myers, Doug Stirrett
ECE 291 Professor:
Professor W. Kent Fuchs
Robotics Newsgroup: comp.robotics
Type "nn comp.robotics" from your EWS account for a discussion of current problems
and discoveries in robotics. Many of the active users of this newsgroup have built Lego
robots.
Robotics Mailing List robot-board@oberon.com
To subscribe to this mailing list, send e-mail to "listserv@oberon.com" with a subject
of "subscribe robot-board your name". Discussions on this mailing list range from topics
like Lego robots to different types of sophisticated sensors.
M.I.T.6.270 Course Manual
The 1992 and 1994 versions of M.l.T.'s 6.270 course manual are located in the ECE 291
lab. This is the course at M.l.T. which has inspired many universities (including U of I
now) to develop courses where students design Lego robots. The course manual contains
oodles of useful information.
Mobile Robots -- Inspiration to Implementation
This book, by Joseph L. Jones and Anita M. Flynn, is also located in the ECE 291 lab,
and is a very well written book. It contains examples of robots, many of which are
built from Lego parts.
Robot-Building Lab and Contest at the 1993 National Al Conference
This is an article by Carl Kadie which describes his experiences when he participated in a
Lego robot contest sponsored by AAAI,
Vesta Hardware Manual
The beige binder contains more detailed information about the Vesta SBC88A
microcontroller you are using. It is actually rather poorly written and somewhat cryptic
in nature, but might still be of some use with enough patience.
C-Thru-ROM User's Manual
This manual contains information on how to use RDEB, the software we use to download
programs to the microcontroller. It also supposedly allows you to debug the code while it
is running on the microcontroller, but this feature has never been exploited yet.
Document History
4/5/95 Rajeev Goel document created
4/9/95 Rajeev Goel errors fixed, sensor information and cheezy pictures added
Copyright © 2001 by Nick Shin. All Rights Reserved.
These pages are designed by ESTSS.