Program/Hardware Design

This project uses two STK-200 boards with AT90S8515 microcontrollers, split into transmitter and receiver assemblies.

The transmitter would be mounted in a weatherproof module in the front of the vehicle. The 8515 instructs the Devantech SRF04 sonic ranger to send out a pulse by holding the pulse input trigger high for 10 microseconds, and measures the time until the pulse returns. The output of the ranger is connected to the input capture pin of the 8515, which waits for a falling edge on the pin. This edge causes a Timer1 capture event, which stores the time in a variable, then sets a flag. In the main program loop, the flag is detected, and the time is converted to a distance. Since we measure the time in clock cycles, we multiply the time by 29/4 to get the distance in centimeters (sound travels one centimeter in roughly 29 microseconds). Timer1 is preloaded to overflow if no echo is returned within about 36 milliseconds. The input capture is then ignored until another pulse is sent out.

Since the range of the ranger can be up to three meters, we store the distance as a 16 bit value, and wish to transmit all the bits over our serial link. Note that we use the serial transmit and receive pins on the 8515 itself, not the RS-232 output. This is due to the undesirable signaling levels of RS-232. The ports themselves are inverted RS-232, which caused us some problems. In inverted RS-232, the channel is held high between bytes; however our receiver could not hold the line high for more than about 10-13 microseconds. To solve this problem, we put high-speed inverters (HC7404s) on both transmitter and receiver to convert to regular RS-232. Once this is done, we are ready to transmit. To be sure that we are correctly receiving both bytes, we put the link in 9-bit mode. We first transmit the high byte of the distance with a '1' in the ninth bit, followed by the low byte with a '0' in the ninth bit. This ensures that a single byte missed will not propagate errors to further updates. If the bytes are not sent in the proper order, the receiver ignores the update. Since the updates are sent at 10 Hz, missing a few, or having a few transfer incorrectly, is not noticeable to the user.

The radiolink consists of an Abacom AM-TX1 transmitter and AM-HRR3 receiver, both operating at 433 MHz. Though the manual recommended a tuned-loop antenna on the transmitter, we found a l/4 dipole worked well. The transmitting board outputs the distance measurements through a blocking functions, so all measurements are transmitted. PortD.1 (TXD) is connected to the CMOS inverter, which in turn, drives the transmitter circuit. We connected the receiver through the inverter to PortD.0 (RXD), which is the serial receive. This board has a few more functions. First, it receives the two byte updates, correctly ordered, via the RXC ISR. Once a complete update is received, the main loop displays the distance on the attached LCD.

The second STK-200 also polls three buttons, which use the upper part of PortD (remember that Port0 and 1 are used by the serial communication). PortD.7 allows the user to recalibrate the distance measurement. The idea here is that the user can specify a position that they want to be at, and the calibrated distance will be zero at that position. The second button resets the calibration distance. This is needed, since the variable is stored in EEPROM, and is preserved even after reset.

The third button serves as a sound toggle. When sound is enabled, a speaker on PortA is driven with a 1 kHz square wave. The currently stored distance controls the pulse repetition frequency. The distance multiplied by four serves as the time between pulses. This means that at the maximum usable range of about 2.5m, there is a one second pause between pulses. As the car approaches an obstacle, the pulses become more rapid, until they become continuous at about 10 cm. This works off the calibrated distance, so a driver could set the calibrated distance for their favorite position, and simply more forward slowly until the sound is continuous.


 

This all sounds great in theory. Please proceed to learn the Results of our toying with the Ultrasonic Parking Assistant.