In CNC machine tool systems, the control of electrical equipment plays a crucial role. Currently, programmable logic controllers (PLCs) are generally used for machine tool electrical control. PLCs are highly reliable and easy to use. For complex applications with a large number of control points, a certain number of expansion units can be added to the basic PLC unit to achieve complex electrical control functions. In CNC machine tools, if PLC is used for electrical control, an electrical connection must be established between the PLC and the NC; otherwise, the MST instructions in the NC program will not be reflected in the PLC, and the PLC will not be able to perform the corresponding actions. Most PLCs sold on the market have communication functions, which can be used to establish a connection between the PLC and the NC. However, because PLC communication is serial, the communication speed is relatively low. For certain real-time signals of CNC machine tools with high requirements, such as emergency stop and overtravel, it is difficult to handle them. Other measures must be taken to meet these special needs, but this increases the complexity of the system. To improve speed and reduce cost, in CNC systems, a digital I/O board with external relays can be used, along with the host software to control the electrical switches. However, this scheme requires the NC host to directly participate in the electrical control logic calculation process, consuming part of the host's operating time and increasing the software complexity. More importantly, concentrating too many functions on the host increases the risk of host failure. Considering real-time performance and reliability, the authors designed an embedded PLC during the development of the five-axis linkage CNC system. This ensures real-time performance while relatively dispersing the risk of failure.
1. Hardware Structure of Embedded PLC
Our five-axis CNC system is a multi-CPU distributed open CNC system based on an industrial PC. As a component of this system, the embedded PLC design must also adhere to the principle of openness. Its hardware is modular, designed according to standard industrial PC expansion cards. Currently, there are two types of backplane buses for industrial PCs: ISA bus and PCI bus. The data transfer rate of the ISA bus is much lower than that of the PCI bus, but it is sufficient to meet the needs of general industrial control. Moreover, the requirements for industrial PC expansion cards are less stringent than those for PCI. Based on existing industrial application experience, its reliability is also relatively high. Therefore, we still choose the ISA bus as the basis for the embedded PLC design.
The components of an embedded PLC are shown in Figure 1.
The embedded PLC uses the Intel 80C196 16-bit microcontroller as its CPU. Its unique register-accumulator structure and three-operand instructions significantly reduce the number of data transfer instructions in the program, improving program efficiency. Figure 1 shows a dual-port RAM used for information exchange between the PLC and the CNC system host. During CNC system operation, the PLC continuously performs electrical control logic operations while periodically refreshing the contents of the dual-port RAM, reflecting electrical switch states and PLC operating states in the RAM. Some panel buttons, such as cycle start, feed hold, and manual, are used for NC operations and cannot be treated as general I/O points. The embedded PLC recognizes button operations and maintains a cycle record of these operations in the dual-port RAM. On the other hand, the NC software modifies specific data in the dual-port RAM according to the M, S, and T instructions in the machining program. The PLC periodically reads this data and controls the on/off state of electrical equipment accordingly. For signals with high real-time requirements, the PLC can send an interrupt to the NC via the ISA bus after updating the dual-port RAM contents.
This method utilizes dual-port RAM to exchange information between the NC and the embedded PLC, which is simpler and clearer than using parallel ports. It eliminates the need for complex communication protocols, allowing the NC to monitor the on/off status of external devices without incurring additional time costs. This approach is more efficient than other implementations.
Figure 1 includes a 6264 static RAM chip, powered by a backup battery—primarily used to store PLC ladder logic programs. The electrical control logic is programmed in the NC, compiled, and then stored in the 6264 via dual-port RAM. The PLC runs this program to complete the electrical control.
2 Software Design
Embedded PLC software design consists of two parts: one is the design of the relevant programs in the industrial control PC, and the other is the design of the monitoring programs that come with the embedded PLC itself. The main functional modules of the former are shown in Figure 2.
The ladder diagram programming module provides users with a convenient means of programming PLC electrical control logic, generating ladder diagram files. These files only store the logical relationships between I/O points, and their format is independent of the CPU type used by the embedded PLC, improving the adaptability and reusability of the programming module. The ladder diagram compilation module converts this file into a series of 80C196 machine instructions, adding necessary additional instructions to generate a BIN file, i.e., a machine code file. This part should consider the resource distribution of I/O points in the PLC, ensuring that the instructions in the final BIN file are consistent with the actual I/O resources. The communication module transfers the BIN file to the dual-port RAM, and then the PLC monitoring program dumps it to the 6264. This part provides a user development interface, allowing users to control the transfer of the BIN file and providing the ability to program the PLC on-site. The monitoring module provides functions such as monitoring and setting user I/O points, and setting PLC running/programming status, facilitating on-site debugging. In addition, an open user interface is provided in this section to enable users to effectively monitor the embedded PLC in their own applications.
The embedded PLC monitoring program mainly implements the following functions: valid verification of the logic processing program in the 6264 (i.e., the BIN file transmitted from the industrial control computer) and its running status; periodic refreshing of I/O points and dual-port RAM mapping areas; monitoring of running faults; and detection of panel buttons. When a valid BIN file is stored in the 6264 and a valid running flag is set, the logic processing program in the 6264 is started. Furthermore, during operation, WatchDog is used to monitor whether the operation is normal, preventing and handling abnormal situations such as timeout errors during program execution in the 6264, and errors in the logic processing program in the 6264. The advantages of this system design are summarized as follows:
(1) The card-type design is adopted, and there are no extra wires between the NC and the PLC, which ensures high reliability and real-time performance.
(2) Use dual-port RAM for information exchange. It is fast and has a simple circuit.
(3) Embedded into the machine tool system. Convenient for development, debugging, use and maintenance. Easy to integrate with user's hardware and software to form more complex systems.
3. Using embedded PLC in CNC systems
As mentioned earlier, the electrical control of CNC machine tools can be implemented using three methods: external PLC, virtual PLC, and embedded PLC. If conventional programming methods are used, different software interfaces must be designed for these three electrical control methods. The main body of the CNC system software will then directly involve the implementation methods and details of electrical control. Once the control method changes, extensive software modifications will be necessary. Software developed in this way has poor versatility and is difficult to adapt to changes. To increase the independence between the software and the equipment, we have adopted object-oriented technology for an open system design.
Clearly, regardless of the control method, the goal is the same. Through careful analysis, we identified the commonalities among the three methods, leading to an abstract class CPLC. This class provides all the external characteristics of the CNC machine tool's electrical control and offers complete interface functions for the main software of the CNC system. Other parts of the CNC system only need to call the corresponding interface functions to make the electrical switches perform the corresponding actions. However, this part does not involve the details of the electrical operation process. Considering the large number of electrical control points in the CNC system, designing a separate interface function for each control action, such as hydraulic opening and closing, would result in too many interface functions and inconvenience in application. Therefore, we designed a general interface function, defined as follows:
If we define the hydraulic switch as number 1, the cooling switch as number 2, ...,
The function call for opening the hydraulic pressure is as follows:
Based on the abstract class CPIC, derived classes CExternalPLc, CVirtualPLc, and CEmbedPLc are defined for the three methods respectively. Only in these classes are the interface functions actually programmed to complete hardware operations. The electrical control software obtained according to this design philosophy has the structure shown in Figure 3. As can be seen from Figure 3, this design method adds an abstract class hierarchy between the main CNC system software and the electrical control hardware, reducing their interdependence and making them two relatively independent parts. The CNC system software obtained using this method has the characteristic of being independent of the device. When new hardware devices appear, only a new class needs to be derived from the original abstract class, and the interface functions need to be interpreted according to a common standard. The hardware can then be manipulated to perform the corresponding actions without any modification to other parts of the software. This greatly improves the efficiency of software design. In fact, after the meaning of the interface function parameters is clearly defined, anyone can refer to this specification to design new electrical control hardware and corresponding drivers, and integrate them into the system. This is the main purpose of the open design of CNC systems.
4. Conclusion
The open design of CNC systems is closely related to the designer's knowledge and experience. Only by fully understanding existing design technologies and user needs, and predicting their near-term development, can a complete open CNC system be achieved using engineering design methods. Current discussions on openness mostly focus on system hardware structure, operating systems, and development environments. How to specifically achieve openness, especially software openness, is rarely discussed. This paper presents an open design for the electrical control subsystem from hardware to software, making a valuable exploration in this area. This subsystem has been integrated into our developed five-axis linkage CNC system. From the usage results, its open interface standards and device-independent software design help reduce errors when writing the main CNC system software, exhibiting strong adaptability and reliability.