Share this

Design and Implementation of PLC Editor for CNC System

2026-04-06 05:07:48 · · #1

1 Introduction
The ANC-45M full-function CNC system is a vertical, semi-closed-loop three-axis machining center CNC system jointly developed by the High-Tech Development Center of Dalian Machine Tool Plant and AVAIL Corporation of Japan. It utilizes a 32-bit RISC CPU, a dedicated multi-tasking real-time operating system, an improved Harvard architecture, a 9″ color LCD display, and a dual-CPU, dual-motherboard design. One motherboard houses the control subsystem of the machining center, while the other CPU and its motherboard form its input/output subsystem, serving as the machine tool's human-machine interface. This paper details the design and implementation of the PLC editor for the ANC-45M machining center.
2. Composition and Structure of the ANC-45M Machining Center <br />Two CPUs and their motherboards are connected by a communication cable via RS-232 asynchronous serial communication interfaces on the two motherboards, exchanging data in message form. The exchanged data includes: machining programs and PLC ladder diagram programs between the MMC (Man-Machine Interface Controller) and CNC sides, as well as real-time coordinate data and machine tool status parameters between the MMC and CNC sides.
3. Software System Structure
3.1 Main Program Algorithm Structure The PLC editor is a subroutine of the MMC section. To better describe the content of this paper, we should first analyze the design algorithm of the MMC main program. Its three main program module algorithms are as follows:
(1) The algorithm of the main function is shown in Figure 1.

Figure 1 Main function algorithm

(2) The task management module is shown in Figure 2.

Figure 2 Task Management Module Algorithm

(3) The status task module is shown in Figure 3.

Figure 3 State Task Module Algorithm

The main program reserves two corresponding sub-functions for each sub-functional module. The PLC editor has its own corresponding no-key processing sub-function and key-input processing sub-function. The key-input processing sub-function handles the judgment and processing of input key values, while the no-key processing sub-function handles the real-time screen refresh of status parameters. Each sub-functional module shares a common characteristic: its no-key processing subroutine is shorter than its key-input processing subroutine. The no-key processing sub-function is called when there is no key input in the current sub-functional module state, and it is called in every main program loop cycle. When there is key input, the key-input processing sub-function is called instead. Once a key input occurs, the system receives the response from the CPU via an interrupt. It first performs the corresponding preprocessing and then calls the task management module sub-program. The task management module program checks whether the current state variable is in the initial state; if so, it enters the corresponding initial processing; otherwise, it checks whether a key press has occurred, and if so, it enters the corresponding branch program.
When a key is pressed, the program first determines the type of the key value. If it is a command to change a function sub-module, the corresponding function key value sub-module is called first, and the status variable TASKSTART is sent. At the same time, the currently running function sub-module is put into the background to wait for the interrupt to complete before it is executed. If it is not a command to change a function sub-module, but a key value input in the current function sub-module state, the system calls the function key value processing sub-module and sends the TASKRUN status, thus entering the key value processing sub-routine of each subroutine.
3.2 Operating System The operating system of this CNC system is developed and designed by AVAIL, and has been successfully applied to the company's embroidery machines. These machines have been sold in mainland China and other regions for many years, and have been validated and recognized by practice and users. This operating system is specifically designed for control systems with relatively simple tasks. A crucial time-task control module is responsible for allocating runtime for each task and monitoring task execution time. We know that for a real-time system, the correctness depends not only on the logical results of the calculations but also on the time it takes to produce those results. To ensure the accuracy of CNC machining, this operating system adopts a hard real-time task management mode. The system assigns a deadline to a specific task, and the system must complete the task before this deadline; otherwise, the system will forcibly interrupt the task's execution. This time-task module determines the machining accuracy of the CNC system, depending on various factors such as CPU execution speed and communication port transmission rate. Because the operating system is simple in function and its tasks are predictable and simple, this provides a fundamental guarantee for the system's higher reliability and stronger stability.
4. Main Functions of the Ladder Diagram 4.1 Input and Editing of Ladder Diagram Symbols This ladder diagram editor uses a soft keyboard to draw corresponding graphic symbols by pressing the menu-driven ladder diagram editor [1-4]. It has functions such as adding, deleting, and modifying, making it easy to operate. When using it, the operator only needs to move to the appropriate position and then press the corresponding ladder diagram symbol on the keyboard to draw the symbol at that position, and can also label it with a number. The drawing window is divided into rows and columns with certain intervals, so that the inserted graphic symbols can only be positioned on grid points. This does not affect the intuitiveness of the ladder diagram editing and makes the interpretation program easy to implement.
4.2 Storage and Retrieval of Ladder Diagram Symbols Each ladder diagram symbol is a bitmap. We store the type, position, and text display information of each bitmap. During retrieval, the bitmaps are drawn in the original order. Since the number of rows in a ladder diagram is unpredictable, dynamic data storage is used for editing the ladder diagram, employing a doubly linked list data structure to record all information. Because each link in the doubly linked list has forward and backward pointers, it allows for both forward and backward access, making various operations highly flexible and convenient.
4.3 Syntax Check: This function primarily checks whether the drawn ladder diagram conforms to the specified format. If the ladder diagram does not meet the format requirements, an error message will be given. First, the stored file is scanned line by line to see if there is output in each branch. If there is, an error is indicated; otherwise, the scan continues. Next, it checks whether the numbers are predefined letters such as X, Y, R, and T. If not, an error is indicated; otherwise, the scan continues. Then, it checks whether the number is followed by a number. If so, it is correct. It checks whether the number is less than 127. If so, the syntax check is successful; otherwise, an alarm is triggered.
4.4 Logical Inspection Since the ladder diagram is stored during editing, only the order between rows and the information of each element in each row are stored, but the logical relationships between the elements are not, making inspection difficult. We adopt the method of first converting the ladder diagram into a statement list to achieve this. This paper proposes a conversion method centered on binary trees. The characteristics of a binary tree: a parent node has exactly two child nodes. This data structure is very convenient for representing logical relationships. The ordered ladder in the ladder diagram can be represented as a forest of several ordered binary trees. By designing a traversal algorithm for each binary tree, the corresponding instruction set can be uniquely obtained.
5. Statement List Main Function Design and Implementation 5.1 Design Principles of the MMC Main Program The MMC main program adopts a main loop structure, scanning and executing each subroutine module approximately every 30ms. Each mode's subroutines include key-directed task subroutines and keyless task subroutines. In each scan cycle of the main program, if a key value is input, the corresponding key-directed task subroutine is executed; otherwise, the corresponding keyless task subroutine is executed. Before each loop, a mode check is performed. If the current mode has changed, the corresponding mode's subroutine is brought to the foreground for execution, while the previously running foreground program is moved to the background for continued execution.
5.2 Design Principles The main program of the MMC section uses a periodic loop to read key values. When an interrupt is encountered, its validity is first checked. If valid, the interrupt subroutine is moved from the background to the foreground for execution and display. Therefore, the full-screen editing subroutine adopts the approach of receiving one character or one control command in each loop cycle and executing it.
5.2.1 Input Processing of Instructions Considering that the editor should be able to accommodate both sequential input of statement lists and modification of parts of program segments, each input instruction should first be checked for validity. If valid, all characters following the current position should be shifted one position to the right, and then the instruction character should be stored in a buffer sequentially and consecutively at the current position. Simultaneously, the instruction is displayed on the monitor. The monitor used is an 800×600 LCD, with a display parameter of 50×18 in normal character mode. The algorithm for character and number input is shown in Figure 4.

