Digchip : Database on electronics components
 
Member, Distributor  
Log In
Email:
Password:


Part: AN443

Category:

Description:

Company:

Datasheet: Download AN443 datasheet     File size : 50 kB

Request For quote: Find where to buy AN443



Datasheet text preview:
Philips Semiconductors Microcontroller Products

Application note

IEEE Micro Mouse using the 87C751 microcontroller
Author: Tracy Ching
DESCRIPTION
Micro Mouse is an IEEE contest first proposed by the author of IEEE Spectrum in 1977. It consists of an autonomous robot known as a "mouse" which navigates through a maze of 256 two-inch-high, seven-inch squares in a 16 × 16 arrangement. The robot is self powered and has no knowledge of the maze configuration prior to releasing it in the maze. The first time it is released into the maze, its prime objective is to find a path from the starting square which is located in a corner of the maze to the destination square which can be located in the center or a different corner depending on competition level. The destination square for the advanced level can be found only by using a smart algorithm which will make the mouse gravitate towards the center without becoming lost. The destination square for a novice contest can be found by using a wall hugging algorithm. The analogy for this algorithm is to imagine a blind person holding their right hand out against a wall and following the walls until they reach the destination. A maximum of ten runs or 15 minutes is given to each mouse. Leaving the starting square constitutes one run. The mouse with the fastest run time from the starting square to the destination square wins. The contest is held with different competition levels for novices and advanced. The novice level is typically held for college students trying to exercise newly acquired hardware and software skills, whereas the advanced level encompasses international talent and may require the implementation of a proportional integral derivative (PID) controller in software to utilize commutated or brushless DC motors and complex navigation algorithms. and sensors. The 87C751 is suitable for this application with its small size. The need for external RAM is eliminated by using the internal RAM to store minimum maze information suitable for the novice level. Nickel cadmium batteries are used because of the cost, size and power density obtainable versus other battery types. Nickel metal hydride was not available during development but would be a good choice over nickel cadmium batteries.

AN443

sensor bank via the 74LS04 (U4) and the MOSFETs. Each sensor bank hangs over the two inch high walls whereby the light emitted from the OP-240 is reflected into the OPL-560-OC if a wall is present. Two sensor pairs in the middle of the array are typically sensing the presence of a wall and the remaining sensors are used for guidance to keep the mouse running parallel to the walls. A 74LS573 connected to port 3 which latched data into eight LEDs was used in the debugging process. P1.7 was used on the latch signal for the 74LS573. Since the eight LEDs and latch were not needed for the final product, they were removed thus reducing weight and battery drain. LEDs D1 and D2 were also used in the debugging process and are currently used for visual feedback when selecting options during operation. Power for the digital circuitry is fed by an 8.4 volt NiCAD battery pack, packaged in a 9 volt battery case, via a 7805 regulator. The circuit can run constantly with the sensors taking "snapshots" of the walls intermittently for at least 30 minutes satisfying the 15 minute maximum requirement. Power for the motors is fed by four "A" size NiCAD cells which have enough energy to run the motors for 15 minutes before becoming useless at about 1 volt per cell.

The 87C751 Microcontroller
The 87C751 is an 8-bit microcontroller based on the 8051 microcontroller family. It is code compatible with the exception of the MOVX, LJMP, and LCALL instructions. The MOVX instruction and external memory accesses are not supported. LJMP and LCALL instructions are not needed since AJMP and ACALL can reach the entire program memory range (2k bytes) of the 751. The 87C751 contains a 2k × 8 EPROM, a 64 × 8 RAM, 19 I/O lines, a 16 bit auto-reload counter/timer, a fixed rate timer, a five source fixed priority interrupt structure, a bidirectional Inter-Integrated circuit (I2C) bus interface, and an internal oscillator. The 87C751 comes in an erasable quartz package (87C751), one time programmable (87C751), and mask ROM (83C751).

