Modern industry is developing towards intelligence and automation. As an important part of industrial production, ranging technology has increasingly stringent requirements for stability and accuracy. Traditional measurement methods can no longer meet the requirements of modern industrial measurement due to the influence of environment, tools and human factors. Ultrasonic ranging, as a non-contact ranging method, has been widely used in the field of industrial measurement due to its strong anti-interference ability [1-2], wide measurement range, easy control and high measurement accuracy. This system is designed for oil mud level measurement. The design measurement range is 50 cm~600 cm, and the design measurement accuracy is centimeter level. The system uses temperature compensation to correct the measurement data to ensure accuracy.
1 Working principle and system design
1.1 Principle of Ultrasonic Distance Measurement
Ultrasonic sensors are mainly composed of a dual piezoelectric chip vibrator, a conical resonance plate, and electrodes. When a certain voltage is applied between the two electrodes, the piezoelectric chip will be compressed and produce mechanical deformation. When the voltage is removed, the piezoelectric chip returns to its original state. If a voltage is applied between the two poles at a certain frequency, the piezoelectric chip will also maintain a certain frequency of vibration. The natural frequency of this type of piezoelectric chip is measured to be 38.4 kHz. When a square wave pulse signal with a frequency of 40 kHz is applied to the two poles, the piezoelectric chip resonates and emits ultrasonic waves. Similarly, an ultrasonic sensor without an external pulse signal will also resonate when the resonance plate receives ultrasonic waves, generating an electrical signal between the two poles [3].
1.2 System Principle Design
The hardware of this system mainly consists of ultrasonic emission, ultrasonic reception and amplification, single-chip control and LCD display, temperature acquisition and compensation, as shown in Figure 1. When the reset button is pressed to start the system, the single-chip microcomputer sends several 40 kHz square wave pulses to the sensor transmitter, and starts the timer to count the ultrasonic propagation time. When the receiving head receives the reflected ultrasonic wave (within the effective ranging range) and transmits it to the single-chip microcomputer after amplification and filtering, the timer stops counting. The sound speed at the ranging temperature is obtained by looking up the table, and the measured distance is calculated according to formula (1) and sent to the LCD display.
s=Ct/2 (1)
Where s is the measurement distance, C is the ultrasonic propagation speed, and t is the propagation time.
2 System Circuit Design
2.1 Ultrasonic transmitting circuit
Due to the harsh working environment of the system, in order to ensure the range and accuracy of the distance measurement, it is necessary to ensure that the external pressure difference of the sensor transmitter is large enough. Therefore, the 16-bit CMOS converter CD4049 with a large conversion range and stable operation is used to form the main body of the ultrasonic transmission circuit (the maximum conversion voltage of CD4049 and the maximum driving voltage of the probe are both 20 V). The ultrasonic transmission circuit is shown in Figure 2 [4].
Considering that the transmitter generally needs 5 square wave cycles to reach 95% of the stable oscillation state and 1.5 times the rise time to reach 99% of the stable oscillation state[5], in order to ensure the maximum degree of triggering, each group of 12 square waves with a bandwidth of 12 μs are generated by the microcontroller and transmitted to the transmitter through the conditioning circuit.
2.2 Ultrasonic receiving amplifier circuit
The attenuation of ultrasonic waves propagating in the air increases with the increase of propagation distance, so the reflected signal received by the receiving head is very weak and cannot be directly sent to the subsequent circuit for processing. It must first be amplified. The ultrasonic receiving and amplifying circuit is shown in Figure 3 [6].
The echo signal received by the receiving head is a sine wave signal, and the signal strength is generally only tens of millivolts. The preamplifier circuit of the receiving part is a bootstrap unidirectional AC amplifier circuit composed of an integrated operational amplifier NE5532. The first two stages of the amplifier circuit constitute a 10,000-fold amplifier, which can sufficiently amplify the sine wave signal. The back stage uses an integrated LM311-8 comparator to condition the preamplified signal, and introduces a standard level through the IN- pin. If the potential of the input envelope signal is higher than the standard level, it is 1, and if it is lower than the standard level, it is 0, which converts the envelope signal into an interrupt pulse signal that can be recognized by the microcontroller. When the 7th pin of the LM311 connected to the interrupt input terminal of the microcontroller outputs a low level, the counter immediately stops timing and saves the data.
2.3 MCU control and display circuit
The main control module of this system is AT89S52 single-chip microcomputer. The controller has 8 KB RAM memory space, which is convenient for online programming and debugging. The single-chip microcomputer control unit mainly includes reset circuit, LCD display circuit, transmission control terminal, and echo receiving terminal. Since the measured distance needs to be displayed intuitively, and the system is installed outdoors with low power consumption and small size, a 128×64 dot matrix LCD display module that is easy to match with CMOS circuit is used. The interface circuit is shown in Figure 4.
3 Software Design and Process
3.1 Overall software process
The system software mainly consists of the main program, initialization program, transmission subroutine, interrupt subroutine and display subroutine. The overall software flow is shown in Figure 5.
After the system is powered on, it is initialized first, the timer and counter working modes are set, the general interrupt is turned on, the display port is cleared, etc. In order to prevent the ultrasonic wave emitted from the transmitter from being directly received by the receiver as an echo, a delay of 0.2 ms is set after calling the timer interrupt subroutine (transmitting square waves), and then the external interrupt 0 is turned on to receive the echo [7]. The system uses a crystal oscillator frequency of 12 MHz and a machine cycle of 1 μs. After the main program detects that the echo is successfully received, the value T0 in the counter T0 is calculated according to the following formula to obtain the measured distance (assuming that the speed of sound is 340 m/s at 20 °C) [8]:
s=(CT0)/2=170T0/100 000 (2)
Finally, the obtained value is directly transmitted to the LCD display through the P0 port in binary form.
3.2 Transmit and Interrupt Subroutines
The function of the ultrasonic transmission subroutine is to generate high and low level output square wave pulses with a width of 12 μs by inverting the P1.2 port at the time of the timer setting. The flow of the timer interrupt program [9] is shown in Figure 6. The flow of the external interrupt program is shown in Figure 7.
4 Error analysis and system accuracy improvement
During the system testing process, it was found that the main factors that have a greater impact on system performance and measurement accuracy include measurement blind areas, echo time determination, controller timer deviation, and the impact of temperature on speed.
4.1 Measurement blind area
There are two main factors that cause the existence of measurement blind spots: the ultrasonic transmitter opens the external interrupt entrance after a delay after emitting a series of square wave signals, to prevent the square wave signal from directly entering the receiving head as an echo and causing interruption, resulting in erroneous measurement. The distance corresponding to the delay is the blind spot; on the other hand, when measuring closer distances, the echo signal will overlap with the emission afterwave, causing peak search failure, which also results in a measurement blind spot.
For the first type of measurement blind area, experiments have shown that reducing the pulse width and the number of pulses transmitted within an acceptable range can indirectly reduce the delay time and expand the measurement range. However, the reduction in the number of pulses will also affect the upper limit of the measurement. For the second type of measurement blind area, the main approach is to add a residual vibration absorption circuit to the echo receiving circuit, change the receiving amplification factor, delay appropriately, and use some unsaturated residual waves to reduce the blind area[10].
4.2 Determination of echo time
Due to the limited intensity of the transmitted square wave signal, after propagation and reflection, the echo signal intensity is attenuated and an envelope phenomenon occurs, but its frequency is the same as the transmitted wave and does not change. The moment when the microcontroller determines that the echo is received is actually a moment when the high and low levels change, which has nothing to do with the echo frequency. However, the envelope signal is not a high-quality level signal, and directly inputting it into the microcontroller will cause a large error. The solution is to add a level comparator to the receiving circuit, whose output frequency is also 40 kHz, and output a standard square wave level signal as a comparison. When the amplifier input (receives) a level signal higher than 0.4 V, the output voltage of the comparator becomes a standard +5 V level input to the microcontroller. This moment is the echo reception moment [11].
4.3 Temperature compensation
At normal temperature and pressure, the speed of sound can be considered a constant, but the working environment temperature of liquid level monitoring varies greatly. The relationship between the speed of sound and temperature is [12-13]:
v=311.5+0.607t (3)
If the temperature changes from -20℃ to +40℃, the speed of sound will change by 36 m/s, so the temperature compensation for the speed of sound must be set.
The sound velocity values at different temperatures are calculated offline and stored in the memory. After the 18B20 measures the field temperature and transmits it to the microcontroller, the sound velocity at the corresponding temperature is found and used as the correction value to calculate the distance. The sound velocity expression in the air can be written as:
It can be seen that the accuracy after temperature compensation reaches the centimeter level, which can meet the measurement requirements well. The experimental data when the measurement temperature is 11.2℃ is shown in Table 1. It can be seen from Table 1 that the upper limit of measurement is 600 cm, the lower limit is 50 cm, and the measurement error within the effective ranging range is less than ±2 cm.
A large amount of data shows that the measurement error of this system is less than ±2 cm, which meets the design requirements and complies with industrial standards. Based on the fact that ultrasonic waves are minimally affected by harsh industrial factors such as dust, vibration and electromagnetic waves, this system can also be widely used in industrial distance measurement, automobile driving, metal flaw detection and other fields, and has good application prospects.
Previous article:51 MCU initialization and control program for SAA7113
Next article:Based on the single chip microcomputer to communicate with the computer through the serial port
- Popular Resources
- Popular amplifiers
- Computer Vision Applications in Autonomous Vehicles: Methods, Challenges, and Future Directions
- Signal Integrity and Power Integrity Analysis (Eric Bogatin)
- Field Line Coupling---Electromagnetic_Field_Interaction_with_Transmission_Lines
- Non-invasive Blood Glucose Level Monitoring System for Diabetic Patients using Near-Infrared Spectro
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
- [SC8905 EVM Evaluation] Power Supply Ripple Test
- Mbed OS changes the way it is released
- STM32MP157A-DK1 Evaluation + SPI Device
- How to define a const structure variable
- [Silicon Labs BG22-EK4108A Bluetooth Development Review] Received the fastest, unboxing
- Introduction to three interrupt debugging methods of ARM
- Ask a superconductivity question
- CC2640R2F Single Carrier Code
- Essential PCB wiring rules for electronic hardware engineers: basic theories of right-angle routing, differential routing, and serpentine routing
- 【EETALK】What is the difference between traditional Bluetooth and low-power Bluetooth? Will traditional Bluetooth be replaced by low-power Bluetooth in the future?