Design of Ultrasonic Distance Meter

Publisher:SereneHeartLatest update time:2012-01-06 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Ultrasonic rangefinders are widely used in car reversing, construction sites and some industrial sites. Its measurement range is 0.10~4.0 m, and the measurement accuracy can be as high as about 1 cm.

This design uses the new 8051 controller c8051f020, and the system uses a 22.1184MHZ high-precision crystal oscillator to obtain a stable time frequency to reduce measurement errors. C8051f020 uses the P3.0 port to output the 40khz square wave signal required by the ultrasonic transducer, and uses the interrupt port to detect the return signal output by the ultrasonic receiving circuit. The display circuit uses an SPI extended LCD1602 liquid crystal.



The focus of this design is the ultrasonic receiving and transmitting circuit.

The ultrasonic transmitting circuit is shown in Figure 1.2





Figure 1.2

The transmitting circuit is mainly composed of the inverter 74HC04 and the ultrasonic transducer. The 40khz square wave signal output from the P3.0 port is sent to one electrode of the ultrasonic transducer through the inverter, and the other is sent to the other electrode of the ultrasonic transducer after passing through two-stage inverters. This method can improve the transmission intensity of the ultrasonic wave.

The ultrasonic receiving circuit is shown in Figure 1.3

Figure 1.3

Integrated circuit CX20106A is a dedicated chip for infrared reception, commonly used in TV infrared remote controls. The commonly used carrier frequency 38khz is close to the 40khz of distance measurement, so it can be used as a receiving circuit. Appropriately changing the size of C3 can change the sensitivity and anti-interference ability of the receiving circuit.

The display circuit is shown in Figure 1.4

Use the SPI of c8051f020 to drive 595 to control lcd1602. LCDCS is the chip select signal of 595.

This design defines the chip select signal as P3.1.

sbit LCDCS P3^1;

Another focus is the algorithm calculation of ultrasonic ranging.

D = S/2(v+t)/2 --------------------------------------------------------------------------- (1-1)

Where D is the distance between the object to be measured and the rangefinder.

S is the round trip distance of the sound wave.

V is the speed of sound.

T is the time taken.

C8051F020 has rich peripherals. This design only uses external interrupts and some pins of SPI. On this basis, a lot of content can be added. Purely using the front and back systems will limit the timeliness of the system. In the next article, I will introduce in detail the transplantation of ucos_II based on c8051f020.

Code part:

//----------------------------------------------------------------------------------

// SPI_Init()

//----------------------------------------------------------------------------------

void SPI0_Init (void)

{

SPI0CFG = 0x07; // data sampled on 1st SCK rising edge

// 8-bit data words

SPI0CFG|=0x40; //CKPOL =1;01000111

SPI0CN = 0x03; // Master mode; SPI enabled; flags


// cleared

SPI0CK R = SYSCLK/2/2000000-1; // SPI clock <= 8MHz (limited by

// EEPROM spec.)

}

void MSPI_SendData(unsigned char ddata)

{

LCDCS = 0; // Chip select HC595

SPIF = 0;

SPI0DAT = ddata;

while (SPIF == 0); // Wait for the completion of writing

LCDCS = 1;

}

Reference address:Design of Ultrasonic Distance Meter

Previous article:Easy step-down conversion using simulated ripple mode
Next article:Main factors affecting insulation resistance measurement during testing

Latest Test Measurement 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号