Micromouse Project Report
Micromouse Project Report
MICROMOUSE
Table of Contents
References ......................................................................................................... 28
The impetus for this project comes from the IEEE sponsored Micromouse Competition. Robots
participating under the official rules of the competition must solve a three meter square wooden maze by
finding a route to the center and making timed speed runs, all within an allotted time period. The robots
cannot have human feedback for solving the maze, and any intervention with the robot, for example to
replace batteries, will result in a time penalty [1].
The maze is divided into 16x16 cells, configured before the event so that competitors do not know the
layout. Robots must have the ability to sense walls and cannot touch or run into walls [1]. A great deal of
flexibility is permitted in the design of the robots, with only a few requirements specified in the official
rules.
This particular design is based on a two-wheel concept that has been used by several other groups; however
both the hardware and software are completely original.
The micromouse hardware is designed to meet IEEE Micromouse Contest Rules for Region 6 as specified
under section C – Rules for the Micromouse. In addition, we decided our particular design should call for
limited size and weight constraints, to add to the challenge of building the device.
The official rules for the micromouse require that (1) the device should be self-contained, with no remote
controls or pre-loaded maze configurations; (2) the device should not use an energy source requiring
combustible fuel; (3) the device should not leave any part of its body behind while navigating the maze; (4)
the device should not modify or damage the maze, and should not jump or fly over the maze walls; (5) the
device should not have a width x length greater than 25 cm by 25 cm; and (6) the total cost of materials
should not exceed $500.00, using market value for all components [1].
Our additional constraints specified that (1) the device should not have a width x length greater than 12 cm
by 12 cm, and height greater than 5 cm; (2) the device should be capable of speeds of up to 2 m/s and
accelerations of up to 2 m/s2; (3) the device should be capable of running off a single battery for at least 15
minutes at nominal speed; (4) the device should use surface mount technology (SMT) for at least 90% of
on-board components; and (5) the device should provide feedback to the user via an LCD display or similar
character display.
Figure 2-1 indicates the position of the ISP header, the power enable header, an 8-pin configuration header,
and a LCD backlight enable.
The micromouse uses a power regulator chip made by Maxim IC, the MAX5091 28V, 100mA high-voltage
linear regulator device. The documentation for this device is provided in /docs/max5091.pdf on the CD, or
can be found on maxim-ic.com.
The robot can be powered by a 6 to 9V voltage source if it is capable of supplying sufficient current to the
motors, as given approximately by the nominal voltage of the motor divided by its terminal resistance. The
controller circuitry of the board will draw a maximum current of 80mA with the infrared sensors and LCD
backlight on, and a minimum current of 40mA with sensors and LCD backlight off. The device will draw
approximately no current when in standby mode.
A standard 9-volt connector from J4 is provided for supplying power (between 6 and 9V) to the circuit.
The power header at JP2 is connected between EN and GND as specified in the Maxim IC documentation.
When this connection is shorted, the EN pin is pulled low and the voltage regulator goes into shutdown
mode (figure 2-2). The circuit should not leak more than 1uA when it is in the off-state.
Control of the micromouse is accomplished using the ATmega32 8-bit RISC Microcontroller produced by
Atmel. The microcontroller’s In System Programming mode is supported by bringing out the connections
to the ISP Header.
To program the microcontroller, use the AVR MkII ISP USB programmer. The 6-pin header jack J1 should
be connected as in figure 2-3(a) or (c) for proper programming. The programmer should be connected with
a USB cable (figure 2-4) from computer to micromouse, and the micromouse should be ON for
programming. Additionally, jumpers on header JP3 should be REMOVED before programming, or the
operation will fail. A green indicator light will show if the connection is properly made, figure 2-3(c), or a
blinking orange light will show if the connection is improper, figure 2-3(b).
(a) Proper connection, close-up (b) Improper connection (c) Proper connection
view
Figure 2-32: ISP Header
Please see the AVR MkII documentation available from AVR Studio’s help menu for further instructions
and troubleshooting information on programming Atmel 8-bit devices.
The robot could be permanently disabled if you make an improper fuse or lock
bit setting.
The configuration header JP3 is provided as an optional method of setting up to 16 possible configuration
modes on the micromouse. The value of the header is available on register PINB7:4 using the avr-libc
definitions available in AVR Studio. To use this feature, you can check the proper port register in software
to see if it is high. To use up to 16 states, combine the 4 bits of the port configuration header into a single
nibble and make selections based on the binary value up to 2^4 = 16 possible states (example 2-1).
int your_function_name(void)
{
…
unsigned int state;
switch (state)
{
case 0:
//example: turn on indicator led
sbi(PORTA,6);
break;
case 1:
//test LCD or something
moveToXY(0,0);
writeStringToLCD("hello!!!");
break;
default:
//turn of indicator led, clear LCD
cbi(PORTA,6);
clearLCD();
break;
}
}
Example 2-1: Using configuration header
An enable is provided for the LCD backlight so that the backlight can be turned off when battery
performance is an issue. The LCD backlight can draw up to 40mA if enabled. To enable the backlight,
connect a jumper across this header (figure 2-5).
3.1 Motors
The motors utilized in this design are Faulhaber 1524E 6V motors, with integrated encoders and gearheads,
however the device will support other types of motors of similar ratings. The hardware should support any
DC motor with nominal voltage rating of less than 9 volts and current draw less than 700mA. A Faulhaber
motor and a Portescap 16N210E motor are shown for size comparison in figure 3-2, both motors have been
tested with this hardware.
To ensure proper connection of a motor, you should refer to schematics in Section 4 and the motor
documentation, making sure that all wires match up. Figure 3-3 shows the connections for a pair of
Faulhaber 1524E motors, and table 3-1 gives the port names for motor block inputs and outputs.
Motor control is achieved using pulse width modulation (PWM). PWM is a method for producing an
adjustable average DC voltage output by adjusting the duty cycle of a modulated voltage wave at high
frequency (figure 3-4). At high frequencies a motor will “observe” the average value of the voltage at its
input, hence varying the duty-cycle of the waveform will have the same effect as using a variable DC
voltage source [2].
In our design we use the 16-bit Timer/Counter1 peripheral on the Atmega32 chip to generate an adjustable
frequency and adjustable duty-cycle PWM wave [3]. The output compare ports OC1A and OC1B on I/O
pins PD5 and PD4 respectively of the microcontroller are multiplexed into two channels that control the
two DC motors through an H-Bridge circuit. The multiplexer is a Maxim MAX4701 Dual double-pole
double-throw (DPDT) switch. Each of the two DPDT switches connects two ports INxA, INxB of the H-
Bridge to OC1x and GND based on the value of their select inputs (INx) as in figure 3-5. The effect of
changing INx from high to low is to reverse the voltage at the input of the motor.
The PWM frequency is chosen based on three factors: (1) the PWM frequency needs to be sufficiently high
to create a smooth voltage across the inductor, something above 1000Hz; (2) PWM essentially creates a
small speaker out of the motor due to the oscillations, so the frequency of the PWM needs to be sufficiently
out of the hearing range, and otherwise it creates an annoying sound during operation; (3) rapidly changing
the state of a motor, either by reversing direction, increasing speed, or turning on/off, will draw a large
amount of current, hence the H-Bridge must have charge pumps capable of supply these peak currents and
smoothing out the system response; high frequencies, above 50kHz, will reduce the current draw in the
system when it is overloaded, and should be used.
AVRLib provides a timer library for accessing the timer peripherals with the ATmega chipset. In our
software we use the PWM functions provided with the library. The functions use Timer1 in Fast PWM
Mode, with register ICR1 set as the top count, a prescaler of N=1, and 8-bit resolution. The frequency is
defined with equation 3-1. The duty cycle can be adjusted by changing the value of registers OCR1x,
between 0 and the value of TOP. Setting OCR1x to 0 will result in a small spike, and setting OCR1x to
TOP will result in a constant high output [3].
_/
An example of running motor 1 at full speed and motor 2 at half speed is given in example 3-1. AVRLib
and the timer library are used in this example, however this method has not be rigorously tested and the
programmer may want to experiment with other PWM modes on Timer1, such as Frequency and Phase
Correct PWM Mode discussed in [3].
#include "global.h"
#include "timer.h"
int your_function_name(void)
{
…
//set PWM frequency divider to 1 (e.g. run at 8MHz or clk_freq)
timer1SetPrescaler(TIMER_CLK_DIV1);
3.2 Encoders
Encoders should be integrated into any motor you decide to use, and are connected to the circuit through
the standard motor connectors shown in figure 3-2. The robot is capable of tracking individually up to
approximately 4.2 billion revolutions of each motor through an external counter chip, the Maxim DS2423.
One channel of each motor is connected to one of the two counter input on the DS2423 chip, turning the
motor shaft will cause the counter increment on rising edge of the encoder pulse. The other channel of the
encoders is not used in this design. Access to the 32 bits of each channel of counter data is provided using a
one-wire interface on the data line connected to microcontroller pin D7. An adapted AVRLib C library is
included to allow easy access to this data in software (example 3-2). For further information on how to
properly access counter registers you should refer to references [3] and [4]. The DS2423 also has 4kbits of
SRAM, which can be accessed through the one-wire interface, see [4] and Section 3.6.
#include "global.h"
#include "timer.h"
#include "onewire.h"
int your_function_name(void)
{
uint8_t MCNT[4] = {0};
…
ow_reset();
ow_reset();
3.3 Sensors
The robot can navigate in a properly lighted environment, such as a maze, with the four onboard infrared
sensors. Each sensor block is comprised of an infrared emitter, the Vishay TSAL6100 device, and a
phototransistor, Vishay BPV11F (figure 3-5). The phototransistor’s collector is connected to an analog-to-
digital converter input on the microcontroller, while the infrared LED is directly controlled by an output
port on the microcontroller.
The sensors work on the basis of reflection: an infrared led is turned on, emitting light in the infrared
spectrum, and a reading is made with an adjacent photo transistor and corresponding ADC unit (figure 3-6).
The value that is read varies unpredictably with differing materials, but when used to determine distance
from a constant type of material, it remains steady under normal indoor lighting conditions, and thus is
adequate for navigation in a controlled environment. The material should be sufficiently non-diffusive so
that an adequate amount of light will reflect back to the sensors. Light from adjacent emitters will not pose
a problem if the sensors are used properly, since the phototransistors have a 15 degree field-of-view, and
the emitters can be independently switched. A calibration routine can be created to set up threshold values
for the robot to allow it to predict approximately where adjacent walls are located. Fuzzy logic routines can
be used to make an estimate of distance based on multiple samples with the emitter both on and off, as
describe in [5].
Figure 3-6: Photographs of TSAL6100 infrared emitter LED, and IR light from outdoors
An example of using the infrared emitters from software is given in example 3-3.
#include "global.h"
#include "timer.h"
#include "a2d.h"
int your_function_name(void)
{
uint16_t ir_val;
…
sbi(PORTA,1); //turn LED emitter 3 on
delay_ms(20); //wait a bit
An 8 character by 2 line display is provided on the robot for feedback, debugging, and any other functions
the programmer can come up with. The LCD display uses the Hitachi HD44780 communication standard,
and modified libraries are provided from those written by Steven Pickles in [8]. Example 3-4 provides an
example of using the LCD display.
#include "global.h"
#include "timer.h"
#include "lcd_4bit.h"
int your_function_name(void)
{
…
moveToXY(0,0);
writeStringToLCD("Micro");
moveToXY(1,3);
writeStringToLCD("Mouse");
The chassis, or body construction of the robot, is made out of hard plastic, and was cut using a CNC
machine (figure 3-7). Overall chassis dimensions are 5.3 cm x 11.0 cm x 3.5 cm, width x length x height,
excluding wheel protrusion.
#include "global.h"
#include "timer.h"
#include "lcd_4bit.h"
#include "a2d.h"
void initializeDevice(void)
{
cli(); //disable interrupts
//Port Setup
PORTA = 0b00000000;
DDRA = 0b01000010; //data direction register, 1 = out, 0 = in
PORTB = 0b00000000;
DDRB = 0b00001011;
PORTC = 0b00000000;
DDRC = 0b00000000;
PORTD = 0b00000000;
DDRD = 0b11111110;
//End port setup
timerInit();
timer0Init();
timer0SetPrescaler(TIMER_CLK_DIV1024);
timerAttach(TIMER0OVERFLOW_INT, handle_timer0);
timer1Init();
timer1SetPrescaler(TIMER_CLK_DIV1);
timer1PWMInit(8);
timer1PWMInitICR(0x65);
a2dInit();
a2dSetPrescaler(ADC_PRESCALE_DIV32);
a2dSetReference(ADC_REFERENCE_AREF);
initializeLCD();
ow_reset();
}
The board layout is shown in figure 4-2. A list of the components is provided below, with external links to
documentation where applicable.
4.1 Microcontroller
The ATmega32 device is used as a central controller for the micromouse system, and can be programmed
in standard C (recommended), or in Assembly. A set of libraries are available from Procyon AVRlib that
will make some features on this device much easier to use. In addition it is recommended to program this
device in AVRStudio 4 or higher and utilize the included avr-libc libraries. A TQFP package is used in this
design (figure 4-4).
ATMEGA32-16AU
This device is used primarily as a counter for the two motor encoders, as described in 3.2 Encoders.
Additionally, there are 4kbits of RAM memory available through the 1-Wire interface. To use this feature,
see the documentation. A TSOC package is used in this design (figure 4-4).
DS2423
This device is used to multiplex the only two Timer1 outputs available and GND into the motor driver H-
Bridge chip (Freescale MPC17531) so that direction reversal of the motors is possible. Please see section
3.1 Motors. The device package used is a thin SSOP (figure 4-4).
MAX4701EUE+
This device is used to drive two motors off the battery supply, with control inputs from the microcontroller
PWM. See section 3.1 Motors. The device uses a VMFP package, which is equivalent to SSOP (figure 4-
5).
As mentioned previously, this chip regulates the battery input from around 9V to a steady 5V. The SO
output of this chip is connected to the microcontroller I/O pin A7, and can be used to detect low power
output from the battery. See the device documentation for further information on its operation and
maximum ratings. See Appendix C: Errata for an important note about this chip.
In figure 4-2J an optional connector is provided for an external oscillator. To use this feature you should
match capacitor values for C1 and C2 to the proper rating for whatever oscillator you use. Verify that your
oscillator will work beforehand by reading the ATmega32 documentation and preferably testing on another
device. After soldering oscillator and capacitors you will have to change the lock bits to the proper External
Oscillator setting as described in the ATmega32 documentation.
These two connections on PAD1 and PAD2 bring out the nets for TXD and RXD from the microcontroller,
but no serial controller circuitry or pull-downs are provided.
The micromouse should work with the LCD unconnected on header JP1. It is very important to connect the
LCD so that the display is facing over the PCB board, as shown in figure 3-1.
Currently this device is bypassed directly to ground, giving full contrast to the LCD display. The LCD may
work with bypass removed and the potentiometer adjusted to the right range, however we had problems
with the display shorting.
This potentiometer provides a way to increase the resolution of the photosensors manually. You can do this
adjusting the lower range value of the ADC VREF so that it matches the collector voltage of the BPV11F
phototransistor devices when IR emitters are off. Be careful adjusting this as it is very sensitive.
This is a small green LED connected to PORTA 6 on the microcontroller, and it can be used for
testing or whatever other purpose you need.
Appendix B: Schematic
Appendix C: Errata
The following issues were noted while testing this device:
A) The MAX5091 voltage regulator has a metal pad underneath the device for grounding. Our PCB has
metal vias underneath the chip, as we did not account for this metal pad. To resolve, we placed electrical
tape under the chip. The PCB designs have NOT been updated to mark this change.
B) The potentiometer for LCD contrast (Section 4.5.4) causes a short if turned incorrectly. To resolve, we
bypass the potentiometer to ground, as this does not pose an issue. In the future a fixed resistor should be
connected in series with this and any other potentiometers.
C) A connection was not added to the PCB for the LCD backlight power (LED+ and LED-). To resolve
LED+ (pin 15 on LCD) is connected through a makeshift header and 220Ω resistor to +5V (VCC). See
section 2.4.
References
[1] “MicroMouse Competition Rules,” IEEE Region 6 Central Area Spring Meeting 2008. Accessed: May
29, 2008 <ewh.ieee.org/r6/central_area/micromouse_rules.pdf>.
[2] "Pulse-width modulation." Wikipedia, The Free Encyclopedia. 20 May 2008, 08:58 UTC. Wikimedia
Foundation, Inc. 29 May 2008 <http://en.wikipedia.org/w/index.php?title=Pulse-
width_modulation&oldid=213664042>.
[4] “DS2423 Datasheet.” Maxim Integrated Products, Dallas Semiconductor. Accessed: May 29, 2008
<http://datasheets.maxim-ic.com/en/ds/DS2423.pdf>
[5] Jianwei Zhang, F. Wille, A. Knoll, "Fuzzy logic rules for mapping sensor data to robot control,"
eurobot, p. 29, 1st Euromicro Workshop on Advanced Mobile Robots (EUROBOT), 1996