In this paper, a design scheme of RTU controller is proposed to solve the problem that field equipment can not be controlled manually under special circumstances. According to the scheme, the hardware and software of the controller are designed, and the acquisition of field signals and the control of field equipment are realized. The design has the advantages of high stability, real-time data receiving and receiving, low bit error rate and easy installation. It can be widely used in many fields, such as urban transportation, energy, power and oil fields. It has very important practical significance to improve the level of automatic control and production efficiency of equipment control in various industries. RTU is a data transmission and controller based on sensor technology and micro-control technology. It can monitor the signal of receiving equipment and send the monitored signal to the monitoring terminal. After receiving the commands issued by the monitoring terminal, the output devices accessed by the local computer can be controlled to achieve remote control of the field equipment or the field environment. According to the functional requirements of the system, the structure of the RTU controller system is shown in Figure 1.
The system takes the microcontroller STM32F103C8 as the core device, and extends the input detection circuit, communication circuit, display circuit and output control circuit to realize the functions of data acquisition, transmission and output control. After the system is powered on, the input of two analog and digital quantities is collected, and the collected results are sent to the microcontroller for processing, and the processed results are sent to the LCD for display. When the display is completed, the data will be packaged and sent simultaneously through the Ethernet interface and RS485. When the transmission is completed, two communication ports are set in the receiving state at the same time, ready to receive monitoring host data. After receiving the command issued by the monitoring host, the output of two digital quantities is controlled according to the command. The core control unit of this design is the minimal system of microcontroller, which consists of STM32F103C8 chip, crystal oscillator circuit and reset circuit.
The minimum system circuit is shown in Figure 2. The input detection circuit uses AD8420 to convert the 4-20mA current into voltage signal to realize analog-to-digital conversion function, and two TPL521 optocouplers to convert the input 24V signal into 3.3V signal output to realize the acquisition of the input digital signal. The input detection circuit is shown in Figure 3. The input 4-20mA signals are converted from Ain1 and Ain2 through two 5R resistors to DC signals and then connected to the two feet of U 2 and U5. The circuit is amplified 28 times to 0.6-2.8V voltage, and output through Aout6 and Aout8.
Aout6 and Aout8 are connected with PB0 and PB1 pins of microcontroller. The program acquires the input analog value by reading the output of ADC_IN8 and ADC_IN9. The 24V voltage signal input from D1 and D2 is decompressed by R11 and R15 and then connected to the photocoupler generator. The output terminals D1_IN and D2_IN are connected to the pins PB2 and PB3 of the microcontroller. When the photocoupler is turned on, the D1_IN and D2_IN pins will appear high-level signals, that is, if STM32 detects high-level signals in PB2 and PB3, it can confirm that there are external digital signal inputs. Conversely, if a low level is detected in PB2 and PB3, it means that there is no external digital signal input. Output control circuit consists of relay and optocoupler, which is used to output 24V control signal. The optocoupler is used to isolate the pin of STM32 and the coil control pin of the relay, so as to prevent the interference coming from the main control chip from affecting the normal operation. The circuit is shown in Figure 4.
The LCD circuit is shown in Fig. 5. The microcontroller controls LCD1602 through PB8-PB11 pins. The communication circuit includes Ethernet communication circuit and RS485 communication circuit. The Ethernet communication circuit is designed by SPI interface Ethernet module W5500, and the RS485 communication circuit is implemented by ISO3082. The circuit is shown in Figure 6. STM32 and W5500 communicate with each other through 4-wire SPI interface. Its PA4-PA7 connects to the SPI control pin of W5500. When receiving and receiving receipts, STM32 first outputs high levels through PA4 pins, enabling W5500 to work. Then the read-write pulse is output on the PA5 pin, the configuration data is written to W5500 through the PA6 pin, and the return data of W5500 is obtained by reading the output value of the PA7 pin. STM32 is connected to ISO3082 through serial port 1. The sending line of serial port 1 is connected to 6 feet of ISO3082 and the output line is connected to 4 feet of 3082. After the circuit works, if it needs to send data, the PA8 output of STM32 will be high level, so that ISO3082 will enter the data transmission state, and then the data will be written to the serial port 1 transmission buffer. When data need to be read, the low level output of PA8 pin makes 3082 enter the data receiving state. When serial port 1 applies for receiving interrupt, data can be received by reading the data of receiving buffer. According to RTU system hardware, software can be divided into two parts: main program and communication program. The main program is used to collect local input data, and call communication subroutines to complete data interaction with the monitoring host. It can control the action of the output device according to the received data and respond to the control commands issued by the monitoring host. The main program first initializes the execution parameters, reads the local data once after initialization, and controls the LCD1602 LCD to display the current collected data. Then the program enters the while (1) loop and executes the actions shown in Figure 7 sequentially. The main function of communication program is to judge the sending and receiving of data. The data sending function is used to upload local data, and the receiving function is used to receive commands from the host and provide data support for the output control end of the host. The communication program flow is shown in Figure 8. The format of the data frame sent by the monitoring host is shown in Table 1. The data in Table 1 indicates that commands are issued to terminal nodes with address 192.168.1.116, and control nodes Relay 1 and Relay 2 are not output. The format of data frame uploaded by this machine is shown in Table 2. The data in Table 2 shows that the nodes with 192.168.1.118 address upload data to the network ports. The Relay 1 and Relay 2 bits of this machine are output.
The acquisition value of analog 1 is 254, the acquisition value of analog 2 is 255, and there are no digital input in this machine. This paper presents a design scheme of RTU controller based on STM32 microcontroller. Through the design of software and hardware, the controller realizes the functions of local data acquisition, thermostatic element display and remote data interaction, and can control the output of digital quantity according to the command of the receiving end, so as to realize the control of access equipment. The RTU controller designed in this paper provides an effective means for the automation control of industrial field equipment. It can change the traditional control concept, simplify the control operation, improve the control efficiency and create greater economic benefits.