In order to adapt to the diversified rural sewage control technology and improve the quality of rural sewage effluent, it is necessary to design a controller with high reliability and data upload.
The design of rural sewage treatment controller first realizes reliable hardware circuit according to the requirements of process control and on-site use environment. Then, according to the idea of software hierarchical design, the software of single chip computer is divided into three layers to realize reliable control of application software. At the same time, field data is uploaded to data center through GPRS technology. In this way, the normal days of effluent are effectively increased. At present, most of the rural sewage is treated in situ by the terminal equipment of sewage treatment. There are many treatment processes, such as constructed wetland process, A? O process, purification tank process and so on. The corresponding control methods are also different. Simple control and controller failure will directly affect the service life of power equipment, such as pumps, as well as the normal water quality. After the construction of operation and maintenance data center, the controller also needs to upload the main data of the field, including flow data, equipment operation status data and so on, to the data center through GPRS technology. For this reason, according to the characteristics of the environment and control technology of the controller, a single-chip controller is designed to meet the requirements of reliable control technology and data upload, and effectively improve the normal days of effluent.
The hardware is mainly composed of single chip computer, 3-channel isolation 485 circuit, 1-channel isolation 232 circuit, FLASH circuit, DC-DC circuit, RTC clock circuit, 6-channel relay output circuit (DO), 10-channel digital input circuit (DI) and 6-channel analog input circuit (AI). The overall hardware structure is shown in Figure 1. The reliable operation of the system is very important for the reliability design of DC power supply. The system is mainly used for 24V and 5V power supply. The 24V power supply uses Mingwei switching power supply NES-50-24. MCU has high demand for power supply.
The DC-DC circuit composed of LM2596-5.0 is changed from 24V to 5V. It has fewer peripheral components, high conversion efficiency and fewer heating. It is suitable for working in outdoor high temperature environment. The minimal system of single chip computer consists of integrated resources, program download circuit and system clock circuit. SCM uses STC15W4K32S4, which includes 32K program space and 4K SRAM, 26K EEPROM, 62 I/O ports, integrated MAX810 reset circuit, 4 independent full-duplex serial ports, integrated hardware watchdog, 10-bit high-speed 8-way ADC, support ISP and USB download, and built-in high-precision R/C clock. MCU has the advantages of 2.5V to 5.5V wide voltage and high anti-interference. STC15W4K32S4 MCU has strong anti-interference ability and can work in industrial environment. The minimum system of single chip computer is shown in Fig. 2. Generally, the values of C5 and C6 capacitors are the same, meeting the feedback coefficient of 0.5. However, due to the actual PCB, the existence of line partial capacitance and the need of anti-jamming, the capacity of C6 can be reduced appropriately. Through experiments, C5 is 30P, C6 is adjusted to 12P.
ISP and USB interface circuit is composed of R1, R2, D3, D4. MCU uses 5V power supply, D3 and D4 regulators can protect the USB interface. Y1 crystal oscillator uses 24M to provide clock for USB download. GPRS signal has been widely used in rural areas. Through GPRS DTU module, the data collected by single chip computer can be sent to the data center. Because the distance between single-chip computer and GPRS module is less than 5 meters, thermostatic element as long as RS232 interface is designed on the single-chip computer, data transmission between GPRS module and single-chip computer can be realized.
The contactor of single-chip computer, pump and fan is placed in the same electronic control box. The spark and surge interfere greatly, and the working environment is bad. For this reason, RS232 interface adopts ADI company’s RS232 transceiver ADM3251E, which has 2.5KV complete isolation. It is small in size, high in reliability and suitable for working in industrial environment. In rural domestic sewage treatment, electromagnetic flowmeter or ultrasonic flowmeter are usually installed at the sewage inlet and outlet. The microcontroller collects the cumulative flow and instantaneous flow through 485 interface and according to the communication protocol provided by the instrument. After processing the data, it uploads the data to the server in time through GPRS. The actual distance between flowmeter and MCU is usually more than 15 meters, and the flowmeter has RS485 interface. It is necessary to design RS485 interface for MCU to read instantaneous flow and cumulative flow. Considering the working environment of MCU, RS485 interface chip uses ADI company’s RS4885 transceiver ADM2587E with 2.5KV complete isolation, small size, high reliability, 15 kV ESD protection, suitable for industrial environment. The circuit adopts mature, typical circuit, integrated isolation power supply and signal isolation in the chip, with high reliability. The 485 interface circuit is shown in Figure 3. When SCM is powered on, the power supply is not stable, the system is still in power-on reset state, P2.0 defaults to weak pull-up, 485 bus is in transmission state, the bus will be occupied, at this time, the bus is occupied affecting the communication of other nodes. By using R5 pull-down resistance, the level of P2.0 is forced to pull to low level during power-up. The 485 bus is in receiving state, which does not affect the transmission of communication data of other nodes on the bus. After the power supply is stabilized, P2.0 is set as push-pull output, which can control the receiving and sending state of 485 bus, and ensure that only one node on the 485 bus can be sent. Status.
ADM2587E bus has 15 kV ESD protection.
In order to adapt to the Multi-lightning environment in rural areas and reduce the surge voltage in series, D5, D6, D7 bidirectional transient diode protection is added to the bus. In rural sewage treatment process, switching signals are mainly collected, including liquid level signals, fault signals, equipment operation signals, etc. The signal is transmitted by 24V, which has strong anti-interference and long transmission distance.
The circuit is equipped with a signal indicating lamp, which is convenient for maintenance and debugging. The switch signal is changed to 5V or 0V signal through the photocoupler TIL521, which is read by the PC port of MCU.
The system software adopts layered software design structure. As shown in Figure 4. It includes application layer program, data processing layer program and hardware driver layer program. According to the control requirements of different rural sewage treatment processes, the application program of application layer compiles different control applications.
Through data processing layer, the hardware driver layer program is indirectly controlled and read to achieve the purpose of operating hardware resources. The software system uses the front and back system. The application layer program flow chart is shown in Fig. 5. The program initializes the RAM and hardware resource registers inside the MCU, as well as the hardware resources such as real-time clock and GPRS module. Then, by calling the data processing program of power equipment, real-time clock, flow meter, Flash, GPRS, timing and automatic control program of data processing layer, the control, data access, data upload and other purposes can be achieved. The data structure of power equipment includes water pump, fan, air compressor, deceleration motor, cable float switch, float switch, fault signal, open door signal, hand automatic signal, operation signal, etc. The application program reads or writes the data structure of power equipment by calling the data processing program of power equipment in data processing layer. The data of power equipment can be used by automatic control program and GPRS data processing program. Real-time clock data structure includes year, month, day, hour, minute, second and so on. The flow meter data structure includes cumulative flow and instantaneous flow. The data structure of automatic control program mainly includes control steps and timing. GPRS data processing program mainly completes the encapsulation of power equipment, traffic and real-time clock data, sends AT instructions to GPRS DTU module, sends data to operation and maintenance data center, receives instructions from operation and maintenance data center, and sends heartbeat packets to operation and maintenance data center on time. Data processing layer mainly implements the interception of communication data content, the increase of data header and verification, data format conversion, data structure assignment, numerical calculation and other operations. Data processing layer is mainly composed of power equipment data processing program, real-time clock data processing program, flow meter data processing program, Flash data processing program, GPRS data processing program, timing data processing program and so on. The data processing program of power equipment directly or inversely assigns the data structure of power equipment to the simple DI and DO signals, but the float DI signals are liable to jitter between seconds and tens of seconds when the water and the float are in contact with each other. Therefore, according to the field application, the software should adjust the delay connection time of the float, and only after the delay processing can the float DI signals be assigned. The value is given to the signal variable of the power equipment.
For AI value, data processing program of power equipment needs 1-5 voltage corresponding to current value of 4-20 mA. After calculation, meaningful values are obtained, such as market voltage, current value of pump, and then assigned to analog data structure of power equipment, which is called by supply layer. Single-chip microcomputers often use 485 interface to collect flow. This method is more accurate than the 4-20MA interface acquisition method. The following is the data processing flow of collecting instantaneous flow or cumulative flow for flowmeter by single chip computer. The flow of collecting instantaneous flow is shown in Figure 6. The MCU first sends the address and command to the flow meter with the specified address, then waits for receiving the timeout, intercepts the flow data content in the data string after checking the correct data string according to the third party agreement provided by the flow meter, calculates the instantaneous flow, assigns the value to the flow data structure of power equipment, and calls the supply layer. The process of collecting cumulative flow and instantaneous flow is the same, but the command code sent is 01. Hardware driver layer, including DI driver, DO driver, AI driver, IIC driver, SPI driver, UART driver, T0 interrupt driver. Hardware driver layer program is mainly the operation of internal registers of single chip computer. The hardware corresponding to the DI driver is the input port of the single chip computer, which reads 0 or 5V signals from the optocoupler, and then puts them into the array variables after delayed de-jitter processing. Array variables can be read by data processing program of power equipment in data processing layer.
The hardware corresponding to the DO driver is the output port of the single chip computer, which controls the relay and the LED signal lamp. DO driver reads the data processed from the data processing layer of power equipment. By judging 0 and non-0, the output port of MCU is set to 0 or 1. AI driver corresponds to the AD input port of MCU, collects 1-5V voltage, and stores the original value into a specified array for further processing layer of data processing program of power equipment, and converts it into meaningful data. The IIC driver corresponds to the common I/O port of the single chip computer. The IIC timing is simulated through the I/O port. The data of SD3088 clock chip is read and the real-time clock data processing program corresponding to the data processing layer is uploaded. SPI driver reads and writes Flash data in W25Q64BV data storage chip through SPI active mode of MCU. UART driver corresponds to four full duplex serial ports of MCU, and can communicate with flowmeter and GPRS module. According to the requirements of rural sewage treatment technology, field use environment and reserved data upload function, this paper realizes reliable hardware interface circuit and three-tier software based on STC15W4K32S4 single-chip computer. Through the application of sewage treatment project, the design of hardware circuit and layered software, and the use of GPRS data upload function, the hardware failure rate of the system is low, the troubleshooting time is short, the control is reliable, and the normal days of effluent are effectively increased.