Abstract: This paper introduces the system structure block diagram, CNC software design concept and flowchart of the 80C51 microcontroller in the control of a two-axis linkage CNC lathe, the selection of stepper motor and drive amplifier circuit. Keywords: 80C51 microcontroller, CNC lathe, stepper motor drive circuit I. System Hardware Design (I) Composition and Function of Computer Numerical Control (CNC) 1. Composition of CNC System The CNC system consists of a program, input/output devices, CNC device, programmable controller (PLC), main drive device and feed drive device. The system block diagram is as follows: 2. Structure of CNC Device The core of the CNC system is the CNC device, which consists of software and hardware. Their main functions are: (1) to correctly identify and interpret the CNC machining program; (2) to perform various data calculations and logical judgments on the interpretation results and complete various input/output tasks. The software component of a CNC machine tool includes management software and control software. The management software consists of input/output programs for the part program, display programs, and diagnostic programs. The control program consists of decoding programs, tool compensation calculation programs, speed control programs, interpolation calculation programs, and position control programs. The hardware component includes a central processing unit, memory, and input/output interfaces, as shown in the figure. 3. Working Process of the CNC Machine Tool The CNC machine tool operates using memory. Its operation is supported by hardware and executes the entire software process. On a CNC machine tool, all operations during the machining process are completed by the CNC system. Its working process is as follows: First, the geometric and process information of the workpiece is digitized. That is, the relative motion trajectory between the tool and the workpiece is programmed into a machining program using code according to prescribed rules and formats. The CNC system then performs corresponding calculations and processing according to the program requirements, and then issues control commands to coordinate the movement of each coordinate axis, spindle, and auxiliary motion, realizing the relative movement between the tool and the workpiece, and automatically completing the machining of the part. (II) System Hardware Structure and Block Diagram The system hardware is mainly based on the control of stepper motors. The stepper motor performs step-by-step rotation by switching the current phase sequence in each phase coil. Therefore, the software of the 80C51 microcontroller is used to distribute the coil pulses. This is mainly achieved by using the PB port of the 8155 parallel interface chip to control the X and Z axes. The stepper motor receives the CNC lathe's part machining program via keyboard input and displays the corresponding information. The system program is then compiled and calls the linear/circular interpolation program to send pulse signals, which are amplified by opto-isolation to drive the stepper motor, thus enabling the stepper motor to move the worktable and tool holder to complete the part machining. (III) Stepper Motor Selection There are many types of stepper motors. According to their working principle, they are classified as: reluctance (resistance) stepper motors (VR type), permanent magnet stepper motors (PM type), and hybrid stepper motors (HB type). Changing the energizing sequence of the stator windings controls its direction of rotation; whether or not the energizing sequence of the stator windings is changed easily controls its start and stop. VR type stepper motor has the following advantages: (1) It is very convenient to control the stepper motor. The number of command pulses determines the number of steps of the stepper motor, and the frequency of the command pulses determines the number of steps; (2) The step angle is small; (3) The excitation current is large, requiring the drive power supply frequency to be large, but the efficiency is low; (4) The internal damping of the resistor is small, and when the number of phases is small, the vibration time of single-step operation is long; (5) It has a good ability to carry inertial loads, especially at high speeds, it is not easy to lose steps; (6) There is no positioning torque after power failure. Combining the design requirements and performance, the reluctance stepper motor VR type is selected. The maximum operating frequency of the stepper motor: fmax=1000Vmax/60ζ=1000*1.5/60*0.005=5000HZ Based on the calculation and comprehensive consideration, the 110BF003 type three-phase six-step stepper motor is selected by referring to the table. The technical parameters are as follows: step angle 0.75º/1.5º; voltage 80V; current 6A; starting frequency 1500HZ; operating frequency 7000HZ. The following figure shows the starting frequency characteristics of 110BF003: As can be seen from the above starting frequency characteristics, when the starting frequency is around 250~350HZ, the torque has a "valley" (torque is zero). When programming, the starting frequency is controlled above 300HZ. (IV) Design of the drive circuit The drive amplifier circuit adopts a high-low voltage drive amplifier circuit. Regardless of the motor frequency, the high-voltage drive circuit uses high voltage to supply power at the leading edge of the conducting phase to improve the current rising rate, and uses low voltage to maintain the winding current after the leading edge. The main circuit is composed of high voltage tube TH, motor winding, and low voltage tube TL connected in series. UH is given high voltage and UL is given low voltage. The circuit diagram is shown below: When TL >> TH, because the average current of the winding is still near the rated value, the low-voltage selection formula is: UL = INR + UDL + UCE. As the motor operating frequency increases, the back EMF of the motor gradually increases, and the current surge during TH decreases. After TH, when only low-voltage power is supplied, the winding current decreases rapidly due to the back EMF. However, at this time, TL is already close to TH, and the energy stored in the magnetic field during the current surge can be maintained for a period of time during the current decline. When the low voltage completely determines the current, it is already close to the trailing edge of TL, so the average value of the winding current can still maintain the required value. When the operating frequency continues to increase, if TL = TH, the high voltage power supply is completely available during the winding conduction time, and the low voltage can no longer play a role. When the frequency continues to increase, TL < TH. At this time, TH should be made to track the width of TL in the signal processing of the preceding stage so that the circuit is always in a high-voltage power supply state. After TL, the winding current enters the freewheeling state, and the current is discharged through DL, the motor winding, and DH. The energy of the magnetic field will be fed back to the high voltage. In summary, high and low voltage drives can ensure a large average current in the phase windings over a wide frequency band and can discharge rapidly when cut off. Therefore, they can generate a large, stable electromagnetic torque, resulting in a high response from the drive system. II. System Software Design 1. System Software Selection In CNC machine tools, the contours being machined vary greatly. Especially complex contours are difficult to generate directly; interpolation is generally used to distribute pulses to each coordinate to complete the trajectory of the entire line segment. There are three common interpolation methods: hardware interpolation, software interpolation, and a combination of hardware and software. According to the design requirements, this system adopts the digital integration method (DDA) within the hardware-software integration method. Hardware-software integration uses software for coarse interpolation and hardware for fine interpolation. Its characteristics include high interpolation speed and high accuracy, making it suitable for high-precision machining centers. The digital integration method, also known as the DDA method, is characterized by uniform pulse distribution and easy coordinate expansion. 2. Overall Software Structure and Flowchart of the System The system adopts a foreground-background software structure, which divides the system software into a foreground program and a background program. The foreground program refers to the program that implements interruption, such as interpolation program, servo control, machine tool logic control and monitoring functions. They are directly related to the movement of the machine tool and have high real-time requirements. The background program refers to the program that implements input decoding, data processing and management functions, also known as the background program. The background program provides the conditions for the implementation of the foreground program and manages it. Figure (1) is the scheduling and management block diagram of the background program under normal machining conditions. After powering on, the initialization program is run first. If the start button is pressed, the input, decoding and data processing programs are executed. After data processing, the trajectory calculation and speed calculation are completed. The cyclic stop processing program is used to handle various stop states. For example, in single-segment execution, the cyclic stop state is set after each data segment is executed, and the CNC machine tool is in a waiting state. When the operator presses the cyclic start button again, the program of the next data segment is executed; if the operator presses the cyclic button for some reason, the interpolation operation will stop immediately. Only when the cyclic start button is pressed again can the program continue to run. If the system is in continuous automatic machining state, the cyclic stop processing program is skipped. The data processing of the subsequent machining program segment is completed by the data execution segment program. Under normal circumstances, the background program loops through steps 1→2→3→4 until the workpiece machining is complete. The foreground program is shown in the block diagram. The first block, the servo program, controls the speed and position of the servo system, implementing feed based on the interpolation results of the previous cycle. The second block, the scan, is used to set the working status flags on the control panel and process the information input from the control panel. The third block, the auxiliary function processing, can call the machine tool logic function subroutines to execute M, S, T auxiliary functions and machine tool logic status control. The fourth block, the interpolation program, can calculate the position deviation value, serving as the basis for servo control in the next cycle. The back scan can modify the status flags on the control panel, indicating the current status to the operator, and then return to the background program. The foreground program is a timed interrupt handler. This interrupt handler interrupts once every certain time interval (e.g., 10ms), and the CPU executes the foreground program once. The process is as follows: the program starts, initializes, and then enters the background program, while simultaneously enabling the timed interrupt. Every 10ms, the timed interrupt occurs, executing the interrupt service routine, i.e., the foreground program. At this time, the background program stops running; after the timer interrupt program finishes execution, it returns to the background program; after 10ms, the timer interrupt occurs again, and so on, to complete all the functions of the CNC system. The overall software design of this system is to input the part processing program of the CNC machine tool through the keyboard, and then perform self-check to determine whether the program meets the specifications. If it does not meet the specifications, an error message will be displayed; if it is correct, the corresponding program segment will be called for processing. The specific program flow is shown in Figure (2). References 1 Zhang Zhuyin CNC Principles and CNC Machine Tools Chemical Industry Press 2 Li Shanshu CNC Machine Tool Principles and Applications Machinery Industry Press 3 Ren Yuxue et al Machine Tool Computer Numerical Control Technology Beijing Institute of Technology Press 4 Li Guangdi Single-chip Microcomputer Basics Beijing University of Aeronautics and Astronautics Press 5 Yu Xicun et al Single-chip Microcomputer Principles and Interface Technology Xi'an University of Electronic Science and Technology Press 6 Liu Baoyan Cheng Shukang Stepper Motor and its Drive Control System Harbin Institute of Technology Press 7 Wang Jin Single-chip Microcomputer Principles and Applications Chongqing University Press 8 Gao Ming Single-chip Microcomputer Interface and System Design Harbin Institute of Technology Press 9 Liu Shouyi Single-chip Microcomputer Application Technology Xi'an University of Electronic Science and Technology Press