School of Communication Engineering, Nanjing Institute of Electronic Science and Technology, Sha Aijun
In daily production and life, many occasions such as car reversing, robot obstacle avoidance, industrial well logging, reservoir level measurement, etc. require automatic non-contact distance measurement. Ultrasonic waves refer to mechanical shock waves with a frequency greater than 20 kHz generated in elastic media. They have the characteristics of strong directivity, slow energy consumption, and relatively long propagation distance, so they are often used for non-contact distance measurement. Since ultrasonic waves are insensitive to light, color, and electromagnetic fields, ultrasonic distance measurement has good adaptability to the environment. In addition, ultrasonic measurement can also achieve a good compromise in real time, accuracy, and price.
Therefore, this paper attempts to design an ultrasonic rangefinder with small size, low price, high accuracy, temperature compensation, real-time LCD display and alarm using a pair of 40 kHz piezoelectric ultrasonic sensors based on the single-chip microcomputer AT89S52.
1 Principle of Ultrasonic Distance Measurement
Ultrasonic sensors are divided into two categories: mechanical and electrical. They are actually a kind of transducer. At the transmitting end, they convert electrical energy or mechanical energy into sound energy, and vice versa at the receiving end. The ultrasonic sensor designed this time uses a piezoelectric ultrasonic transducer in the electrical mode, which works by the resonance of a piezoelectric crystal. It has two piezoelectric chips and a resonance plate. When a pulse signal is applied to its two poles, and its frequency is equal to the natural oscillation frequency of the piezoelectric chip, the piezoelectric chip will resonate and drive the resonance plate to vibrate, generating ultrasonic waves. On the contrary, if no voltage is applied between the two electrodes, when the resonance plate receives ultrasonic waves, it will press the piezoelectric chip to vibrate, converting mechanical energy into electrical signals, and it becomes an ultrasonic receiver. In the ultrasonic circuit, the transmitting end outputs a series of pulse square waves. The larger the pulse width, the more the number of outputs, the greater the energy, and the farther the distance that can be measured. The ultrasonic transmitting transducer and the receiving transducer are slightly different in structure. When using them, you should distinguish the signs on the device.
There are many methods of ultrasonic distance measurement: such as round-trip time detection method, phase detection method, and sound wave amplitude detection method. This design uses the round-trip time detection method to measure distance. The principle is that the ultrasonic sensor emits ultrasonic waves of a certain frequency, which are transmitted through the air medium and reflected back after reaching the measurement target or obstacle. After reflection, the ultrasonic receiver receives the pulse. The time it takes is the round-trip time, which is related to the distance of the ultrasonic wave propagation. The distance can be obtained by testing the transmission time.
Assuming s is the distance between the measured object and the rangefinder, the measured time is t/s, and the ultrasonic propagation speed is v/m·s-1, then we have the relationship (1)
s=vt/2 (1)
When the accuracy requirement is high, it is necessary to consider the effect of temperature on the ultrasonic propagation velocity and correct the ultrasonic propagation velocity according to formula (2) to reduce the error.
v=331.4+0.607T (2)
Where T is the actual temperature in °C, and v is the propagation speed of ultrasound in the medium in m/s.
2 Overall system design
The system consists of ultrasonic emission, echo signal reception, temperature measurement, display and alarm, power supply and other hardware circuit parts and corresponding software parts. The system principle block diagram is shown in Figure 1.
The whole system is controlled by the single-chip computer AT89S52. The ultrasonic sensor adopts a split-type transmitter and receiver, which consists of an ultrasonic transmitter transducer TCT40-16T and an ultrasonic receiver transducer TCT40-16R. The ultrasonic signal is transmitted into the air by the ultrasonic transmitter transducer, and the echo is received by the ultrasonic receiver transducer after being reflected by the object to be measured. After relevant processing, the INT0 pin of the input single-chip computer generates an interrupt, and the intermediate time is calculated. At the same time, the corresponding sound speed is calculated according to the specific temperature. According to formula (2), the corresponding distance can be obtained for display. Of course, in some occasions, the distance alarm value can also be set according to needs.
3 Hardware Design
3.1 Ultrasonic emission part
The ultrasonic transmitting part is to enable the ultrasonic transmitting transducer TCT40-16T to send a square wave pulse signal of about 40 kHz to the outside world. There are usually two ways to generate a square wave pulse signal of about 40 kHz: using hardware such as 555 oscillation or software such as single-chip software programming output. This system uses the latter. The programming outputs a square wave pulse signal of about 40 kHz from the P1.0 port of the single-chip microcomputer. Since the output power of the single-chip microcomputer port is not enough, the 40 kHz square wave pulse signal is divided into two paths and sent to a push-pull circuit composed of 74HC04 for power amplification so that the transmission distance is far enough to meet the measurement distance requirements. Finally, it is sent to the ultrasonic transmitting transducer TCT40-16T to be emitted into the air in the form of sound waves. The circuit of the transmitting part is shown in Figure 2. The pull-up resistors R31 and R32 at the output end in the figure can improve the driving ability of the inverter 74HC04 to output a high level on the one hand, and on the other hand, it can increase the damping effect of the ultrasonic transducer and shorten its free oscillation time.
3.2 Ultrasonic receiving part
The TCT40-16T transmits the ultrasonic wave in the air and returns when it encounters an obstacle. The ultrasonic receiving part is to smoothly receive the reflected wave (echo) to the ultrasonic receiving transducer TCT40-16R to convert it into an electrical signal, and then amplify, filter, and shape the electrical signal. Here, the integrated chip CX20106 produced by Sony is used to obtain a negative pulse and send it to the P3.2 (INT0) pin of the microcontroller to generate an interrupt. The circuit of the receiving part is shown in Figure 3.
It can be seen that the integrated chip CX20106 plays a great role in the receiving circuit. CX20106 is a widely used special chip for infrared detection and reception. It has the advantages of strong functions, superior performance, simple peripheral interface and low cost. Since the commonly used carrier frequency 38 kHz of infrared remote control is close to the ultrasonic frequency 40 kHz of ranging, and the filter center frequency f05 set inside CX20106 can be adjusted by its 5-pin external resistor, the larger the resistance, the lower the center frequency, ranging from 30 to 60 kHz. Therefore, this design uses it as the receiving circuit. The CX20106 is composed of a preamplifier, a limiting amplifier, a bandpass filter, a detector, an integrator and a shaping circuit. The working process is as follows: the received echo signal first passes through the preamplifier and the limiting amplifier to adjust the signal to a rectangular pulse of appropriate amplitude, and the filter selects the frequency to filter out the interference signal, and then it is shaped and sent to the output terminal 7 pin. When receiving an echo signal that matches the center frequency of the CX20106 filter, its output pin 7 outputs a low level, and the output pin 7 is directly connected to the INT0 pin of the AT89S52 to trigger an interrupt. If there is some error in the frequency, the external resistor R42 of the chip pin 5 can be adjusted to set the center frequency of the filter at 40 kHz to achieve the ideal effect.
3.3 Other main circuits
(1) Temperature measurement part.
Since the speed of sound varies at different temperatures, a temperature compensation function is used to improve the accuracy of the system. The main component used here is the single-bus digital temperature sensor DS18B20 produced by Dallas Semiconductor Corporation in the United States, which has the characteristics of high accuracy, intelligence, small size, and simple circuits. Temperature measurement can be achieved by connecting the DS18B20 data line to the P1.1 port of the microcontroller, as shown in Figure 4.
(2) LCD display part.
The display part of this design uses a character type TC1602 liquid crystal to display the measured distance value. The capacity of TC1602 display is 2 lines and 16 characters. The liquid crystal display has many advantages such as low power consumption, small size, rich display content, ultra-thin and light, easy to use, etc. Compared with the digital tube, it looks more professional and beautiful. When using, P0 can be connected to the data line of the LCD, and the P2 port can be connected to the control line of the LCD, as shown in Figure 5.
Among them, the 4th pin RS of TC1602 is the register selection, the 5th pin RW is the read/write signal line, and the 6th pin E is the enable terminal. The 7th to 14th pins: D0 to D7 are 8-bit bidirectional data lines. It should be noted here that for the convenience of wiring, D0 to D7 on the microcontroller side are connected to D1 to D0 on the LCD/602, which is just the opposite. Therefore, it is necessary to do some processing when writing the software to make the reading correct.
(3) Alarm part.
A buzzer is used, and a signal of a certain frequency is output by P1.2. Before being connected to the buzzer, it is amplified by a transistor 9012. The connection of the alarm part is shown in Figure 6.
(4) Power supply circuit: 220 V is stepped down by a 9 V transformer, then rectified by D1~D4 bridges and stabilized by 7805 to supply power to various parts of the circuit.
(5) Crystal oscillator circuit: Use a 12 MHz crystal oscillator.
4 Software
The system software design adopts modular design, which mainly includes main program design, T1 interrupt service subroutine, INT0 external interrupt service subroutine, temperature measurement subroutine, distance calculation subroutine, display subroutine, delay subroutine and alarm subroutine design.
When compiling the system software, the connection of related hardware should be considered, and the allocation and use of storage space, registers, timers and external interrupt pins should also be carried out. In this design, the P1.0 pin is connected to the 7 HC04 push-pull amplifier circuit and then to the ultrasonic transmitter sensor. The output of the P1.0 pin will be a 40 kHz square wave generated by software, and P3.2 (INT0) is used to receive the echo. Timers T1 and T0 both work in working mode 1, which is a 16-bit count. The T1 timer is used to start a ranging process and start a transmission measurement cycle with its overflow as a mark. The T0 timer is used to calculate the pulse round-trip time. Their initial values are set to 0.
After the system is initialized, timer T1 starts counting from 0. At this time, the main program enters the waiting state. When it reaches 65 ms, T1 overflows and enters the T1 interrupt service subroutine. In the T1 interrupt service subroutine, a new ultrasonic emission will be started. At this time, a 40 kHz square wave will be generated on the P1.0 pin, and timer T0 will be started. In order to avoid diffraction of the direct wave, a delay of 1 is required. ms later, INT0 interrupt is enabled again; after INT0 interrupt is enabled, if P3.2 (INT0) pin is low at this time, it means that the echo signal is received, and an interrupt request will be made to enter the INT0 interrupt service subroutine. In the INT0 interrupt service subroutine, timer T0 will be stopped, the time value of timer T0 will be read to the corresponding storage area, and the reception success flag will be set at the same time; once the main program detects the reception success flag, it will call the temperature measurement subroutine to collect the ambient temperature during ultrasonic ranging, and convert the accurate sound speed and store it in the RAM storage unit; the microcontroller will call the distance calculation subroutine to calculate and calculate the distance between the sensor and the target object; after that, the main program calls the display subroutine to display; if the minimum alarm distance is exceeded, the speaker alarm will be activated; when the process of transmitting, receiving and displaying is completed, the system will delay 100 ms to reset T1 to the initial value again, and start T1 again to overflow and enter the next ranging. If the obstacle is too far away and exceeds the range, so that the echo has not been received when T0 overflows, "ERROR" will be displayed and return to the main process to enter a new round of testing. The block diagrams of the main program and the timer T1 and external interrupt INT0 interrupt service subroutines are shown in Figures 7 to 9 respectively.
In addition, there are a few points that need to be explained:
(1) Timer T1 overflows every 65 ms because it is a 16-bit timer/counter (65,535). When using a 12MHz crystal oscillator, since the period T = 1/f = 1/[(12×106)/12] = 1μs, one machine cycle is 1μs, and the counter overflows every 65 ms.
(2) In this design, the generation of the 40 kHz square wave is implemented by software: the P1.0 port is controlled to output a high level for 12 μs and then a low level for 13 μs, thus obtaining a cycle of 40 kHz pulses, which are then sent 8 times in a cycle.
(3) After the CPU stops sending the pulse group, due to electrical damping, the transducer cannot stop sending ultrasonic waves immediately, and will continue to send them for a period of time. Therefore, during this period, INT0 cannot be immediately turned on to receive the echo. It is necessary to wait for a period of time to avoid that part of the direct wave from the transmitter is directly diffracted to the receiver without passing through the object being measured. This period is called "false reflection wave". From the start of transmission to the end of the "false reflection wave", the INT0 interrupt application is not opened, which can effectively avoid interference, but it will also cause a "blind area" in the test. This time it is set to 1 ms. Assuming the temperature is 20℃, the measurement blind area is s=1×10-3×344/2≈17.2 cm.
(4) The maximum test distance will depend on: the minimum time interval between two pulse groups and the energy of the pulse. Generally speaking, the more pulses the transmitter has, the greater the energy, and the farther the distance that can be measured. However, it is not unlimited. This time, the count value of timer T0 is read. The maximum test distance is that T0 has not overflowed. Therefore, at a temperature of 20°C, the maximum test distance is s=vt/2=65535×344/(2×106)=11.272 m. In some periodic ultrasonic transmission equipment, if the maximum distance to be tested is 10 m, the minimum time between two pulse groups is t=2×s/v=2×10/344≈60:ms.
5 Conclusion
In order to verify the measurement accuracy of the system, field measurements were carried out in the laboratory. The system was used to conduct multiple tests in the range of 20 to 1 000 cm. After compensation, the maximum error reached 2 cm, and the linearity, stability and repeatability were relatively good. The system has the advantages of simple structure, small size, real-time LCD display and alarm, temperature compensation, and good anti-interference performance. The error of the system mainly comes from the fact that the ultrasonic wave emitted by the transmitting probe is diffused in a horn shape, the surface of the object being measured is not smooth and is not necessarily perpendicular to the axis of the two probes, so the reflected waves may be obtained from different points. In addition, the delay and interference of the electronic components themselves also have a certain impact. According to the specific occasion, the appropriate power probe can be selected, and the frequency, width and number of pulses in the program can be adjusted to improve the accuracy or measurement distance and expand the application range of the system.
Previous article:Using single chip microcomputer to simulate 2272 software decoding
Next article:Design of intelligent lighting control system based on single chip microcomputer
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- DC-DC chips have current control mode and voltage control mode? How to understand?
- The permanent magnet synchronous motor keeps vibrating and turning back and forth
- Basic principles of STM32 serial communication
- 09. Anlu SparkRoad domestic FPGA evaluation [practical] key control VGA display
- VS1053 cannot read or write registers
- Several interesting GIF animations
- Several issues on the second-order low-pass filter circuit of voltage-controlled voltage source
- EEWORLD University Hall----Live Replay: Application of TI Precision ADC in Transmitter
- 【TI recommended course】#What is I2C design tool? #
- BQ40Z50-R2 security mode introduction and password modification method