HARDWARE DESCRIPTION
Figure 1 is a schematic diagram of the mouse. The stepper motors are 4 volts 0.95 amperes per coil giving about 14 oz-inches of torque. Each motor is driven by an Allegro UCN-5804B unipolar stepper motor translator/driver which contains the sequencing logic and high current darlington outputs. The sequencing logic only requires clock, direction of rotation, and output enable signals from the 87C751 which relieves the chore of having to cycle through a sequencing table for both motors therefore reducing code size. Fast recovery diodes are used to protect the darlington outputs from negative voltage due to motor winding flyback. The infrared (IR) emitters are Optek OP-240A. The sensors are Optek OPL-560-OC which have a built-in light amplifier and TTL open collector output. Each sensor bank is enabled via a high side P-channel MOSFET. A 74LS04 (U4) is used to drive the P-channel MOSFET. Data from each bank of eight IR sensors is fed into port 3. By using open collector output sensors, the need for latching the data using a 3-State buffer is eliminated. Port pins P0.0 and P0.1 are used for enabling either the left or right

TASK PRIORITIES
Several tasks take place during program execution which are as follows in order of importance: pulsing the stepper motors according to a velocity profile table, gathering sensor data, deciding whether to accelerate, decelerate, turn left or right. In-line coding is used to avoid calling subroutines that cause the program counter to be pushed onto the stack and use valuable RAM for the turn decisions. Interrupt subroutines are an exception. Interrupt timer 0 (T0) vectors to the routine which supplies a pulse to the stepper motor drivers. This is the most important task because the stepper motors require a smooth train of pulses in order to prevent jerky or sporadic motions. Thus, T0 must have the highest priority and must not be interrupted. Although timer 0 is a 16 bit timer, only eight bits are used with the higher byte set to FFH. T0 takes care of pulsing the left and right motor drivers at different times by using two external registers which are used as prescalers. Each motor can be assigned a different prescale value via the assigned register in order to step each motor at a different step rate.

DESIGN OBJECTIVES
Several design objectives were as follows: minimize weight, minimize part size and count, minimize power consumption which allows the use of smaller and lighter batteries, minimize cost and maximize speed. The main objective was to keep the total weight at a minimum to obtain the fastest acceleration from the stepper motors and to reduce wheel slippage during deceleration and turning. The objectives are inter-related such that changing one will affect the other. Hence, having a low part count means lighter weight, faster acceleration and lower cost. A typical mouse may consist of a microcontroller with supporting memory and GLU logic to interface the motor controllers

June 1993

1

Philips Semiconductors Microcontroller Products

Application note

IEEE Micro Mouse using the 87C751 microcontroller

AN443

The velocity profile table for T0 was designed using a spreadsheet program with visual graphing. This aided the ability to derive an exponential table for the fastest stepper motor acceleration using qualitative observations. The first part of the in-line code contains the routine to accelerate the mouse from a stopped position. A pointer for each motor is incremented until the end of the velocity profile table is reached. During acceleration, the left and right sensors are strobed and stored after each step caused by T0. The routine that strobes the sensors for wall data returns several results through the use of flags. The routine first stores the sensor data in registers. This information is used to determine if the sensor array or mouse is too far right, left, or aligned in a square and to set the corresponding flags. It also returns the presence of a front wall using the innermost sensor pairs. The deceleration routine is similar to the acceleration routine except the pointers decrement through the velocity profile table skipping a few values each time. Deceleration uses less steps than acceleration. The routine which decides whether to continue acceleration, deceleration, or turn left or right keeps track of step count or position of the mouse within a square in order to store wall information at the proper time. After the previous routines have stored the data for the front, left, and right walls, a decision is obtained. If the mouse is not in a back-up mode, the wall information, status of the back-up flag and left/right algorithm flag forms an offset byte. If the mouse is in a back-up mode, the decision from above plus the previous decision on the stack is used to form the offset byte. This offset is stored in the accumulator. The decision which contains the direction to turn is obtained using the MOVC instruction which points to the table using the data pointer. The logic table is shown in Tables 1 and 2 below. External interrupt 0 (INT0) vectors to the routine which brings the mouse to a halt. INT0 subroutine disables T0, sets output enable high on the stepper motor drivers, and sets the return address for the program counter to 0000H. This causes the mouse to restart program execution without losing the internal RAM.

Table 1. Logic Table: Non-Back-Up Mode
(1) R R R R R R R R L L L L L L L L (2) NONE F R R, F L L, F L, R L, R, F NONE F R R, F L L, F L, R L, R, F (3) R R S L R R S 180 L L L L S R S 180 (4) push R onto stack push R onto stack push S onto stack push L onto stack push R onto stack push R onto stack ignore turn on B-U flag push L onto stack push L onto stack push L onto stack push L onto stack push S onto stack push R onto stack ignore turn on B-U flag