Figure 4 Input Flowchart

5.2.2 Input Processing of Confirmation Key (1) Editing Function. After editing a PLC statement list program segment, the confirmation key must be pressed before the next program segment can be edited. Once the confirmation key is pressed, the editor needs to perform a series of processes on the program segment, including error checking, error tolerance, formatting, and normalization. Syntax check: Checks whether the user statement program has spelling errors, instruction format errors, instruction address out of bounds errors, etc.; Language program logic check: Checks whether the statement list program has logical errors.
(2) Error Detection Function. Before converting the PLC program into intermediate code, the development system must first check whether the PLC program has syntax errors. To facilitate PLC programmers in modifying the PLC program, the system follows the ladder diagram sequence during compilation. Syntax checks are performed during compilation, primarily to verify whether the compiled ladder diagram conforms to the specified format. If the ladder diagram does not meet the format requirements, an error message will be given. Simultaneously, the compilation process also verifies whether the signal codes in the ladder diagram are consistent with the signals defined in the signal definition module. If they are inconsistent, a message will indicate that the signal code is undefined. Users can view the error messages given during compilation and make corresponding modifications until there are no errors.
5.2.3 Handling of Other Function Keys In PLC programming, to facilitate instruction editing, functions such as row selection, row copy, row paste, character selection, character copy, character paste, and line number search are provided. Of course, in screen editing and all the functions described above, automatic up/down screen movement is also encountered; this is a basic function that every editor should have. It is worth noting that in this editing system, the cursor always automatically points to the next position as input is made, guiding the user to input the characters at the current position. The cursor cannot be freely moved to empty spaces on the screen. Furthermore, during row and character selection, the selected content is refreshed in reverse color at the original position.
6. Conclusion <br />The embedded soft PLC editor proposed in this paper embodies the openness requirements of CNC systems, easily achieving hardware independence. Its unified data structure facilitates deep system openness, and its convenient programming environment and flexible programming methods lower the PLC programming threshold, making it easier for users. Furthermore, this method reduces system costs. This PLC editor performs internal logic operations based on discrete input information and completes input/output control functions, fully meeting the requirements of economical CNC machining centers. The PLC has been successfully applied in the CNC system design of the ANC_45M economical machining center, and the CNC products are about to be sold nationwide.

Read next

CATDOLL 146CM Christina TPE

Height: 146cm A-cup Weight: 26kg Shoulder Width: 32cm Bust/Waist/Hip: 64/54/74cm Oral Depth: 3-5cm Vaginal Depth: 3-15c...

Articles 2026-02-22