With the development of network communication technology, the application of Ethernet in the field of industrial control is becoming more and more extensive. The remote monitoring system based on Ethernet realizes the effective integration of remote monitoring, control and management [2]. Use the remote monitoring system to monitor the industrial production process through the network, timely understand the on-site information, and make quick decisions.
The key technology of remote control lies in how to solve the network access problem of industrial field equipment. At present, there are two main methods: one is to use a PC to collect data through a PC port (such as RS232, USB interface) or a data acquisition card while providing a network interface [3], this method uses powerful PC software support It is easy to implement network communication functions, but the PC port resources are limited, and the cost of the dedicated acquisition card is high, which is difficult to promote; the other is to use an embedded system to achieve network access in the field. The embedded system has low power consumption and small size. Low cost, high reliability, strong real-time characteristics, etc., it is more suitable to be used in industrial control field.
This article combines embedded technology and network technology, uses the embedded system to realize the network communication function in the field to transmit the liquid level signal and the control signal in real time, and realizes the remote communication with the field embedded system through the socket programming on the client PC , So as to achieve remote liquid level monitoring.
1 Remote liquid level monitoring system structure
The structure of the remote liquid level monitoring system designed in this paper is shown in Figure 1: Among them, the processor chip uses ARM microprocessor S3C44B0X; S3C44B0X comes with 8-channel 10-bit ADC for A / D conversion to collect liquid level data, which is realized by expanding DAC0832 D / A conversion to output control quantity; S3C44B0X connects to 10M Ethernet card RTL8019AS to provide hardware interface for network functions; μC / OS-Ⅱ is transplanted to S3C44B0X to provide operating system support, which facilitates the development of application programs and the entire system Management; the embedded TCP / IP protocol stack LwIP is transplanted to the μC / OS-Ⅱ platform to realize the software processing of network data, thereby providing network communication functions for the embedded system; the remote PC client logs in to the embedded system server , Real-time data exchange between the two ends through Ethernet.
Figure 1 Structure diagram of remote liquid level monitoring system
2 Hardware introduction and design
Samsung's S3C44B0X microprocessor chip uses ARM's 16 / 32-bit ARM7TDMI RISC structure CPU core with a main frequency of 66MHz. It provides a wealth of peripheral functions by expanding a series of general peripheral components. Its storage system has 8 memory banks, each with 32MB of storage space, allocated through 8 chip selects of nGCS0-7. In the design scheme used in this article, nGCS0 is connected to Flash chip AM29LV160DB, the starting address is 0x00000000, the size is 2MB, nGCS6 is connected to SDRAM chip HY57V641620ET-7, the starting address is 0x0c000000, the size is 8MB, nGCS3 is connected to RTL8019AS, and the starting address is 0x06000000.
RTL8019AS is a highly integrated full-duplex Ethernet controller that can simultaneously transmit and receive speeds up to 10Mbps; supports 8-bit and 16-bit data buses, and 8 interrupt request lines to choose from; supports UTP, AUI and BNC automatic detection ; Built-in 16K SRAM for data buffering, paging structure in units of 256B, you can allocate the size and position of the page for sending and receiving, generally the first 12 pages are used for sending buffer, the last 52 pages are used for receiving buffer; Comes with sending and receiving CRC check, FIFO logical queue, etc., reducing the workload of the main CPU to process network data. S3C44B0X's operation of RTL8019AS mainly focuses on the reading and writing of the network card register and the processing of SRAM in the network card.
3 Software design
3.1 Server-side programming based on embedded system
3.1.1 Transplantation of μC / OS-Ⅱ on S3C44B0X
The embedded operating system μC / OS-Ⅱ can run on various types of microprocessors. It has a small core, high efficiency, and has a high degree of modularity and portability. It supports multi-task real-time scheduling and can be supported after expansion. Network functions, graphical interfaces, etc. make application development easier and more feature-rich.
Before using μC / OS-Ⅱ, we must first transplant it to S3C44B0X, the transplantation work mainly includes three aspects [4]:
(1) Set the code related to the processor and the compiler, including the definition of a series of data types, the implementation of the interrupt macro and the interrupt macro, and define the growth direction of the stack;
(2) Write 6 operating system related functions in C language: OSTaskStkInit () initialization task stack structure, and 5 hook functions OSTaskDelHook (), OSTaskSwHook (), OSTaskStatHook (), OSTImeHook (), OSTaskCreateHook ();
(3) Write 4 processor-related functions in assembly language: the ready-to-run task function OSStartHighRdy () with the highest priority, task-level task switching function OS_TASK_SW (), interrupt-level task switching function OSIntCtxSw (), clock tick Service function OSTIckISR ().
3.1.2 Implementation of TCP / IP protocol stack on μC / OS-Ⅱ
LwIP (Light-weight IP) is a set of open source TCP / IP protocol stack developed by Adam Dunkels of the Swedish Institute of Computer Science (Swedish InsTItute of Computer Science) and others [5]. LwIP is reduced on the basis of maintaining the main functions of the TCP / IP protocol The occupation of RAM makes it suitable for use in low-end embedded systems.
The LwIP protocol stack has been designed to separate all the parts related to the transplantation of hardware, operating system, compiler, etc. in the / src / arch directory. Therefore, the implementation of LwIP on μC / OS-Ⅱ is to modify the files in this directory [6].
(1) Parts related to CPU and compiler
Mainly the definitions of data length and word order in cc.h, cpu.h, peRF.h files, these should be consistent with the definition of parameters when implementing μC / OS-Ⅱ. In addition, under normal circumstances, the C language structure struct is 4 bytes aligned, but when processing data packets, LwIP uses the length of different data in the structure to read the corresponding data, so, be sure to Use the _packed keyword when defining a struct to let the compiler give up the byte alignment of the struct.
(2) The part related to the operating system
LwIP needs to use semaphore communication, so the semaphore structure sys_sem_t and related semaphore processing functions should be implemented in sys_arch.h and sys_arch.c: including creating a semaphore structure sys_sem_new (), releasing a semaphore structure sys_sem_free (), Send semaphore sys_sem_signal (), request semaphore sys_arch_sem_wait ().
LwIP uses message queues to buffer and transfer data packets, so the message queue structure sys_mbox_t and corresponding operation functions must be implemented in sys_arch.h and sys_arch.c: including creating a message queue sys_mbox_new () and releasing a message queue sys_mbox_free (), Send a message sys_mbox_post () to the message queue, get the message sys_arch_mbox_fetch () from the message queue.
Each thread connected to the external network in LwIP has its own TImeout attribute, that is, waiting for the timeout time. The migration work needs to implement the sys_arch_timeouts () function to return the timeout queue pointer corresponding to the currently running thread.
The processing of network data in LwIP requires threads to operate, so it is necessary to implement the function of creating a new thread sys_thread_new (). In μC / OS-II, there is no concept of threads, only tasks. Therefore, you must encapsulate the function OSTaskCreate () to create a new task before you can implement sys_thread_new ().
(3) Implementation of related library functions
Eight external functions are used in the LwIP protocol stack, mainly to complete the exchange of high and low bytes of 16-bit data, swapping the size of 32-bit data, return string length, string comparison, memory data block copy, data of specified length Block clearing and other functions are related to the system or compiler and need to be implemented by the user.
(4) Network device driver
There can be multiple network interfaces in LwIP, and each network interface corresponds to a netif structure. This netif contains the attributes and sending and receiving functions of the corresponding network interface. The main function of the network device driver is to implement four network interface functions: network card initialization, network card receiving data, network card sending data, and network card interrupt processing function.
3.2 Design of client program on PC
The client program implementation in VC ++ 6.0 environment includes the following parts:
(1) Establish the client's Socket: The client application first constructs a CAsyncSocket [7] object CltSock, and then calls the CltSock.Create () function to establish the CltSock entity.
(2) Make a connection request: The client socket CltSock makes a connection request to the server socket by calling the CltSock.Connect (strAddr, nPort) function.
(3) Data transmission: Overload message processing functions OnReceive () and OnSend () in the client application. Receive data from the server side by calling the CltSock.Receive () function in OnReceive (); send data to the server side by calling the CltSock.Send () function in OnSend ().
(4) Close the connection: The client socket CltSock closes the connection by calling the CltSock.Close () function.
4 Development of remote level monitoring application
The remote control relay self-tuning PID control system based on Ethernet designed in this paper is completed. The control algorithm is implemented on the remote host (client), the two ends communicate through TCP protocol, and the local embedded system (server) It realizes the processing of network data, on the one hand, it completes the collection and control of the liquid level height; on the one hand, it processes the real-time data on the network on the remote PC, on the one hand, it calculates the control amount through PID, and displays the relevant parameters. The real-time liquid level changes are shown in Figure 2. From the figure, it can be seen that the actual liquid level (red curve) can be stabilized at the liquid level set value (blue curve). At the same time, not only can read the liquid level height value, PID self-tuning parameters, etc. from the user interface, but also can change the liquid level height setting value, so as to truly realize the remote monitoring of liquid level objects.
Figure 2 Remote liquid level relay self-tuning PID control effect diagram
This paper designs and solves the problem of implementing network functions in embedded systems, and introduces and implements a new design scheme, which uses Samsung ARM7 processor S3C44B0X + Realtek's 10M network card RTL8019AS hardware combination, by operating in μC / OS-Ⅱ With the support of the system core, the embedded TCP / IP protocol stack LwIP is added to realize the function of network communication, and Socket communication with the PC client. On this basis, a remote liquid level monitoring system based on Ethernet was developed, which achieved good Control effect. It can be seen that this type of system has good application prospects in remote monitoring.
The author's innovation: This article introduces embedded network technology into the field of industrial process remote monitoring, proposes its own design plan, and successfully develops a remote liquid level monitoring system.
FTTA IP68 Hardened Connections
Ftta Ip68 Hardened Connections,Ftta Ip68 Hardened Connections Adapter,Ftta Ip68 Hardened Connections Box,Ftta Ip68 Hardened Connections Cable
Huizhou Fibercan Industrial Co.Ltd , https://www.fibercaniot.com