Table 2. Logic Table: Back-Up Mode
(1) R R R L L L S S S (2) R L S R L S R L S (3) R L S R L S R L S (4) push S onto stack, clear B-U pop stack only push L onto stack, clear B-U pop stack only push S onto stack, clear B-U push R onto stack, clear B-U push L onto stack, clear B-U push R onto stack, clear B-U pop stack only

NOTES: Abbreviations used: R = right L = left F = front S = straight B-U = back-up flag stack = RAM used for storing decisions (not for the program counter) Non back-up mode: (1) wall hugging algorithm (user selected) (2) walls surrounding present square (3) direction to turn (4) operations to perform

NOTES: Abbreviations used: R = right L = left F = front S = straight B-U = back-up flag stack = RAM used for storing decisions (not for the program counter) Back-up mode: (1) previous decision from top of stack (2) decision from the above table for this current square (3) direction to turn (should be equal to (2) (4) operations to perform (all operations require lowering the stack by one before pushing data)

June 1993

2

Philips Semiconductors Microcontroller Products

Application note

IEEE Micro Mouse using the 87C751 microcontroller

AN443

OPERATION Reset
True reset is accomplished only during power on. After completing the maze, the operator brings the mouse to a stop using the start/stop switch which effectively disables the motors and resets the program counter to 0000H, restarting the mouse's program with the exception that the RAM contains vital maze information.

a wall or incurring a condition in the stepper motors called "pull-out". Pull-out is a condition wherein the fields are changing in the coils faster than the rotor can maintain synchronism with the coils, causing the rotor to stall.

SOFTWARE LIMITATIONS
The 87C751 has 64 bytes of RAM. The program requires 31 bytes of RAM leaving 33 bytes for storing decisions. One hundred thirty two decisions can be stored in 33 bytes of RAM since four decisions are stored per byte. Although there are 16 times 16 squares with possibly 256 decisions to be made, this condition is not very probable since every square typically is not made into a turning point. Long straight ways are used as well as turning points. The probability that the RAM will fill to the maximum capacity is very slim in the novice level where there are typically 50 decisions to be made. Hence, RAM which can hold 132 decisions is adequate but not infallible.

the center of the maze would add about 800 bytes more of code. Since some of the code for the novice class would be eliminated, it would bring the total code size to less than 2k bytes. A few maze solving algorithms have been implemented successfully on other mice. These are the flooding or Bellman's algorithm, backtracking algorithm and others. The first two algorithms are recursive, thus the code sizes are quite small. Another added feature would be the ability to execute a rounded turn rather than pivot. This requires a more complex navigation scheme and velocity profiler to make the motors turn at differing speeds in order to make the rounded turn. In addition to the enhancements aforementioned, methods to track a wall through the use of an A/D converter which measures the reflectivity strength from infrared sensors pointing at the sides of the walls can also be implemented on the I2C bus. This would eliminate the array of sensors hanging in front of the mouse on top of the walls thus decreasing the weight.

Starting/Stopping
After power-up, the mouse remains idle with the motors and sensors disabled, awaiting an interrupt from switch SW1. The first time the switch is pressed, the mouse will start. The second time the switch is pressed, the mouse will stop and the cycle repeats.

Selecting right or left wall hugging
After power on reset, the program defaults to right wall hugging. Pressing switch SW2 will cause the mouse to follow the left walls. If it is pressed again, it will follow the right walls-- toggling between the left and right wall hugging algorithm each time it is pressed.

FUTURE ENHANCEMENTS
Although the 87C751 has minimal RAM, I2C RAM could be easily added by switching the MOSFET drivers using the LED port pins and placing the I2C RAM on port pins P0.0 and P0.1. This would allow the implementation of a full mapping algorithm thus allowing entry to the advanced class. The code size for the I2C routines and recursive algorithm to find

Increasing motor speed
After completing the first run, pressing switch SW2 causes the timer value to increase by an index of one, increasing the speed of the motors. This allows the mouse to be run at increasing speeds each run in order to attain the fastest possible time before crashing into

CONCLUSION
The 87C751 microcontroller provides the required computing resources and I/O ports necessary to control a robotics device known as a "Micro Mouse". The I2C interface allows for an abundance of variations on this robotics device.

June 1993

3

Philips Semiconductors Microcontroller Products

Application note

IEEE Micro Mouse using the 87C751 microcontroller

AN443

VCC C6 10µF left sensor enable R10 8.2K VCC U10C right sensor enable 5 6 9

U10A 1 2 3

U10B 4

Q2 MOSFET P left IR sensor bank

74LS04 U10D 8 VCC

R7 1.2K D1 Right

R8 1.2K D2 Left Q1 MOSFET P X1 11 OPL560­OC 6 7 P0.2 P0.1 P0.0 P1.7 / T0 P1.6 / INT1 P1.5 / INT0 P1.4 P1.3 P1.2 P1.1 P1.0 X2 16 MHz 10 22pF 3 VCC 2 OUT 1 GND VCC

87C751
9 RST

OPL­240A

LEFT/ RIGHT

8 SW2 20 19

5 P3.0 4 P3.1 3 P3.2 2 P3.3 1 P3.4 23 P3.5 22 P3.6 21 P3.7

STOP

SW1

3 VCC 2 OUT 1 GND

18 17 16 15

3 VCC 2 OUT 1 GND 3 VCC 2 OUT 1 GND

VMM

14 13 R2 0.8 2W 1 2 3 4 5 6 7 8

U2 P1 V1 P2 GND GND P3 V1 P4 /OE DIR GND GND STEP HALF GND 15 14 13 12 11 10 9 U4 LM7805 VI 8.4V POWER DPST GND C5 10µF VO VCC

3 VCC 2 OUT 1 GND

3 VCC 2 OUT 1 GND

M1 4V 0.95A Stepper

UCN5804 BT1 SW3

3 VCC 2 OUT 1 GND 3 VCC 2 OUT 1 GND

VMM

R4 0.8 2W 1 2 3 4 5 6 7 8 M2 4V 0.95A Stepper

U3 P1 V1 /OE P2 DIR GND GND GND GND P3 STEP V1 HALF P4 GND UCN5804 15 14 13 12 11 10 9

R5 10 ohm BT2 SW3 VMM 4.8V POWER DPST right IR sensor bank

Figure 1. Schematic Diagram of the Maze Mouse June 1993 4

Philips Semiconductors Microcontroller Products

Application note

IEEE Micro Mouse using the 87C751 microcontroller

AN443

MCS­51 MACRO ASSEMBLER LOC OBJ

751MAIN

04/16/92

PAGE

1

0008 0009 000A 000B 000C 000D 000E 000F 0010

008B 008D

0020 0000 0001 0002 0003 0004

=1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1 =1

LINE 1 2 3 4 5 6 7 8 9 +1 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

SOURCE ;******************************************************** ; 87C751 Micro Mouse version 4.0 started 9­27­91 * ; version 4.3 finished 4­16­92 * ; Algorithms and programming by Tracy Ching * ; Some symbols commented out for use as in­line coding * ; rather than being used as subroutines (S.R.) * ;******************************************************** $include (751.equ) ;These are all RAM addresses ;equate table of constants ;ind_reg equ 00 ;map_org equ 01 ; equ 02 ; equ 03 ; equ 04 ; equ 05 ; equ 06 ; equ 07 step_count temp_reg1 ls373 count_fw l_timr r_timr l_ptr r_ptr map_offset ; equ ; equ ; equ ; equ ; equ ; equ ; equ ;PCON ;TA rtl rth EQU EQU equ equ equ equ equ equ equ equ equ equ equ 11h 12h 13h 14h 15h 16h 17h 87H 0C7H 8bh 8dh 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h

;used for ind addr of regs ;pointer for storing map of maze ;decide storage­local, ;do180, turn90 use it ;snapshot R wall storage ;snapshot L wall storage ;store_val, decel, int 1, gen purp ;pause setting, gen purp ;step count used by decide ; ;storage for 74LS373 debug data leds ;count for wall, step count ;value to be used in the isr ; ;points at accel table ; ;points to the specific two bits in map ptr

;flag declarations, they are erased after every restart ss_bits equ 20h ;sens flag reg too_r bit 20h.0 ;too close to right wall too_l bit 20h.1 ; left wall r_wall bit 20h.2 ;right wall present, snapshot storage l_wall bit 20h.3 ;left wall present, snapshot storage f_wall bit 20h.4 ;front wall present, snapshot storage

June 1993

5




Others parts begin by an
AN-1   AN-2   AN-3   AN-4   AN-5   AN-6   AN-7   AN-8