Application of single chip microcomputer in ultrasonic distance measurement alarm system

Publisher:CrystalBreezeLatest update time:2014-01-22 Source: dqjsw Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  Ultrasonic waves have the advantages of good directionality, concentrated energy, low attenuation during transmission, and strong reflection ability. Ultrasonic sensors can be widely used in non-contact detection methods, so simulation technology is used for ultrasonic ranging.

  At present, the ultrasonic distance measurement ASICs in China have a measurement accuracy of only centimeters. By analyzing the causes of ultrasonic distance measurement errors, improving the measurement time difference to microseconds, and using the LM92 temperature sensor to compensate for the sound wave propagation speed, the designed high-accuracy ultrasonic distance meter can achieve millimeter-level measurement accuracy.

  1 Basic Principle of Ultrasonic Distance Measurement Alarm System

  As shown in FIG. 1 , the single chip microcomputer can receive the distance signal output by the ultrasonic module, and after reasonable processing, display the distance between the ultrasonic module and the obstacle in real time on the display module.

Figure 1 System connection diagram

Figure 1 System connection diagram

  The single-chip microcomputer sends out a 40 kHz square wave signal, which is amplified and output through the ultrasonic transmitter; the ultrasonic receiver amplifies the received ultrasonic signal through the amplifier, performs detection processing with the phase-locked loop circuit, and starts the single-chip microcomputer interrupt program. The measured time is t.

  Then the software is programmed to distinguish and calculate, and the measured distance value is obtained and displayed by the LED digital tube. The principle block diagram is shown in Figure 2.

Figure 2 Principle block diagram of ultrasonic rangefinder

Figure 2 Principle block diagram of ultrasonic rangefinder

  The ultrasonic wave emitted by the transmitter propagates in the air at a speed of v. When it reaches the object to be measured, it is reflected back and received by the receiver. The round trip time is t. The distance of the object to be measured is calculated by the formula: measured distance L (m) = sound speed 340 (m/s) at normal temperature × induction time t (s) / 2. Since ultrasonic wave is also a sound wave, its sound speed v is related to temperature. If the temperature does not change much, the sound speed can be considered to be basically unchanged. If the distance measurement accuracy is very high, it should be corrected by temperature compensation.

  2 System Hardware Design

  2.1 Principle of Ultrasonic Distance Measurement

  The MCU transmits a square wave at time T0 and starts the timer to count. When the echo is received, a negative jump is generated to the port of the MCU. The MCU responds to the interrupt program and the timer stops counting. By calculating the time difference, the time t of the ultrasonic wave propagating in the medium can be obtained, and the distance can be calculated from it. The timing diagram is shown in Figure 3.

Figure 3 Ultrasonic timing diagram

Figure 3 Ultrasonic timing diagram

  2.2 Hardware Circuit

  The design of the hardware circuit mainly includes three parts: the single-chip microcomputer system and display circuit, the ultrasonic transmitting circuit and the ultrasonic detection receiving circuit. The single-chip microcomputer adopts STC89C51 or its compatible series. A 12 MHz high-precision crystal oscillator is used to obtain a more stable clock frequency and reduce measurement errors. The single-chip microcomputer uses the P2.4 port to output the 40 kHz square wave signal required by the ultrasonic transducer, and uses the external interrupt 0 port to monitor the return signal output by the ultrasonic receiving circuit. The display circuit uses a simple and practical 4-bit common anode LED digital tube, the segment code is driven by the program, and the bit code is driven by the PNP transistor. [page]


  2.3 Hardware of each main module

  The STC89C51 chip pins and package are shown in Figure 4.

Figure 4 STC89C51 pinout

