CSE477 Laboratory Assignment #2


Building a Simple System: an Ultrasonic Directional Range-finder

Assigned: 11 October
Due: 20 October


Objectives:

When you have completed this lab, you should know how to:

Important Notes:


Reading:


Part 1: Setting Up The Sensors

The digital compass
The digital compass we are using is not a high precision instrument but nevertheless it can discern 8 distinct orientations: N, NE, E, SE, S, SW, W, and NW. The compass has four terminals that behave symmetrically. If the compass is pointing in one of the cardinal directions then that terminal will be low and the other three terminals will be high. For example, when pointing south, only the south terminal is low, the west, east, and north will be high. The other four directions the compass can identify lie between the four cardinal directions at NE, SE, SW, and NW. To indicate when it is pointing in these directions, the compass will have two terminals low and two high. For example, if it is pointing NW then the north and west terminals will be low while the south and east terminals will be high. Therefore, either a single terminal is low or two consecutive terminals are low. There will never be three or four terminals low simulateously. An LED can be connected to each terminal to help in understanding the operation of the compass and in debugging. When one terminal points south, the corresponding LED will be on. When the compass points in a 45 degree direction, two LEDs will be on.

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:

  1. a power lead,
  2. a ground lead, and
  3. an open collector lead.
See the figure below for a schematic. Because the transistor can only drive the output low, we also require an external pull-up resistor connected to 5 volts. In this manner, when the transistor is not pulling low, we will see a high voltage. The diagram also shows how to connect the LED to the third lead with an appropriately sized resistor.

Try to answer the following questions with your compass:

You can find more documentation about the digital compass at the Dinsmore web site.

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
* Pin 1 is the pin closest to J1

The sonar transducer should be connected to the range finder board as follows:

E1 on the range finder board --> (+) brass tap on black disk
E2 on the range finder board --> (-) black tap on black disk

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.


Part 2: Polling The Compass And Sonar

You will now connect the compass and sonar to the StrongARM board. Use the board schematics to locate the set of LCD pins that the Peripheral Pin Controller (PPC) controls. Use a wire-wrap tool to attach the compass and sonar to these pins. Find the ppc_regs struct in the sa1100.h header file. What is the base address of the PPC?

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.


Part 3: Using GPIO Interrupts

In this part of the lab you will now change your program to use interrupts to detect changes in direction. First, you will need to have an input whose state changes whenever the compass reading changes. Build an XOR tree like the one shown below using a Motorola 74LS86 chip. Are there other ways to connect the inputs?

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.