Design of digital ultrasonic distance meter based on AT89C51 single chip microcomputer

Publisher:chaohuangmeitaoLatest update time:2012-08-03 Source: 电子发烧友Keywords:AT89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:AT89C51 Reference address:Design of digital ultrasonic distance meter based on AT89C51 single chip microcomputer

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

Sharing of DC motor PWM speed control program based on AT89C51 single chip microcomputer
This is a PWM speed control program for DC motors with AT89C51 MCU. The program can be directly used in AT89C52, AT89S51, AT89S51, STC89C51, STC89C52 MCUs. The MCU crystal uses 11.0592M. The DC motor is controlled by L298 integrated circuit. The frequency of the generated PWM is about 91Hz. The pins of L298 have been
[Microcontroller]
Sharing of DC motor PWM speed control program based on AT89C51 single chip microcomputer
Design of Multi-point Temperature Detection System Based on AT89C51
0 Introduction In industrial production and daily life, multi-point temperature detection systems are widely used, such as non-destructive temperature detection of fire protection electrical equipment, overheating fault prediction detection of power equipment, temperature detection of air-conditioning syste
[Microcontroller]
Design of RFID car anti-theft system based on GSM network
1. Features of anti-theft system Early car anti-theft systems were mainly composed of mechanical door locks and wheel locks. The function of the car locks has evolved from simply controlling the opening of the car door to controlling the ignition and manipulating the car circuit. With the development of moder
[Microcontroller]
Design of RFID car anti-theft system based on GSM network
Design of automatic range switching frequency with AT89C51 microcontroller as the core
In recent years, with the rapid development of science and technology, especially the rapid rise of related integrated circuit production technologies such as microcontrollers, it has promoted the rapid development of the instrumentation and home appliance industries. Program codes are used to simplify the complexity
[Microcontroller]
Design of automatic range switching frequency with AT89C51 microcontroller as the core
Single chip microcomputer (AT89C51) timer/counter experiment case
case analysis Here are three types that are often encountered: It is known that the 8051 microcontroller's fosc=12MHz is timed by T1. Try to program the P1.0 pin to output a square wave with a period of 2ms. Given that the 8051 microcontroller has a fosc of 12MHz and uses T1 for timing, try programming the P1.0 pi
[Microcontroller]
Single chip microcomputer (AT89C51) timer/counter experiment case
Design of time/displacement commutation controller based on microcontroller AT89C51
introduction In the actual production process, control components with automatic reversing functions are often used, such as round-trip operation (displacement) in machining, forward and reverse output of DC power supply, forward and reverse operation of motors, etc. When the forward (or reverse) operation reaches a
[Microcontroller]
AT89C51 digital electronic clock
This digital clock can achieve a variable precision clock with an accuracy error of ≤ 1S/day, and can easily adjust the clock, time, timing time, etc.              LED1 bit p1.0; LED definition         led2 bit p1.1              led3 bit p1.2         led4 bit p1.3        led5 bit p1.4        led6 bit p1.5         led7
[Microcontroller]
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号