Share this

Design and Application of CPLD in Ultrasonic Ranging Systems

2026-04-06 04:48:01 · · #1
Abstract: This paper analyzes the problems and causes of the use of microcontroller systems in ultrasonic ranging and proposes to use CPLD programmable logic devices specifically for ranging. The time in ranging is counted by using a high-precision crystal oscillator as the clock signal source, which can achieve high-precision and synchronous measurement. Keywords: CPLD, ultrasonic ranging, high precision, synchronization Design and Application of CPLD in the ultrasonic ranging system Abstract: This paper analyzes the problems and causes of the single-chip system in the ultrasonic ranging process, and proposes using a specially programmable logic device (CPLD) for ranging. Time in ranging is counted using a high-precision crystal oscillator as a clock signal source, carrying out high-precision and synchronous measurement. Keywords: CPLD, ultrasonic ranging, high precision, synchronization Introduction Ultrasonic ranging is a non-contact measurement method. Ultrasonic waves have advantages such as high frequency, short wavelength, strong directivity, slow energy consumption, long propagation distance, immunity to electromagnetic interference, stable echo performance, and high measurement accuracy. Ultrasonic detection is often rapid, convenient, computationally simple, and easy to control in real time, so ultrasonic ranging devices are commonly used for distance detection. Previously, single-chip microcomputer systems were used for ultrasonic ranging, with software controlling the transmission and reception of ultrasonic signals and the start and stop of the counter. This leads to asynchrony between the transmission of the ultrasonic signal and the start-up of the counter, and asynchrony between the signal received by the ultrasonic sensor and the signal detected by the microcontroller. Furthermore, because the microcontroller's counting frequency is low, the ranging error of the microcontroller system is generally on the order of centimeters. This cannot meet the requirements for precise measurement. This paper uses a CPLD to complete the transmission and reception of ultrasonic waves and accurately record the echo time, overcoming the speed limitation of the microcontroller. It can not only record the echo time with accuracy to the nanosecond level but also achieve synchronous measurement, thus meeting the requirements of high-precision engineering measurement. 1. Principle Block Diagram and Function of the CPLD Module The CPLD module mainly consists of five parts: a transmission module, a 16-bit timer/counter module, a receiving module, a sequential execution counter module, and a six-to-one data selector module. Its overall block diagram is shown in Figure 1. The CPLD module mainly completes the transmission, reception, and time measurement of ultrasonic waves. The ultrasonic transmitting module starts transmitting 125KHz ultrasonic waves. When the transmitted pulse train reaches the set value, the ultrasonic transmission is turned off, and the six-channel timer/counter module starts timing. The signal is reflected back after passing through an obstacle. After the receiving circuit receives the echo, it shapes it and uses it as the signal for the receiving module. After receiving all the echo pulse signals, the output terminal of the receiving module sends a signal to turn off the timer/counter and stop working. After all the echoes have been received, the output terminal of the sequential execution counter sends a signal to start the microcontroller to start receiving data. The six different count values ​​are read by the count value of the sequential execution counter, the selection terminal of the data selector, and the control terminal of the timer/counter. After all the data has been read, the count value of the timer/counter is cleared to prepare for the next cycle counting. [align=center] Figure 1 CPLD System Principle Block Diagram[/align] 2 CPLD System Functional Module Design 2.1 Transmitting Module Design 2.1.1 Port Description: CLK: Input port, connected to the crystal oscillator clock. CLR: Input port, after the microcontroller reads all the count values ​​of the timer/counter, it clears all the counters inside the CPLD to restore them to their initial state. START: Input port, enables the module to start outputting a 125kHz square wave. SEND: Output port, outputs a 125kHz square wave. SENDFINIS: Output port, after outputting a certain number of pulse trains, outputs a high level to start the timer counter. [align=center] Figure 2 Ultrasonic Transmitting Module[/align] 2.1.2 Function: The crystal oscillator is divided by a frequency divider to obtain a 125kHz square wave for transmission. When the microcontroller sends the control signal START=1, the 125kHz square wave transmission is started. After the pulse train is completed, SENDFINISH changes from low to high level, serving as the trigger pulse for the timer counter to start counting. 2.2 Receiver Module Design 2.2.1 Port Description REVCLK: Input port, receives the echo signal input. CLR: Input port, after all timer counter data is sent to the microcontroller, it resets all counter values ​​inside the CPU to zero. REVCOUNT: Output port, after receiving the echo signal, outputs a high level to stop the timer counter. [align=center]Figure 3 Ultrasonic Receiver Module[/align] 2.2.2 Function: After receiving the echo signal, the receiver module checks if its count value is the same as the transmitted pulse train value. If they are the same, RECOUNT turns off the timer counter; otherwise, the output state remains unchanged. 2.3 Timer Counter Module Design 2.3.1 Port Description: A: Input port, data selection terminal. When A=0/1, read the high/low 8 bits of the timer counter respectively. CONCLK: Input port, control port for reading the timer counter value; CLK: Input port, connected to the crystal oscillator clock. CLR: Input port, after all timer counter data is sent to the microcontroller, it resets all counter values ​​inside the CPU to zero. SEND: Input port, input high level to start the timer counter. REV: Input port, after the receiver module receives the echo signal, input high level to turn off the timer counter. CE: Input port, enables sending the six count values ​​to the data bus respectively. DB[0…7]: Output port, sends the timer counter value to the microcontroller. [align=center]Figure 4 Timer/Counter Module[/align] 2.3.2 Function: The crystal oscillator clock is divided to obtain the counting frequency, which is used as the clock pulse for the 16-bit timer/counter. When SEND is high, the timer/counter starts counting; when REV is high, the timer/counter stops counting. Since its count value is a 16-bit binary number, it is sent to an 8-bit microcontroller for processing. By controlling the high and low levels of port A, the 16-bit count value is divided into high and low 8 bits. Combined with the CE and CONCLK ports, the 16-bit count value is sequentially sent to the microcontroller via the data bus. 2.4 Sequential Execution Counter Module Design 2.4.1 Port Description REVCOUNT A…F: Input port. After the receiving module receives the signal, it outputs a high level, causing the FINISH port of the data sending module to notify the microcontroller to start receiving data. RDCLK: Input port. The microcontroller sequentially reads the pulse signal of the count value of the timer/counter. CE1-CE6: Output ports, enabling the corresponding timer/counter modules. FINISH: Output port, starts the microcontroller to prepare for receiving data. [align=center] Figure 5 Sequential Execution Counter Module[/align] 2.4.2 Function: After all receiving modules have received data, the FINISH port outputs a high level to trigger the microcontroller to enter the data receiving state. The microcontroller sends a signal to the RDCLK port of the data transmission module to start the sequential execution counter. The count value increments by 1 each time, and the output port enables the corresponding timer counter. The microcontroller then reads the count value from the corresponding timer counter. The order of selecting the timer counters is listed in Table 1. Table 1 Order of Selecting Timer Counters 2.5 Sequential Execution Counter Module Design 2.5.1 Port Description: A2, A1, A0: Input ports, selection terminals for each timer counter. DB[7…0]: Output port, sends the timer counter value to the microcontroller. X0[7…0]-X5[7…0]: Count values ​​of each timer counter. [align=center] Figure 6 Data Selector Module[/align] 2.5.2 Function: Select the six timer counters through the selection terminals A2, A1, and A0 of the data selector, and then send the count value to the microcontroller through DB[7…0]. The order of selecting the count value is shown in Table 2. Table 2 Order of Selecting Count Values ​​3. Microcontroller Reads Data This system module is mainly for the transmission and reception of 125KHz ultrasonic waves, as well as the measurement of the time between transmission and reception of the six ultrasonic waves. Finally, the count value is read out through the data bus by the microcontroller control signal and sent to the microcontroller. However, in order to read the data accurately, the execution process of reading the count value is as follows: (1) When the port FINISH of the sequential execution counter module is 1, the microcontroller is notified to prepare to receive data. (2) Select the count value of the timer counter to be read by the data selector through A2, A1, and A0. (3) Select the timer counter by the pulse input of RDCLK. (4) Use A to select the high and low 8 bits of the timer counter value to be output. (5) Use the control signal CONCLK to read the high and low 8 bits of the value. Conclusion Using CPLD programmable logic device for distance measurement, the system response time is in the nS level, which effectively improves the system accuracy and meets the requirements of accurate distance measurement. In addition, the six ultrasonic sensors work simultaneously, realizing synchronous data acquisition. This provides a possibility for the application and promotion of ultrasonic in the field of precision measurement. References: [1] Cheng Tiedong, Yang Lirong. High-precision ultrasonic ranging system of CPLD and single-chip microcomputer [J]. Single-chip microcomputer and embedded system application, 2005: 17-19. [2] Ge Jianqiang. Development of ultrasonic rangefinder based on CPLD [J]. Journal of Wuxi Commercial Vocational and Technical College, 2004, 4(3): 8-10. [3] Bian Jinian. Digital Logic and VHDL Design [M]. Beijing: Tsinghua University Press, 2005.
Read next

CATDOLL 136CM Seina

Height: 136cm Weight: 23.3kg Shoulder Width: 31cm Bust/Waist/Hip: 60/54/68cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22
CATDOLL Rosie Hard Silicone Head

CATDOLL Rosie Hard Silicone Head

Articles
2026-02-22
CATDOLL 140CM Qing TPE

CATDOLL 140CM Qing TPE

Articles
2026-02-22