Research and design of an ultrasonic sensor based on single chip microcomputer

Publisher:SereneMeadowLatest update time:2010-09-29 Source: 电子技术应用Keywords:Ultrasonic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:Ultrasonic Reference address:Research and design of an ultrasonic sensor based on single chip microcomputer

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

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号