Application of Single Chip Microcomputer in Ultrasonic Distance Measurement System

Publisher:心动代码Latest update time:2011-08-25 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

In an autonomous walking robot system, the robot must collect environmental information in real time to avoid obstacles and navigate in an unknown and uncertain environment. This must be achieved by relying on a sensor system that can perceive environmental information. Visual, infrared, laser, ultrasonic and other sensors are widely used in walking robots. Ultrasonic ranging methods are widely used because they are simple, cheap, small, simple in design, easy to control in real time, and can meet industrial practical requirements in terms of measuring distance and measurement accuracy. The robot introduced in this article uses a three-way ultrasonic ranging system, which can provide information about the movement distance for the robot to identify the environment in front, left and right of its movement.

1 Principle of Ultrasonic Distance Measurement

The ultrasonic generator is composed of 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, thus generating ultrasonic waves. On the contrary, if no external voltage is applied between the two poles, when the resonance plate receives ultrasonic waves, it becomes an ultrasonic receiver. There are generally two methods for ultrasonic ranging: ① Take the average voltage value of the output pulse, which is proportional to the distance, and the distance can be measured by measuring the voltage; ② Measure the width of the output pulse, that is, the time interval t between transmitting and receiving ultrasonic waves, and obtain the measured distance based on the measured distance s=vt?2. Since the ultrasonic velocity v is related to temperature, if the temperature changes greatly, it should be corrected by temperature compensation.

This measurement system adopts the second method. Since the measurement accuracy requirement is not particularly high, the temperature can be considered to be basically unchanged.

This system uses PIC16F877 microcontroller as the core, and realizes real-time control of peripheral circuits through software programming, and provides the required signals to the peripheral circuits, including frequency vibration signals, data processing signals, etc., thereby simplifying the peripheral circuits and having good portability. The block diagram of the system hardware circuit is shown in Figure 1.

Since this system only needs to know whether there are obstacles in front, on the left, or on the right of the robot, and does not need to know the specific distance between the obstacle and the robot, there is no need for a display circuit. It only needs to set a distance threshold so that when the distance between the obstacle and the robot reaches a certain value, the microcontroller controls the robot's motor to stop. This can be achieved through software programming.

2 Ultrasonic transmitting circuit

The center frequency of ultrasound is 40kHz, which can be generated by the following program (part of the source program):

2.1 Ultrasonic transmitting circuit

The ultrasonic transmitter circuit is based on PIC16F877. When the microcontroller is powered on, the microcontroller generates a 40kHz ultrasonic signal from the RA0 port. However, the signal cannot enter the amplifier circuit through the NAND gate to enable the ultrasonic transmitter to transmit the ultrasonic wave. Only when the switch S1 is closed, a gate signal with a frequency of 4kHz is transmitted from the RA1 port. At the same time, the timer TMR1 inside the microcontroller is started to start counting. For each cycle of the waveform emitted by the gate signal, the ultrasonic wave will emit 10 complete waveforms, which can be obtained from their frequencies. The period of the ultrasonic wave is 1 (40kHz) = 01025ms, and the period of the gate signal is 1 (4kHz) = 0125ms. Finally, the distance between the obstacle and the mobile robot is calculated according to s = vt2. When the ultrasonic receiver receives the reflected ultrasonic wave, the counter stops counting, and the time t can be calculated according to the counter count and the period of the gate signal. The RA2 port is connected to the RS trigger, which can automatically control the emission and stop of the ultrasonic wave. The circuit of this system also includes a manual reset circuit, which is controlled by connecting the MCLR pin of the microcontroller to S2. The ultrasonic transmission circuit diagram is shown in Figure 2.

2.2 Gate control circuit (RS trigger)

In order to realize automatic control of ultrasonic emission and reception, a gate circuit must be added to the circuit. The frequency of the gate signal is 4kHz. If the output pulse is used as the gate signal and the pulse of known frequency fc is allowed to pass through the gate, then t=NTc, where Tc is the period of the known pulse and N is the number of pulses.

The gate circuit is composed of an RS flip-flop. When the input terminal R=1 (S=0), it is reset, that is, the output terminal Q=0; when R=0 (S=1), it is set, that is, Q=1. The RS flip-flop is connected to the RA2 port of the microcontroller.

2.3 Ultrasonic Amplifier Circuit

The ultrasonic amplification circuit is composed of transistors, etc. Since the RA port of the microcontroller has a maximum pull-up current of only 20mA to 25mA, and the ultrasonic transmitter requires a minimum current of 60mA, an amplifier circuit is added after the NAND gate to amplify the current to complete the ultrasonic emission. The ultrasonic amplification and transmission circuit is shown in Figure 3.

3 Ultrasonic receiving circuit

3.1 Ultrasonic receiving amplifier circuit

Since the ultrasonic signal received by the ultrasonic receiving head is very weak, an ultrasonic receiving amplifier circuit needs to be added after it. This circuit uses two integrated operational amplifiers, which are designed as two stages. Both stages are in-phase inputs. Because the voltage amplification factor of the in-phase input is 1+RfR, the amplification factor of each stage is 10, and the two-stage amplification factor is close to 100 times, so that the subsequent circuit can easily detect the input signal. The integrated operational amplifier is powered by dual power supplies. The ultrasonic receiving amplifier circuit is shown in Figure 4.

3.2 Signal filtering circuit

The sound waves coming out of the signal amplifier circuit have certain interference. In order to remove the interference signal, a filter circuit is needed. The signal filter circuit uses a bandpass filter circuit with a center frequency of 40kHz and a bandwidth of 2kHz. A zero-crossing comparator is added to convert the output signal into a square wave signal. The signal filter circuit is shown in Figure 5.

3.3 Signal Shaping Circuit

The square wave signal coming out of the signal filtering circuit is very irregular, so a shaping circuit is added after it. The shaping circuit consists of two stages of NOT gates connected in series and a resistor in parallel. After shaping, it is sent to the single-chip microcomputer for processing. The signal shaping circuit is shown in Figure 6.

4 Software Programming

The software adopts modular design and consists of a main program, a launch subroutine, etc. The software program flowchart is shown in Figure 7.

5 Conclusion

The ultrasonic distance measurement system designed in this paper adopts single chip microcomputer programming technology and completes the system requirements with hardware. Its accuracy can meet most engineering needs. Compared with the traditional distance measurement system, it has the characteristics of simple structure, low price and good portability.

Reference address:Application of Single Chip Microcomputer in Ultrasonic Distance Measurement System

Previous article:CAN bus controller IP core code analysis
Next article:Remote Communication System Designed Based on Single Chip Microcomputer 8251 and MODEM

Latest Industrial Control Articles
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号