Improvement of Ultrasonic Distance Measuring System

This paper mainly introduces a kind of ultrasonic distance measuring system with AT89C51 single chip as the core component. The paper expounds the principle of ultrasonic sensor and ultrasonic ranging, hardware circuit and software program, and the results of experiment and analysis.The hardware circuit based on SCM, the software design adopts the advanced microcontroller programming language.The amplitude of the received signal and the time of ultrasonic propagation are regulated by closed loop control. [1,2]The double closed loop control technology for amplitude and time improves the measuring accuracy of the instrument. The experimental results show that greatly improves the measurement accuracy of the system.


Introduction
Ultrasonic is a kind of sound wave that frequency is higher than 2KHz.It has good directivity, strong penetration ability and easy to obtain more concentrated sound energy.[3]The use of ultrasonic detection is relatively fast, convenient, simple and easy to control in real time.And ultrasonic can meet the practical requirements of industry in terms of measurement accuracy.So it has been widely used in mobile robots, car safety, ocean measurement and so on.The design of the system mainly includes two parts, that is the hardware circuit and the software program.The hardware circuit mainly includes the single chip circuit, the transmitting circuit, the receiving circuit, the display circuit and the power supply circuit.This paper uses AT89C51 microcontroller as the core of the digital display ultrasonic range finder.The whole circuit is designed by modularization, which is composed of signal transmitting and receiving, power supply, display and so on.The received signal amplitude and the propagation time of ultrasonic extraction use double closed-loop control technology.The experimental results show that the system has high precision measurement level and can meet the range requirement in industry.

Ultrasonic sensor and the principle of ultrasonic distance measurement 2.1 Ultrasonic sensor
The ultrasonic sensor is a kind ofsensor that converts ultrasonic signals into other energy signals (usually electrical signals).It has the function of converting electrical signals into mechanical signals and converting mechanical signals into electrical signals.We chose the piezoelectric ultrasonic generator in the design.[4] The piezoelectric ultrasonic generator actually works by using the resonance of a piezoelectric crystal.This paper adopts HC-SR04 ultrasonic sensor.This module has stable performance, accurate measurement of the distance, module of high precision and small blind region.The ultrasonic time sequence diagram is shown in Fig. 1.

The principle of ultrasonic distance measurement
The principle of ultrasonic distance measurement is TOF (time of flight).[5]The emission circuit sends out the ultrasonic.The ultrasonic waves propagate in the air and is reflected back when it meets an obstacle.The receiving circuit receives the reflected ultrasonic wave, and the single chip microcomputer measures the time required for transmitting to receiving.The time for detecting the ultrasonic wave transmitted from the emitter to the receiving end is t, and the time is time of flight.The velocity of ultrasonic wave propagation in the air is C, and the distance between the emission point and the measured object is s.[6]The range formula is expressed as: The wave velocity of ultrasonic wave is related to the propagating medium, which is the fastest in the solid and the slowest in the gas.Ultrasonic is a kind of sound wave, so its velocity is related to temperature.Table 1 lists the sound velocity at several different temperatures.When in use, if the temperature change is not big, it is considered that the velocity is basically unchanged.If the measurement accuracy is very high, it should be corrected through temperature compensation method.The relationship between the velocity of sound and the temperature in the air can be expressed as: In order to further improve the accuracy of the measurement, this design increases the angle compensation as shown in the diagram.Measuring distance is When s>>h, and c is the ultrasonic speed.

Singlechip circuit
The AT89C51 singlechip is the core component of the instrument.The singlechip timer sends out the square wave pulse signal around 40KHz.The pulse is added to the ultrasonic sensor through the ultrasonic driving circuit, and the ultrasonic sensor sends out the ultrasonic.Because the output power of the MCU port is relatively small, it is difficult to meet the requirement of measuring distance.The ultrasonic transducer is output by the ultrasonic transducer after enlarging the amplifying circuit.The emitted ultrasonic wave is used as the input of the system.[7]The phase locked loop locks this signal, and produces a lock signal to start microcontroller interrupt program.The internal timer stops the timing, software system calculat and analyz the signal then.The corresponding calculation results are sent to the LED digital tube for display.The single ship sequence diagram is shown in figure 4.

Transmitting circuit
The transmitting circuit uses square wave modulation pulse transmitting circuit.The principle is shown in Figure 3.The singlechip generates a control signal and this signal triggered monostable multivibrator generates a main control pulse.When the master pulse is in high level, square wave generator produces a square wave pulse, the frequency is same with frequency transmitting transducer.Through the drive switch, transformer coupled excites ultrasonic transducer to emit ultrasonic.

