Design of Embedded Programmable Controller in CNC Machine Tool System
2026-04-06 00:19:34··#1
Abstract: Electrical control is a crucial component of CNC machine tools, but conventional design and application methods have limitations. Based on an analysis of the advantages and disadvantages of existing methods, this paper proposes a new open design approach, introducing its design philosophy and hardware structure, and providing a detailed explanation of the software design. Keywords: Programmable Logic Controller; PLC; Microcontroller; Computer Numerical Control System In CNC machine tool systems, the control of electrical equipment plays a vital role. Currently, Programmable Logic Controllers (PLCs) are generally used for machine tool electrical control. PLCs offer high reliability and ease of 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 PLCs are 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. Currently, most PLCs sold on the market have communication functions, which can be used to establish a connection between the PLC and the NC. Because PLCs use serial communication, their communication speed is relatively low. This makes them unsuitable for handling signals with high real-time requirements in CNC machine tools, such as emergency stop and overtravel. Other measures must be taken to meet these special needs, but this increases the system's complexity. To improve speed and reduce cost, a switch I/O board with external relays can be used in the CNC system, with the host software controlling the electrical switches. However, this solution requires the CNC host to directly participate in the electrical control logic calculations, occupying part of the host's operating time and increasing 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 design ensures real-time performance while relatively dispersing the risk of failure. 1. Hardware Structure of the Embedded PLC The five-axis linkage CNC system we developed is a multi-CPU distributed open CNC system based on an industrial PC. As part of this system, the embedded PLC design must also follow the principle of openness. Its hardware is modular, designed according to standard industrial PC plug-in cards. Currently, there are two types of backplane buses for industrial control computers: 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. Furthermore, the requirements for industrial control computer 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 embedded PLC design. The composition of the embedded PLC is shown in Figure 1. The CPU of the embedded PLC uses the Intel 16-bit microcontroller 80C196. Its unique register-accumulator structure and three-operand instructions can greatly reduce the number of data transfer instructions in the program, improving program execution efficiency. The dual-port memory in Figure 1 is used for information exchange between the PLC and the CNC system host. During the operation of the CNC system, while the PLC continuously performs electrical control logic operations, it also periodically refreshes the contents of the dual-port RAM, reflecting the electrical switch status and PLC operating status in the dual-port RAM. Some panel buttons, such as cycle start and feed hold, are also included. Manual operations, such as those used for NC operations, cannot be handled as general I/O points. The embedded PLC recognizes key presses and maintains a cyclic queue in the dual-port RAM to record these key presses. Meanwhile, the NC software modifies specific data in the dual-port RAM according to the M, S, and T parameters 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 content. This method uses dual-port RAM to complete information exchange between the NC and the embedded PLC. Compared to the parallel port approach, this method is simpler and clearer, requiring no complex communication protocols. The NC can understand the switching status of external devices at any time without consuming additional time, making it more efficient than other implementation methods. Figure 1 includes a static RAM chip 6264, powered by a backup battery—primarily used to store the PLC ladder diagram program. The electrical control logic is programmed in the NC, compiled, and then stored in the 6264 via the dual-port RAM. The PLC runs this program to complete the electrical control. 2. Software Design The embedded PLC software design consists of two parts: the design of related programs in the industrial PC and the design of the monitoring program built into 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 the PLC's electrical control logic, generating a ladder diagram file. The ladder diagram file only stores the logical relationships between I/O points, and its format is independent of the CPU type used by the embedded PLC, thus improving the adaptability and reusability of the programming module. The ladder diagram compilation module is used to convert this file into a series of 80C196 machine instructions, adding some 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 generated BIN file are consistent with the actual I/O resources. The communication module is used to transfer the BIN file to the dual-port RAM, and then the PLC monitoring program dumps it into the 6264. This section provides a user development interface, allowing users to control the transfer of BIN files and enabling on-site programming of the PLC. The monitoring module provides functions such as user I/O point monitoring and setting, and PLC running/programming status settings, facilitating on-site debugging. Additionally, to enable users to effectively monitor the embedded PLC in their self-developed applications, this section also provides an open user interface. 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 transferred from the industrial computer) and its running status; periodic refreshing of I/O points and dual-port RAM mapping areas; running fault monitoring; 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, a watchdog timer is used to monitor whether the operation is normal. To prevent and handle abnormal situations such as timeout errors when running programs in 6264, and errors in the logic processing program in 6264, the advantages of this system design are summarized as follows: (1) Adopting a plug-in card design, there are no extra wires connecting the NC and PLC, resulting in high reliability and guaranteed real-time performance. (2) Using dual-port RAM for information exchange, which is fast and has a simple circuit. (3) Embedded into the machine tool system, it is convenient for development, debugging, use and maintenance, and easy to combine with the user's hardware and software to form a more complex system. 3 Using embedded PLC in CNC system As mentioned above, the electrical control of CNC machine tools can be carried out in three ways: external PLC, virtual PLC and embedded PLC. If conventional programming methods are used, different software interfaces must be designed for the above three electrical control methods. The main body of the CNC system software will directly involve the implementation method and details of electrical control. Once the control method changes, the software will have to be modified a lot. The software written in this way has poor universality and is difficult to adapt to changes. In order to increase the mutual independence between software and equipment. We employed object-oriented technology to design an open system. 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 external features of the CNC machine tool's electrical control and complete interface functions for the main CNC system software. 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, hydraulic closing, etc., would result in too many interface functions and inconvenience in application. Therefore, we designed a general interface function, defined as follows: If the hydraulic switch is defined as number 1, the cooling switch as number 2, ..., then the function call for opening the hydraulic switch is... Based on the abstract class CPIC, derived classes CExternalPLc, CVirtualPLc, and CEmbedPLc are defined for the three methods respectively. In these classes, the interface functions are actually programmed to complete the hardware operation. The electrical control software obtained according to this design idea has the structure shown in Figure 3. As shown in Figure 3, this design method adds an abstract class hierarchy between the main software of the CNC system and the electrical control hardware, reducing their interdependence and making them two relatively independent parts. The CNC system software obtained using this method has equipment-independent characteristics. When new hardware appears, only a new class needs to be derived from the original abstract class, the interface functions are interpreted according to a common standard, and the hardware is manipulated to perform corresponding actions without any modification to other parts of the software. This greatly improves the efficiency of software design. In fact, after clearly specifying the meaning of the interface function parameters, 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 open design for 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, and using engineering design methods, can a perfect open CNC system be obtained. Currently, discussions on openness focus more on system hardware structure, operating system, and development environment; 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 regard. This subsystem has been integrated into the five-axis linkage CNC system we developed. From the perspective of usage effect, its open interface standard and equipment-independent software design help reduce errors when writing the main software of the CNC system, and has strong adaptability and reliability. [References] [1] Fan Liuqun et al. Structure and implementation of NC and PLC in CNC machine tools [J]. Industrial Instrumentation and Automation Devices 1998 (1) [2] Feng Xianying et al. Open CNC system based on PC bus [J]. Modular Machine Tools and Automated Machining Technology • 1998 (8)