Ultrasonic waves are often used to measure distances due to their strong directivity, slow energy consumption, and long propagation distance. For example, distance meters and level meters can be realized through ultrasonic waves. Ultrasonic distance measurement is mainly used in reversing radars, construction sites, and some industrial sites. For example: liquid level, well depth, pipeline length, etc. Ultrasonic detection is often quick, convenient, simple to calculate, easy to achieve real-time control, and can meet industrial practical requirements in terms of measurement accuracy. Therefore, it has also been widely used in the development of measurement and control systems. This article introduces a low-cost, high-precision, miniaturized digital display ultrasonic distance meter with AT89C51 microcontroller as the core hardware circuit and software design method.
1 Principle of Ultrasonic Distance Measurement
1.1 Ultrasonic generator
Ultrasonic waves are mechanical waves with a frequency of more than 20kHz. In order to study and use ultrasonic waves, people have designed and manufactured many ultrasonic generators. Generally speaking, ultrasonic generators can be divided into two categories: one is to generate ultrasonic waves by electrical means. The other is to generate ultrasonic waves by mechanical means. Electrical means include piezoelectric, magnetostrictive and electric types; mechanical means include Galton flute, liquid whistle and airflow whistle.
The frequency, power and sonic characteristics of the ultrasound waves they generate vary.
Therefore, the uses are also different. At present, the piezoelectric ultrasonic generator is more commonly used.
1.2 Principle of Piezoelectric Ultrasonic Generator
Piezoelectric ultrasonic generators actually work by using the resonance of piezoelectric crystals. The internal structure of the ultrasonic generator is shown in Figure 1. It has two piezoelectric chips and a resonance plate. When transmitting ultrasonic waves, the piezoelectric chip in the piezoelectric sensor resonates after being stimulated by the transmitting electric pulse, and drives the resonance plate to vibrate, thus generating ultrasonic waves. When receiving ultrasonic waves, no external power is applied between the two electrodes. The resonance wave receives the ultrasonic wave and compresses the piezoelectric chip to vibrate, converting the mechanical energy into an electrical signal.
1.3 Principle of Ultrasonic Distance Measurement
Ultrasonic distance measurement can be divided into two types in principle: resonance type and pulse reflection type. Since the application requirements of the resonance method are complex, the pulse reflection type is used here.
The principle of ultrasonic ranging is to transmit ultrasonic waves in a certain direction through an ultrasonic transmitter, and start timing at the same time as the transmission. Ultrasonic waves propagate in the air. If they encounter an obstacle on the way, they will return immediately. The ultrasonic receiver will stop timing immediately when it receives the reflected wave. The propagation speed of ultrasonic waves in the air is C, and according to the time difference t between the emission and the reception of the echo recorded by the timer, the distance s between the emission point and the obstacle can be calculated. That is: S: Ct/2. This is the so-called time difference ranging method. Since ultrasonic waves are also a kind of sound waves, their sound speed c is related to temperature. Table 1 lists the sound speeds at several different temperatures. When in use, if the temperature does not change much, the sound speed can be considered to be basically unchanged. If the ranging accuracy is very high, it should be corrected by temperature compensation.
Once the speed of sound is determined, the distance can be calculated by measuring the time it takes for the ultrasonic wave to travel back and forth. This is the mechanism of the ultrasonic distance measurement system.
2 System Hardware Circuit Design
ATMEL's AT89C51 microcontroller is a low-power, high-performance 8-bit CMOS microcontroller with 4KB Flash ROM on chip. The operating voltage range is 2.7~6V (actually using 105V power supply).
It has a programmable full-duplex serial communication interface that can simultaneously transmit and receive serial data. It communicates with the outside world through the RXD pin (serial data receiving end) and the TXD pin (serial data transmitting end). This ultrasonic ranging system uses the AT89C51 as the central processor, and its system principle block diagram is shown in Figure 2.
After the system is powered on, the pulse generator sends out a pulse signal. On the one hand, the pulse signal drives the pulse generator to send out ultrasonic pulses through the driving circuit, and on the other hand, it triggers the internal timer T1 of AT89C51 (implemented by external interrupt INT0) to start timing; at the same time, AT89C51 controls to automatically change the gain of the amplifier according to time, that is, gradually increase the amplifier gain according to the propagation time before the transmitted wave reaches the receiver. After amplification and filtering, the received ultrasonic echo is directly sent to the amplitude detector, and the peak value of the echo is extracted as the reference information of the threshold through the peak holding circuit. AT89C51 samples the echo peak value through ADC0809, and after software weighted processing, it is used as the identification threshold, and then sent to the amplitude detector through DAC0832. When a wave in the echo envelope is identified, the external interrupt INT1 is immediately triggered to turn off the timer T1, and at the same time, P1.1 sets the detection window; the number of echoes in the TO counter window is identified as 12, and the size of the next identification given value is determined according to n, and the closed-loop control is carried out until n≤5. Then take out the compensation value corresponding to rl from the compensation value table, correct the timing of T1 (actually this is the count value from the emission of the ultrasonic wave to the reception of the first identification echo, the count cycle is 1US, 12M vibration), obtain the actual reciprocating propagation time of the ultrasonic wave, and then calculate the distance through 3-byte floating point operation, and send it to the LED display through the AT89C51 serial communication port. This system samples the ambient temperature every 5s to correct the sound speed, so a temperature sensor can also be added to the system to monitor the ambient temperature, and the data listed in Table 1 can be used in the program for temperature compensation. [page]
3 Compensation and ranging principles
Objects of different shapes and positions have similar echo waveforms, but different amplitudes. Therefore, the system adopts a variable threshold amplitude fixed compensation method:
(1) Use microprocessor closed-loop control to automatically change the threshold;
(2) Identify the first wave with less than 6 waves near the envelope peak in the ultrasonic echo, form a trigger signal for closing the timer, and set the detection window at the same time;
(3) Count the number of identification echo formats n (identification echo = number of identification echoes in the window + 1) within the detection window;
(4) Determine the size of n. If n>5, reduce the identification threshold and go to (2) for re-detection. If n≤5, take out the compensation value corresponding to n from the a priori fixed compensation value table for correction. The identification echo extraction and compensation time are shown in Figure 3.
Compensation correction formula:
It can be seen that different At correspond to different values, which are obtained as prior data through actual testing and observation, and a compensation value table is established and stored in the memory.
The error of this ultrasonic ranging system is mainly composed of system error, environmental error, detection error, timing time error, compensation time error, etc. After the system adopts the variable closed value fixed compensation method, the time error can be compensated to a small extent.
The S/N ratio of the detection signal is improved, thereby improving the accuracy and range of ultrasonic ranging.
4 Software Design of Ultrasonic Ranging System
AT89C51 single-chip microcomputer and its development application system have many advantages, such as concise language, good portability, strong expression ability, flexible expression, structured design, direct control of computer hardware, high quality of generated code, and easy use. The ultrasonic rangefinder is developed and designed using AT89C51 single-chip microcomputer. It adopts modular design and consists of modules such as main program, timing program, and display subroutine. Here is the main program block diagram. As shown in Figure 4.
5 Conclusion
For ultrasonic sensors with fixed materials and structures, the detection wave characteristics remain unchanged, that is, the re-transmitted sensor emits ultrasonic waves under the same excitation voltage source, and the waveform change law of the reflected wave will not change due to the change of the object type and distance, but the amplitude is different. Therefore, the system adopts the variable threshold amplitude fixed compensation method to reduce the error and thus improve the ranging accuracy. The system transmits a pulse voltage of 20V, and has made multiple measurements of flat objects. It is found that the ranging range is 10m and the ranging accuracy is 0.2%. It can be seen that the ultrasonic ranging system designed based on the single-chip microcomputer has the characteristics of simple hardware structure, reliable operation, and small measurement error.
Therefore, it can be used not only in mobile robots but also in other detection systems.
Previous article:51 single chip electronic clock complete version
Next article:A highly reliable MCU system monitoring solution
Recommended ReadingLatest update time:2024-11-16 23:41
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
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
- Guwei LCR819 bridge cannot be tested maintenance record
- MP2459 related circuit solution
- TI Industrial Robots Online Seminar Resource Sharing
- Power Optimized 77GHz Liquid Level Transmitter Reference Design
- [Gifts to give away] STMicroelectronics Power and Discrete Devices (PDSA) Quiz with Prizes!
- Enjoy the Avnet Artificial Intelligence Cloud Exhibition and challenge the 60-day check-in learning and development record!
- How is the domestic isolated power supply module doing? There are many manufacturers now.
- Detailed explanation of dBm, dB, and dBc
- AutoCAD Eagle is in my game
- 460 Questions on Frequency Conversion Speed Regulation