Receiving circuit
The receiving circuit filters the signal to form the echo envelope, and the high speed voltage comparator produces a receiving signal pulse and transmits it to the 51 single chip circuit.
In order to overcome the received signal amplitude changes caused by changes in the distance test.mberequations consecutively.In the hardware circuit design, using 4 point CMOS analog switch, based on the principle that the amplification of the inverting amplifier depends on the ratio of the resistance value, the resistors with 1, 1/2, 1/4 and 1/8 weights are in parallel in turn, and the logic level is used to control the resistance, and the synthetic resistance of 0~15 times is obtained.[8] In this way, a programmable amplifier with 0~15 times gain is obtained.As shown in Figure 9.In the system, programmable operational amplifier circuit, bandpass filter, absolute value circuit, π filter circuit, peak value holding circuit, voltage comparator and single chip microcomputer form the closed loop control loop with adjustable amplitude.The peak holding circuit extracts the maximum envelope of the received signal, and compares it with the preset threshold circuit.[9]When it is lower than the preset threshold, that the received signal is in the best received signal amplitude range, digital signal generated by the microcontroller control programmable amplifier, gain adjustment circuit, to achieve closed-loop gain control, the received signal amplitude changes in the vicinity of the threshold setting, so as to overcome the increase or decrease the amplitude of the signal caused by the change of the distance.The propagation time is extracted based on ultrasonic echo.When a fixed threshold is used to read the ultrasonic propagation time, the time error will be caused by the variation of the echo amplitude, which will greatly affect the accuracy of ranging.Therefore, in the system design, a programmable variable threshold generation circuit is designed by using digital potentiometer, and a time readable closed loop control circuit is formed by highspeed voltage comparator (reduced signal comparison delay), microcontroller and variable threshold circuit.For the same distance, the echo signal is adjusted from a gain adjustment loop to a reasonable range.[10] Its envelope passes through a high speed voltage comparator to form a receiving pulse, and the width of the receiving pulse is detected by a single chip microcomputer.When it is not within reasonable limits (the 990us 1000US), according to its value, the microcontroller output digital adjustment signal, control the digital potentiometer to produce a new threshold.[13,14] Thus the closed loop control of the received pulse width can be realized, and the timing error caused by the same distance is overcome by the amplitude change, and the measurement precision is improved.

Display circuit
The system uses a Trinity LED digital tube to display the measured distance, such as figure 10.

Power circuit
The working current of the system is about 30-45mA.In order to ensure the system to work and debug the system for convenience, we use the USB port to supply the power directly to the computer.The 6V AC current is rectified by diode into a pulsating DC current, then it passes through the filter capacitor C1 to form the direct current.The voltage in the circuit passes through the integrated circuit transforms into 5 volt DC to supply to the whole system for electricity.In order to further improve the quality of power supply, the 5 volt DC power is filtered by C3 and C4 again.The power supply circuit is shown in Figure 11.

Software design
The instrument software design use advanced microcontroller programming language.It is convenient to carry out various mathematical operations.The main modules include ultrasonic transceiver module, automatic gain control module, receiving pulse width modulation module, temperature measurement module, data sorting and filtering module, remote communication module and so on.[11]The program flow is shown in Figure 13 .3 were obtained for the 3000mm test point.According to the Bessel formula, [12] the standard deviation of the double closed loop control is 0.32mm, and the standard deviation is 4.39mm when the fixed threshold is used.It can be seen that the measurement accuracy has been greatly improved when double closed loop control is adopted.

Conclusion
The experimental results show that in the closed loop control of amplitude, the control of automatic gain control circuit is avoided, and the amplitude variation caused by distance variation is overcome.For the time variable threshold control, variable threshold generation circui and time readable closed loop control loop overcome the timing error caused by the change of amplitude.
The results of laboratory studies show that the echo waveforms of different test distances are the same, but the echo amplitude is different.[15]For the same test distance, the echo waveform is almost the same, and the amplitude is still slightly changing.In the case of the same waveform, in the same distance and different distance, the wave amplitude of the wave should be changed because the sound wave is affected by the propagating medium.In the design of ultrasonic distance measuring system, the change of echo amplitude must be overcome so that the precision of distance measurement can be improved.

Table 3 .
The sound velocity at several different temperatures Table 2 and table 3.

Table 2
Experimental data of double closed loop control (Unit: mm)

Table 3
Typical experimental data of measured points (unit: mm)

Table 2
data is the average value of the 5 measured values at the same point.The data of Table