Assignment AMP1 – Ultrasonic range finder
Introduction
The aim for this assignment is to write a program for the ultrasonic range finder. It is similar to the sonar system, which emit a time-limited ultrasonic wave and receive the echo of the signal. The delay between transmission and reception of the
Signal can be used as a measure for the distance at which the object is found. The process shows below.
Overview
The microcontroller program needs to implement a ultrasonic range finder. First switch the transceiver to ‘transmitting’ by producing a high-level signal on the RX/TX control line, using port P3, and pin 0 for this. Then, a 1 ms lasting 39 kHz square-wave burst is to be generated on the data line of the module. Port P2 used for this signal. Following this, the transceiver is to be switched to ‘reception’ by pulling the RX/TX control line to low. A short delay of 1 ms should be implemented before the receiver is enabled To avoid confusion between potential transient oscillations. Upon detecting a reflected 39 kHz burst, the receiver produces a high-level on its output line. This low tohigh transition is the event which marks the end of the measurement; the microcontroller should now calculate the distance using equation. x=v T2
Where: v = the speed of wave in air which is 331.4m/s T = the total time flight of the wave packed between transmission and reception. X = the unknown distance to the object in the range from 30 cm to 4 m
Note that this program imposes a lower and an upper time limit for the echo measurement. These limits need to be considered.
Flow chart for the whole program
Start
Switch the transceiver from high to low
Start PWM to generate 39kHz signal
Start T3 to control the PWM lasing 1ms
After 1ms
Stop PWM
Start T3 for the 1ms delay
Start T4for the total time flight
After