Figure 4 STC89C51 pinout

  Pin function description:

  (1) VCC: power supply voltage.

  (2) GND: Ground.

  (3) RST: Reset input. When the oscillator resets the device, the RST pin must be kept high for two machine cycles.

  (4) /EA/VPP: When /EA is kept at a low level, the external program memory (0000H-FFFFH) is used during this period, regardless of whether there is an internal program memory.

  (5) XTAL1: Input of the reverse oscillation amplifier and the input of the internal clock working circuit.

  (6) XTAL2: Output from the reverse oscillator.

  (7) Port 0: Port 0 is an 8-bit open-drain bidirectional I/O port, also known as an address/data bus multiplexing port. When used as an output port, each pin can absorb 8TTL gate current.

  (8) P1 port: P1 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P1 port buffer can absorb or output 4TTL gate current.

  (9) P2 port: P2 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P2 port buffer can absorb or output 4 TTL gate currents. When "1" is written to the P2 port, its pin is pulled high by the internal pull-up resistor and acts as an input.

  (10) P3 port: P3 port pins are 8 bidirectional I/O ports with internal pull-up resistors, which can absorb or output 4 TTL gate currents.

  Port P3 can also be used as some special function ports of AT89C52, as shown in Table 1.

Table 1 P3 special function port

Table 1 P3 special function port

  Port P3 receives some control signals for both flash programming and programming verification.

  (11) ALE//PROG: The address latch enable output level is used to latch the status byte of the address when accessing external memory.

  (12) /PSEN: Selection signal of external program memory.

  During instruction fetch from external program memory, /PSEN is valid twice in each machine cycle. However, when accessing external data memory, these two valid /PSEN signals will not appear. [page]


  2.4 Ultrasonic Transmitter Circuit

  The principle of the ultrasonic transmitter circuit is shown in Figure 5. Two inverters are connected in parallel at the output end to improve the driving ability. The upper resistors R10 and R11 can improve the driving ability of the inverter 74LS04 to output a high level, and on the other hand, they can increase the damping effect of the ultrasonic transducer and shorten its free oscillation time.

Figure 5 Schematic diagram of ultrasonic transmitting circuit

Figure 5 Schematic diagram of ultrasonic transmitting circuit

  2.5 Ultrasonic detection receiving circuit

  The integrated circuit CX20106A is a special chip for infrared detection and reception. Considering that the carrier frequency 38 kHz commonly used in infrared remote control is close to the ultrasonic frequency 40 kHz for ranging, it can be used to make an ultrasonic detection and receiving circuit (as shown in Figure 6). Experiments have shown that using CX20106A to receive ultrasonic waves (output high level when there is no signal) has good sensitivity and strong anti-interference ability.

Figure 6 Ultrasonic detection receiving circuit

Figure 6 Ultrasonic detection receiving circuit

  2.6 Display Circuit

  The display circuit uses a simple and practical 4-digit common anode LED digital tube, the segment code is driven by 74LS244, and the bit code is driven by PNP three-stage tube. The digital tube connected to the P2.1 pin is the ones-digit display digital tube, and its decimal point is displayed when P2.1 is valid. This function is completed by software.

  2.7 Reset Function

  The system should have a ranging start function that can reset the system to start ranging again.

  In summary, the characteristics of this system are to use a single-chip microcomputer to control the emission of ultrasound and the timing of the round-trip time from the emission to the reception of ultrasound. The single-chip microcomputer uses STC89C52, which is economical and easy to use, and has an 8K ROM on the chip for easy programming. The circuit principle is shown in Figure 7.


  3 Software Solution

  The system software design adopts modular design, which mainly includes main program design, T0 interrupt service subroutine, external interrupt service subroutine, distance calculation subroutine, LED display subroutine design, etc.

  The main program first initializes the system environment, sets the working mode of timer T0 to 16-bit timer counter mode, sets the general interrupt enable bit EA and clears the display ports P0 and P2 to 0.

Figure 7 Circuit principle Baidu Button BEGIN
Reference address:Application of single chip microcomputer in ultrasonic distance measurement alarm system

Previous article:Design of single chip microcomputer in LED aquarium light source
Next article:Design of single chip microcomputer in wireless ward pager

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号