Assigned: 11 October
Due: 20 October
Each of the four terminals really consists of 3 leads for a total of 12 pins on the compass. Each terminal is simply a three terminal transistor that reacts to the magnetic field of the Earth. The leads are:
Try to answer the following questions with your compass:
The sonar range finder
The sonar range finder will be used to determine the distance to the
closest object directly in front of it. The transducer of the sonar
is the black perforated disk with a metal disk behind it.
(Note: a transducer is a device that converts signals from one form
to another, in our case, from electrical to sound and vice-versa.)
The disk
generates the sound and vibrates to the echo. The small board that
accompanies the disk is its controller. It generates the sound given
a rising edge on a digital input and detects the echo by providing
a rising edge on a digital output. There is interesting analog
circuitry on the controller board that charges up the transducer to
the high voltages needed to both generate and sense ultrasound.
The sonar device sends out 16 pulses at 49.5 kHz that travel from the disk and reflect off of the objects in front of it. The first echo to return (from the closest object) is used to raise the output signal. The range finder is started by raising the INIT signal. When the echo returns the ECHO signal goes high. INIT has to stay high at least until ECHO goes high. The sonar board operates this way in the mode you will using (when both BINH and BLNK are low).
Make sure to be careful in handling the board. The device generates high voltages on the controller board and at the transducer leads (in the range of 200 to 400 volts). Touching the sonar circuit board while it is powered up and/or operating may result in a burn.
The range finder board should be connected as follows:
Name | GND | BLNK | INIT | ECHO | BINH | VDD |
Pin | 1 |
2 | 4 | 7 | 8 | 9 |
Connect to | 0 V | 0 V | input | output | 0 V | 5 V |
The sonar transducer should be connected to the range finder board as follows:
Like the compass, the range finder board has an open collector output. The ECHO output should be connected to a 4.7 Kohm pull-up resistor (i.e. connected to 5 V).
Try the following procedure to make sure that your sonar is working properly. Connect INIT to high to start the range finding operation. You should hear a scratching, which is the transducer sending off the 16 pulses. In addition, ECHO goes high immediately. Reset the sonar range finder by making INIT low and ECHO should go low as well.
Your can find more documenation about the sonar range finder at the Acroname and Wirz web sites.
Starting from these project files, write a function that read the state of the pins connected to the compass and returns the current direction (N, NE, E, etc.).
Write a second function that sends the sonar's INIT line high and waits for the ECHO signal to go high. Use the OS Timer Count Register to measure the time this takes. Convert clock ticks to seconds, and seconds to meters. (Sound travels through air at 343 m/s.) Your function should return the distance measured.
Use these functions to write a program which continuously reads the state of the compass and sonar. Before calling these functions, your program will need to configure the PPC appropriately. Your program should display the current state of the compass and sonar using the LEDs and HexLEDs. Use the block of 4 LEDs used in Lab 1 to indicate direction. Each LED will represent a cardinal direction (N, E, S, W in that order). If the compass indicates SE, then the second and third LED should be illuminated (and the others off). Display the distance using the numeric HexLEDs. These can be changed by calling the _saSetHexLEDs function.
Using the board schematics, locate the GPIO pins (not the PPC pins) that are connected to the LCD header. Attach the output of your XOR tree to one of these GPIO pins using the wire-wrap tool.
Modify your program so that an interrupt is generated on both rising and falling edges on the GPIO pin you have selected. How do you clear the edge detect status for this pin? (Look for the GP_PIN constants in the sa1100.h header file.)
Finally, write and install an interrupt handler which will read the compass and measure the distance whenever the output of your XOR tree changes. Don't forget to clear the edge detect status. What happens if a second interrupt occurs while you are handling the first? You should display the current direction and distance in the same way as Part 2.
Demonstrate your program to a TA. Be prepared to answer questions about
how the PPC and GPIO registers work.