“In the long-term use of PLC, programmable controllers have gradually exposed technical limitations such as simple loop opening; poor communication expansion capabilities; cumbersome ladder language programming; and inconvenient debugging. With the rapid development of computer technology, information technology and industrial control technology, higher requirements are put forward for the development of PLC, which are mainly reflected in: the need for higher-function, faster, and larger-capacity PLC products to complete large-scale control Projects and realization of networking and stronger communication capabilities; require more reliable control and more stable performance; require diversified and more convenient programming languages.
In the long-term use of PLC, programmable controllers have gradually exposed technical limitations such as simple loop opening; poor communication expansion capabilities; cumbersome ladder language programming; and inconvenient debugging. With the rapid development of computer technology, information technology and industrial control technology, higher requirements are put forward for the development of PLC, which are mainly reflected in: the need for higher-function, faster, and larger-capacity PLC products to complete large-scale control Projects and realization of networking and stronger communication capabilities; require more reliable control and more stable performance; require diversified and more convenient programming languages.
For this reason, Nanjing Nanrui Automatic Control Co., Ltd. has developed a new generation of MB series intelligent programmable controllers, which inherit the advantages of traditional PLCs and make up for the technical weaknesses of traditional PLCs. It is a great improvement to traditional PLC functions. The product integrates intelligence, reliability, openness, and flexibility, and is suitable for applications in a variety of complex control fields.
2. Design of MB series intelligent programmable controller
2.1 MB series intelligent programmable controller structure
The MB series intelligent programmable controller adopts the LAN/FieldBus system architecture and provides a standard Ethernet interface to complete the communication with the host computer system. Between the main control module and the intelligent I/O module, the fieldbus CAN is used as the internal bus and expansion bus. The unique high reliability of the fieldbus and the adaptability to the field environment make the MB series intelligent programmable controller system configuration The flexibility and reliability are greatly improved. Figure 1 shows the architecture of the dual-master hot standby redundancy mode.
Using VxWorks Embedded Operating System to Realize the Software and Hardware Design of MB Series Intelligent Programmable Controller
Figure 1 MB series intelligent programmable controller architecture
On the Intel x86 hardware platform, the Tornado integrated development environment of WindRiver is used to realize the programmable controller based on VxWorks.
2.2 Features of MB series intelligent programmable controller
(1) High-performance main control module: high-end software and hardware configuration makes the main control module have strong data processing capabilities, computing capabilities and communication processing capabilities;
(2) Open standard Ethernet communication interface: provide external 10/100M Ethernet interface, support Modbus/TCP protocol, and can be interconnected with host computer and various monitoring software;
(3) Advanced fieldbus network: using fieldbus CAN network, it has the characteristics of fast communication speed, strong anti-interference ability, low cost, simple structure, flexible expansion, and good real-time performance, which provides convenience for system expansion and remote control;
(4) Powerful serial communication function: a serial communication module is provided, which can be configured freely and can communicate with other smart devices conveniently;
(5) Highly reliable hot standby redundancy scheme: supports dual CPU, dual Ethernet, dual power supply hot standby redundancy scheme, and automatically backs up data in real time;
(6) Convenient and flexible interconnection between different types of PLCs of the MB series: seamless connection between different PLCs can be realized without any expansion modules, saving system costs;
(7) The fully intelligent I/O design and a series of safety and reliability designs provide guarantee for the safe and reliable operation of the system: the optical isolation and software filtering functions of the switch input module; the reverse reading of the switch output module, The combined control of the verification and implementation of the relay ensures that there will be no misoperation under any circumstances; the advanced design of each independent cross-current source of the temperature input module greatly improves the acquisition speed and anti-interference; the analog input module has a good capacitance The design method ensures the absolute isolation of the internal circuit and external interference, greatly improves the acquisition accuracy, and minimizes the drift of the analog quantity;
(8) Friendly interface and easy-to-use programming software
Flexible ladder diagram programming language and more and richer ladder function modules; all-Chinese ladder diagram design greatly improves the readability of ladder diagram programs; intuitive visual flowchart programming language makes the realization of complex control processes very Simple; modular program structure, programs can call each other; support remote programming and debugging;
(9) Direct GPS synchronization clock interface
Directly provide GPS synchronous clock interface, without programming and setting, hardware time synchronization can reach the module level, SOE event information is more accurate and reliable;
(10) Convenient and practical local man-machine interface
Provides a serial communication interface with the touch screen, supports the Modbus communication protocol, and can be directly connected to a variety of touch screens without adding auxiliary equipment or writing communication drivers.
2.3 Operating system and development environment
In order to ensure the reliability of the software and the real-time performance of the device, the project adopted the most widely used 32-bit real-time operating system VxWorks in the world. VxWorks is a modular, high-performance, real-time operating system designed specifically for embedded microprocessors. VxWorks is currently the world’s largest real-time operating system with the largest number of users, with rich application software support, good technical services, scalability, scalability, and reliable system stability. The open structure of VxWorks and the support for industrial standards enable developers to design effective real-time operating systems suitable for different user requirements with minimal work.
The development environment of VxWorks is Tornado provided by WindRiver. Tornado adopts the host-target development method, the host system adopts a workstation or PC running Windows2000/NT, and VxWorks runs on target processors such as x86. Tornado provides a variety of application tools such as a friendly visual development interface, cross-compilation environment, source-level debugging tools, target machine command interpreter and target machine status monitor, providing an efficient and reliable platform for application software development.
3. Key technology
The key to the software design of MB series intelligent programmable controllers is to ensure the real-time performance of the software, including key technologies such as task division, selection of communication mechanisms between tasks, interrupt handlers, network communication programs, and serial port communication programs. .
3.1 Task division
In an embedded real-time system, the reasonable division of tasks is crucial to the real-time performance of the system. When performing task division, first analyze the data conversion in the data flow chart to determine which data conversion can be performed in parallel and which must be performed in sequence. The most important factor that determines the division of application system tasks is the asynchronous relationship between the functions implemented by the system, which can be specifically considered from two aspects: I/O functions and system internal functions.
Wind, the real-time kernel of VxWorks, uses a preemptive scheduling algorithm based on task priority by default. At the same time, it also supports round-robin scheduling algorithms. The Wind core has 256 priority levels, numbered from 0 to 255, priority 0 is the highest, and 255 is the lowest. The task is created using the taskSpawn() function.
MBPLC is divided into the following tasks according to function and priority:
(1) Main task: The main task is responsible for hardware initialization, database initialization, ladder initialization, process initialization, network initialization, etc., and create corresponding tasks according to the definition of the database;
(2) CAN1 task: CAN1 task mainly completes the functions of CAN1 network drive and exchange of messages with the I/O module. It can send messages such as loading, setting, setting, and query to the I/O module. It can also receive measured values, events and other messages sent by the I/O module, and process the database accordingly;
(3) Ethernet task: Ethernet task mainly completes the functions of Ethernet driver, letter and text sending and receiving, and realizes the transmission of data and control commands between PLC and upper computer, and supports standard MODBUS/TCP protocol;
(4) CAN2 task: CAN2 task mainly completes the transmission function of CAN2 network drive, information and control commands with external equipment (such as communication devices, protection devices, excitation devices, speed regulators, etc.). As long as the external device supports the CAN interface, it is easy to connect to the PLC;
(5) Process task: The process task provides a unique sequential control process execution method, executes the assembly code generated by the MBPro programming software, obtains data by accessing the database, describes certain judgments and blocking conditions, generates corresponding actions, and The calculation results are written to the database, and various information of real-time execution can be fed back to the debugging machine to monitor the execution of the process. The flow chart is executed sequentially and is suitable for sequential control operations, such as normal start-up and shutdown control of the unit, emergency shutdown control, etc.;
(6) Ladder task: Ladder task provides ladder diagram execution method, executes the assembly code generated by MBPro programming software, obtains data by accessing the database, realizes certain judgment and blocking conditions, generates corresponding actions, and writes the calculation results In the database, various information of real-time execution can be fed back to the debugging machine at the same time, so as to monitor the execution of the trapezoid. The ladder diagram is cyclically scanned, suitable for logic control and state control, and can be used for main program, communication, data processing, control startup, such as unit state judgment, etc.;
(7) Adjustment task: The adjustment task is responsible for PID closed-loop adjustment of the active and reactive power of the unit, which can carry out load increase and decrease, adjustment switching, adjustment condition limitation, adjustment increase and decrease limit, adjustment timeout judgment, adjustment speed limit, etc.;
(8) Clock task: The clock task manages the PLC clock, processes the sub-synchronization signals, and performs some hardware operations regularly, such as turning on the running lights;
(9) Self-inspection task: The self-inspection task automatically diagnoses the operation status of various tasks and equipment and alarms. When the PLC runs disorderly or crashes due to some interference or hardware failure, Watchdog can generate a self-recovery signal to make the PLC automatically resume operation;
(10) Debugging task: The debugging task communicates with the debugger via Ethernet, and is responsible for exchanging information with the programming software MBPro, including uploading real-time data, SOE events, process alarm information, etc., and can modify the database, ladder diagrams and flowcharts. Operations such as time synchronization, reset, master-slave switching, etc.;
(11) Dual-machine task: The dual-machine task realizes automatic and manual switching of master and slave, and can back up important data on the opposite side through the internal high-speed network. When some important equipment or tasks of the host fail, the slave function will automatically be upgraded to the host;
(12) Display task: The display task communicates with the intelligent LCD touch screen through the serial port to complete local data display and operation functions, including display of measuring point information, accident list, optical characters, module status, etc., and can issue control commands and settings Setting value, setting parameters, etc.;
(13) Serial port task: The serial port task completes the communication function with external equipment, and realizes the exchange of data and commands with external equipment, such as GPS, temperature inspection device, exchange acquisition device and so on. It supports Modbus standard protocol, and can be programmed to realize special protocol when necessary.
3.2 Inter-task communication
The inter-task communication mechanism is the main means for multitasking to synchronize and communicate with each other to coordinate their activities. The communication methods between tasks provided by VxWorks are semaphores, message queues, pipes and sockets in descending order of speed. Commonly used communication mechanisms are semaphores and message queues, and sockets are used for network programming.
Semaphore is the main mechanism to achieve mutual exclusion and synchronization of tasks. The semaphore provided by VxWorks has been highly optimized and has the fastest speed among all inter-task communication mechanisms. For mutual exclusion, semaphores can lock access to shared resources, and provide a more precise mutual exclusion granularity than prohibition of interruption or prohibition of preemption. For synchronization, semaphores can coordinate the execution of external events and tasks.
MBPLC uses binary semaphores to solve the mutual exclusion problem of multiple tasks reading and writing data, and uses counter semaphores to solve the timer counting problem;
(2) Message queue
The message queue is the main mechanism for communication between tasks in a single CPU provided by VxWorks. The message queue allows messages to be queued in FIFO or priority-based mode, the number of messages is variable, and the length of messages is variable. Any task can send messages to and receive messages from the message queue. Multiple tasks allow sending and receiving messages from one message queue. However, two-way communication between two tasks usually requires two message queues, each used in one direction.
MBPLC uses message queues to realize data exchange between tasks. First call the msgQCreate() function to create the message queue, then use the msgQSend() and msgQReceive() functions to send and receive messages, and finally call the msgQDelete() function to stop the message queue.
3.3 Interrupt handler
The interrupt handler is an important part of the real-time system. The system understands the external world through the interrupt mechanism and responds to external events. The response of the real-time system depends on the system’s response speed to the interrupt and the processing speed of the interrupt handler. Since many interrupts may be generated in a short period of time, high-priority interrupts will block low-priority interrupts. Therefore, the processing time of the interrupt handler must be minimized.
MBPLC interrupts include second interrupts, sub-synchronization interrupts, CAN network interrupts, BSP-level Ethernet interrupts, hard disk interrupts, and so on. The following uses the second interrupt (interrupt level is 5) as an example to illustrate how to use the interrupt:
ntConnect(INUM_TO_IVEC(INT_VEC_GET(5)), SECISR, 0);
These two functions are used to associate the interrupt handler SECISR() with the second interrupt, and are stored in the corresponding entry of the interrupt vector table. When the second interrupt event occurs, the VxWorks kernel will call the interrupt handler. At this time, you can use the interrupt handler to release a semaphore (through the semGive() function), and drive the corresponding data processing module through the semaphore (through the sem-Take() function) to achieve real-time operation.
In addition, we also use the intLock() function and intUnlock() function to set the interrupt mask to ensure that the protected code is not interrupted by interruption during execution.
3.4 Network communication
Network communication can generally be achieved through sockets. Vx-Works provides standard BSD socket calls, which have two types: Stream socket (full-duplex stream type) and Datagram socket (datagram type). The former supports TCP protocol, and the latter supports UDP protocol. Any one task can open one or more sockets, and sockets of other tasks can be connected to it.
The client program first calls the socket() function to generate a socket for connecting to each subsystem, and then initializes a socket structure, assigns it the IP address and port number of the server, and uses it as the function connect() Parameter, call the connect() function to actively connect to the server. After the connection is successful, use the send() and recv() functions to read and write data until all the data is exchanged, and then use the close() function to close the socket.
The server also uses the socket() function to establish a socket first, and then calls the bind() function to bind its own IP and port number to ensure that the client correctly recognizes it, and then uses the listen() function to indicate that it is ready to accept connections from the client , And use the accpet() function to accept a connection request. After receiving it, use the send() and recv() functions to transmit data until all the data is exchanged, and then use the close() function to close the socket. In order to ensure that the server can receive data from the client in real time, when the server establishes a connection with the client, a loop must be embedded, and the recv() function is used to continuously wait for client data. At the same time, the client should wait for the server to reply after sending data each time to establish a handshake mechanism.
3.5 Serial port communication
In VxWorks, the I/O system is designed as any type of device, providing a simple, unified, and device-independent interface. Any operation on the serial port can still be regarded as an operation on a file without knowing about the device. Or program-driven implementation details. Before using the serial port, use open() to open the corresponding serial port, and then use ioctl() to set the baud rate, data bit, stop bit, parity and other attributes, and then call the function write(), read() performs read-only operations, write-only operations, or read-write operations on the serial port at the same time, and finally closes the serial port with close().
For serial communication, we still need to care about the real-time data reception. The interrupt mode can be used to use the event trigger mechanism of the select() function provided by VxWorks to block the task of reading the serial port so that it has been waiting for data. When there is data, the task will automatically respond immediately to improve the real-time performance of the system.
The introduction of the embedded real-time operating system VxWorks and its development environment greatly simplifies the complexity of programmable controller software design, shortens the development cycle, and improves the real-time and reliability of the product. Therefore, the application of VxWorks RTOS in the MB series intelligent programmable controller is successful. As a new generation of PLC products, MB series intelligent programmable controllers are believed to be able to exert greater advantages in various complex control fields such as electric power, chemical industry, industrial process control, urban and building automation, and make the automation level of these industries greater The improvement.