The objective of this problem is to design an underwater ultrasonic ranging system. The distance to the object, d, can vary from 1 to 100 m. The ultrasonic transducer will send a short 5-μs sound pulse into the water in the direction of interest. The sound wave will travel at 1500 m/s and reflect off the first object it runs into. The reflected wave will also travel at 1500 m/s back to the transducer. The reflected pulse is sensed by the same transducer. Your system will trigger the electronics (give a 5-μs digital pulse), measure the time of flight, then calculate the distance to the object. Using periodic interrupts, the software will issue a 5-μs pulse out PT1 once a second. Using interrupting input capture, the software will measure the time of flight, ?t. The input capture interrupt handler will calculate distance d as a decimal fixed-point value with units of 0.01 m and enter it into a FIFO queue. The main program will call the ritual, then get data out of the FIFO queue. The main program will call Alarm() if the distance is less than 15 m. You do not have to give the implementation of Alarm().You may use any of the FIFOs in Chapter 4 without showing its implementation. To solve this problem on other microcomputers, you may modify the hardware in Figure 6.26 to conform to the available ports. As shown in the figure the time of flight, ?t, is measured from the rise of PT1 (9S12 output) to the rise of PT0 (9S12 input).
Figure 6
![1847_2cb4c7fe-557b-48f6-b12c-179c20d02a6a.png](https://secure.tutorsglobe.com/CMSImages/1847_2cb4c7fe-557b-48f6-b12c-179c20d02a6a.png)
a) Derive an equation that relates the distance d to the time of flight ?t.
b) Use this equation to calculate the minimum and maximum possible time of flight ?t.
c) Choose the TCNT rate that will satisfy the range and resolution requirements of this problem.
d) Give the ritual that initializes the interface, including PORTT timer channels 0 and 1. Don't worry about the other six timer channels.
e) Give the main program that first calls the ritual. The main program will empty the FIFO and call Alarm() if the distance drops below 15 m. Decide whether it is better to convert time (TCNT counts) to distance (decimal fixed point, 0.01m) here in the main program or in the interrupt handler.
f) Give the TC1handler() periodic interrupt handler that issues pulses of about 5-μs duration on PT1 every 1 sec. Good interrupt software has no backward jumps.
g) Give the TC0handler() interrupt handler that measures the time of flight and puts the result (either the count or the calculated distance) into the FIFO. Good interrupt software has no backward jumps. There may be additional sonic echoes, so only calculate the range of the first one and ignore the others.