Share this

Design of a high-precision water level monitoring instrument based on a single-chip microcomputer

2026-04-06 06:07:53 · · #1
Abstract: This paper studies and designs a high-precision water level monitor based on a microcontroller. The entire system is described in detail from three aspects: hardware design, software design, and system anti-interference design. The system uses the highly integrated mixed-signal system-on-a-chip C8051F021 to realize signal acquisition and processing, and completes the SPI interface task between the AD421 and the microcontroller, coordinating the relationship between the AD421, AD7705 chip, and the microcontroller to form an SPI bus system. The system solves the problems existing in previous water level monitors and meets the various standards of high-precision water level measuring instruments. Keywords: Water level monitoring; Microcontroller; Analog-to-digital conversion 1 Introduction Water level monitors are widely used in automatic detection and control systems in fields such as water conservancy, petroleum, chemical, metallurgy, and power. Currently, some water level monitors have some problems during operation, such as: system instability, poor anti-interference ability, low accuracy, output control or display signals not meeting requirements, cumbersome on-site program modification or upgrade, and poor communication capabilities. The intelligent water level monitoring instrument designed in this paper absorbs the design experience of the latest intelligent instruments at home and abroad. It adopts an industrial control microcontroller and integrates water level acquisition, storage, display and remote networking. It is suitable for various liquid level measurements and gate opening measurements. 2 System Hardware Overall Design The main functions considered in the hardware part of this system are: analog quantity conversion; analog quantity acquisition; application of high-precision 16-bit analog-to-digital converter AD7705 in the system; application of precise clock chip DS1302; four-channel relay alarm, the relay driver chip adopts ULN2003; application of 4~20mA current loop output digital-to-analog converter AD421 to provide system detection signals; interface implementation for communication with the upper microcomputer. The system block diagram is shown in Figure 1. [align=center] Figure 1 System Hardware Schematic Diagram[/align] In this system, the main control chip we selected is the highly integrated MCU chip C8051F021. The C8051F microcontroller is a fully integrated mixed-signal system-on-a-chip (SoC). It features a high-speed CIP-51 core compatible with the 8051 and an instruction set fully compatible with the MCS-51. It integrates commonly used analog and digital peripherals and other functional components in data acquisition and control systems. It has built-in FLASH program memory and internal RAM; most devices also have XRAM located in external data memory space. The C8051F microcontroller has on-chip debugging circuitry, allowing for non-intrusive, full-speed online system debugging via a 4-pin JTAG interface. 2.1 SPI Communication Interface Design In the system design, two external chips utilize the SPI interface: AD7705 and AD421. The microcontroller and these two peripheral chips form an SPI bus system. The microcontroller's NSS pin is left floating and connected high by an on-chip pull-up resistor. Because the AD421 is a 4-20mA output digital-to-analog converter chip, its data line connection with the microcontroller is only master output and slave input, i.e., MOSI. The connection of the SPT system in the water level monitor is shown in Figure 2. [align=center] Figure 2 SPI interface system schematic diagram[/align] 2.2 Analog-to-digital conversion design In this design, we selected two analog-to-digital conversion circuits. The first is to use the 12-bit ADC on the microcontroller, which is used in the variable resistor channel. The other is the external high-precision analog-to-digital conversion chip AD7705, which has a precision of 16 bits and is used in the data acquisition of the pressure sensor channel. The following is a calculation of the precision that can be achieved in the specific application. In the design of the water level monitor, we ignore the front-end error of the analog circuit. The precision in millimeters can be calculated by Equation 1: (1) It can be calculated that when the measurement range a=10m, if a 12-bit ADC is used, the measurement precision is 2.44mm; if a 16-bit ADC is used, the measurement precision can reach 0.153mm. Our design requirement is to be accurate to 2 mm, so if a 16-bit ADC is used, it can fully meet our design requirements. In the design, due to the inherently low measurement accuracy of the variable resistor method, a 12-bit ADC on the microcontroller was used. To maximize measurement accuracy and minimize measurement errors, another channel of the microcontroller was used to acquire the power supply voltage of the variable resistor. The two were appropriately integrated in the software, which will not be detailed here. For the pressure sensor channel, an external ADC conversion chip, AD7705, was selected. The AD7705 chip has two analog channels, which are used for our two pressure sensor channels. Channel switching is performed in the software. 2.3 Alarm Circuit Design The four alarm circuits in this system are implemented using the microcontroller's I/O ports and the Darlington driver chip ULN2003. The output is then connected to the relay control terminal. The ULN2003 consists of 7 Darlington transistor arrays, corresponding resistor networks, and clamping diode networks. It has the ability to drive 7 loads simultaneously and is a single-chip bipolar high-power high-speed integrated circuit. The relay selected is the G6B-1174P model, with a 24V power supply. The internal electrical structure connection diagram is shown in Figure 3. This system design uses four relay signal output alarms, including high water level 1, high water level 2, low water level 1, and low water level 2. These four alarm water level heights can be manually set and modified via the lower-level computer buttons or the upper-level computer interface. Taking high water level 1 as an example, when the water level is between high water level 1 and high water level 2, the microcontroller sends a switch control signal to make the normally open contact of the corresponding relay conduct. The specific alarm method can be flexibly selected; an alarm light or alarm bell can be connected in series in the external circuit. When the relay is activated, the corresponding alarm starts (manifested as the light illuminates or the bell rings). [align=center] Figure 3 Alarm Circuit Principle Block Diagram[/align] 2.4 Design of 4-20mA Current Loop Output Digital-to-Analog Conversion Circuit and Clock Circuit In microcomputer industrial measurement and control scenarios, there are often situations where the analog voltage signal to be measured is far from the measuring equipment. It is obviously unreasonable to directly send the analog voltage signal to be measured into the measuring equipment through a long line. The common method is to amplify and filter the analog signal to be measured at the measurement site, then transform it before long-distance transmission, and finally convert it back into a voltage signal near the measuring equipment for measurement. Signals suitable for long-distance transmission in industrial measurement and control systems are generally current source or frequency signals. To convert the analog voltage signal to be measured into a current source signal for transmission, a voltage/current converter circuit is often used. This system uses a high-performance digital-to-analog converter AD421, whose output signal is a 4-20mA current loop. In microcontroller applications, to ensure real-time performance, a clock circuit is needed to provide a clock signal (year, month, day, hour, minute, second). We selected the DS1302 chip from Dallas Semiconductor. The main control chip C8051F021 used in the water level monitor has two serial ports. In our design, one is used for communication with the host computer, and the other is used for communication with the encoder. Therefore, the interface design between the clock module and the microcontroller can only use the second interface method, i.e., using ordinary I/O ports to simulate the working timing. This clock chip has very strict timing requirements. Timing is closely linked to hardware; internal registers and latches all have strict timing requirements, highlighting the importance of combining hardware and software during development. Data transmission errors caused by timing issues were encountered during program design, but these were ultimately resolved successfully. 2.5 Design of the Serial Communication Circuit In this design, two communication methods were used for the serial port between the lower-level computer and the upper-level microcomputer: RS-232 communication and RS-485 communication. The RS-232 communication level was implemented using the MAX202 conversion chip. The MAX202 is suitable for RS-232 communication in noisy environments. Each transmitter output and receiver input can withstand ±15kV electrostatic discharge (ESD) without needing to be sealed. The MAX202 has two drivers and two receivers. It is a bidirectional converter designed for RS-232C to TTL/CMOS level conversion in the absence of ±12V power. The MAX202 operates on a +5V power supply, and its maximum level conversion speed is no less than 120kbps. The MAX202 requires few external components, only four 0.1μF capacitors, further reducing cost and space consumption. In our design, we used the SN65LBC184 level converter chip. The SN65LBC184 is a differential data line transceiver within the industry standard range of the SN5176, featuring built-in high-energy transient noise protection. This design feature significantly improves reliability against transient noise on data synchronization cables. The differential driver design integrates a slew-rate-controlled output, capable of transmitting data at a rate of 250kbps. Slew-rate control allows for longer unterminated cable operation and longer stub lengths from the trunk, as well as faster voltage transitions, compared to uncontrolled operation. The unique receiver design provides high-level output failure protection when the input is floating (open circuit). The SN65LBC184 receiver includes a high input resistance equivalent to 1/4 unit load, allowing up to 128 similar devices to be connected on the bus. The SN65LBC184 operates from -40°C to +85°C, thus meeting the environmental requirements for operation. To prevent mutual interference between the host and slave computers, using opto-isolation devices is a simple and effective method. In the RS-485 interface circuit, we also selected the high-speed optocoupler 6N136. The connection circuit is shown in Figure 4, where the power supply label +5 (2) indicates the +5V power supply output from the DC-DC module. [align=center]Figure 4 RS-485 Interface Circuit Diagram[/align] 3 Software Design of the Water Level Monitoring System In our water level monitoring system design, we selected Cygnal IDE as the software debugging environment. Cygnal IDE is an integrated development environment tailored for the C8051 series microcontrollers. We integrated the tools of the Kei18051 compilation environment into Cygnal IDE, thus forming a development environment that integrates editing, compiling, downloading code, and online debugging, which is very convenient for developing microcontroller programs. In our system, the overall program design is divided into two main modules: the initialization module and the loop execution module. The corresponding subroutines are: the system initialization subroutine and the loop subroutine, which are called by the main program. The system initialization subroutine initializes the I/O, external oscillator, AD/DA, timer, DART, SPI, and interrupt system. The loop subroutine is an infinite loop that includes the initialization of the display section and the loop body. Within the loop body, we not only complete the display functions but also handle semaphores that the system should continuously query, such as button presses, interrupt enable switching for corresponding channels, and control processing of relay output signals. The author's innovations include: this water level monitor meets the design requirement of 1mm accuracy; it can largely overcome external interference and achieve stable operation; it features a multi-functional design, accommodating various usage methods, with functions selectable according to specific requirements; and it facilitates human-machine operation, allowing for the setting and modification of various parameters, thus meeting the requirements of intelligent operation to a certain extent. References [1] Wang Binqi, Chen Hongwei, Jiang Guangwen. ADC application elements in C8051F020 [J]. Microcontroller & Embedded System Application. 2002, 11 [2] Pioneer Studio. Microcontroller Programming Examples [M]. Tsinghua University Press, 2003. [3] Gao Yushui, Wang Huli, Wang Hui. Application of photoelectric rotary encoder in missile simulator [J]. Electronic Design Application, 2003, 08. [4] Yu Guoqing, Chen Huanwen, Tang Fuliang. Design and implementation of remote water level automatic measurement system [J]. Microcomputer Information, 2007, 7-1: 95-96
Read next

CATDOLL Q 92CM Body with TPE Material

Height: 92cm Weight: 13kg Shoulder Width: 25cm Bust/Waist/Hip: 47/47/56cm Oral Depth: 3-5cm Vaginal Depth: 3-13cm Anal ...

Articles 2026-02-22