CSE477 Laboratory Assignment #2


Building a Simple System: an Ultrasonic Directional Range-finder

Assigned: 15 January
Due: 26 January


Objectives:

When you have completed this lab, you should know how to: Note: take care in your assembly for this assignment as you will be reusing the hardware you design and build in the next assignment.


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 alsow shows how to connect the LED to the third lead with an appropriately sized resistor.

Figure 1: diagram of compass and the detail of connections to one of the four 3-lead terminals.

Try to answer the following questions with your compass:

You can find more documentation about the digital compass at:

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). See the controller board documentation for the other modes of operation it supports.

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 might give you an uncomfortable burn.

The interconnect to the sonar range finder board is (pin 1 is closest to J1 on the sonar board):
 
purpose gnd BLNK INIT ECHO BINH Vdd
pin / voltage 1 / 0V 2 / 0V  4 / Input  7 / Output  8 / 0V 9 / 5V

The connections to the sonar transducer (see transducer documentation) are:

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

The ECHO output is an open collector output like the terminals of the compass (see the figure below).

Figure 2: Schematic diagram for ECHO output including pull-up resistor size.

Try to follow 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:

Part 2: Connecting the compass and sonar to the EVB

Decide which ports to use on the EVB for the compass and sonar range finder. You will need minimum of four input pins for the compass. A fifth input may be useful to be able to detect the compass direction has changed (rather than polling and trying to do this in software). This is a simple example of extra logic outside the microcontroller making the system simpler. The sonar will require one input pin port and one output pin port. An input capture pin should be used to measure the time of the echo.

The compass can easily be tested with hyperterminal using

MD <address of input port register>
(MD is explained in the User Manual). When the compass is rotated, the value stored at that memory address should change.

You will have to write a small C program to test the sonar range finder. The program should measure the time between when the INIT signal goes high and when the ECHO signal goes high. Make several measurements to see if the readings make sense (i.e., try out objects or walls at different distances).

Part 3: Integrate the compass and sonar into a small system

After you've gotten both the compass and sonar working. You should write a C program that takes a distance measurement and prints the distance (in feet) and the direction of the compass at the time of the reading to the PCs terminal window. It should get a new reading every time the compass changes direction. Here is an example of the output that should be seen in the hyperterminal for a North-West heading with an object at 3 feet:
NW 3
You can round off to the nearest foot.

What to Turn In

Demonstrate Part 3 to the TAs and explain the final C program.
Comments to: cse477-webmastbmaster@cs.washington.edu (Last Update: )