This is the application report from Texas Instruments about distance measurement using ultrasonic and MSP430 microcontroller. The report is provided in PDF file, you may download the application report at the end of this post.
This application report describes a distance-measuring system determined by ultrasonic sound using the MSP430F413 ultralow-power microcontroller. The system transmits a burst of ultrasonic sound waves towards the subject point and after that receives the corresponding echo.
This application is primarily based upon the reflection of sound waves. Sound waves are defined as longitudinal pressure waves in the medium in which they’re travelling. Subjects whose dimensions are greater than the wavelength of the impinging sound waves reflect them; the reflected waves are known as the echo. In the event the speed of sound in the medium is recognized and the time taken for the sound waves to travel the distance from the source towards the subject point and back to the source is measured, the distance from the source to the subject point will be computed accurately.
The devices applied to transmit and receive the ultrasonic sound waves within this application are 40-kHz ceramic ultrasonic transducers. The MSP430 drives the transmitter transducer using a 12-cycle burst of 40-kHz square-wave signal derived from the crystal oscillator, and therefore the receiver transducer receives the echo. The Timer_A in the MSP430 is configured to count the 40-kHz crystal frequency such that the time measurement resolution is 25 µs, that is more than enough for this application. The measurement time base is extremely stable because it is derived from a quartz-crystal oscillator. The echo received by the receiver transducer is boosted by an operational amplifier and the amplified output is fed towards the Comparator_A input. The Comparator_A senses the presence of the echo signal at its input and triggers a capture of Timer_A count value to capture compare register CCR1.
The capture is accomplished exactly at the immediate the echo arrives at the system. The captured count will be the measure of the time taken for the ultrasonic burst to travel the distance from the system to the subject point and back to the system. The distance in inches from the system towards the subject point is computed by the MSP430 implementing this measured time and displayed on a two-digit static LCD. Instantly right after updating the display screen, the MSP430 goes to LPM3 sleep mode to keep electrical power. The Basic Timer1 is programmed to interrupt the MSP430 every 205 milliseconds. The interrupt signal from the Basic Timer1 wakes up the MSP430 to repeat the measurement cycle and update the display screen.