1. Introduction
With the rapid development of computer technology, traditional manufacturing has undergone fundamental changes. Developed industrial nations have invested heavily in research and development of modern manufacturing technologies, proposing entirely new manufacturing models. In modern manufacturing systems, numerical control (NC) technology is a key technology. It integrates microelectronics, computers, information processing, automatic detection, and automatic control, featuring high precision, high efficiency, and flexible automation. It plays a crucial role in achieving flexible automation, integration, and intelligence in the manufacturing industry. Currently, NC technology is undergoing a fundamental transformation, evolving from a dedicated, closed-loop open-loop control mode to a general-purpose, open, real-time, dynamic, fully closed-loop control mode. Based on integration, NC systems have achieved ultra-thin and ultra-miniaturized designs. Based on intelligence, by integrating computer, multimedia, fuzzy control, neural network, and other multidisciplinary technologies, NC systems have achieved high-speed, high-precision, and high-efficiency control. During machining, they can automatically correct, adjust, and compensate for various parameters, enabling online diagnosis and intelligent fault handling. Based on networking, CAD/CAM is integrated with NC systems, machine tools are networked, and centralized group control machining is achieved.
With the rapid development of computer technology, computers are increasingly being used in various aspects of people's work and life. Microcontrollers and their application technologies have also made significant progress in recent years. Microcontrollers are widely used in industrial automation control, intelligent instruments, data acquisition, communication, and home appliances. With a development model completely different from general-purpose microcomputers, microcontrollers continuously meet the requirements of industrial measurement and control and reliable operation in harsh environments. Microcontrollers have become an indispensable and important component in modern industry. The development speed of microcontroller technology is very rapid. Faster and more powerful 16-bit and 32-bit microcontrollers have emerged, but 8-bit microcontrollers, especially the new generation of high-end 8-bit microcontrollers, have excellent performance and can meet the needs of most microcontroller application areas. In addition, they have advantages such as high reliability, simple peripheral chip support system structure, rich application software, mature technology, and convenient development and application, and still have a certain market share in microcontroller applications.
With the development of my country's market economy, domestic and international market competition is becoming increasingly fierce. To address the complex, precise, small-batch, and variable machining problems encountered by enterprises, CNC machine tools are needed. However, these machine tools are expensive, making them unaffordable for small businesses. This system uses the MCS-51 series microcontroller to perform CNC design on specific ordinary machine tools, which can play a significant role in enterprise manufacturing. In-depth research and analysis of CNC machine tool retrofit technology were conducted, with a focus on the design of the machine tool control system. The entire control system is centered on the CNC system, and the microcontroller design enables the CNC system, electrical control system, and servo system to work in a coordinated and unified manner to achieve CNC machining.
2. Structure of CNC machine tools
2.1 Overview of CNC Lathes
CNC lathes, also known as Computer Numerical (CNC) lathes, are lathes controlled by computer numerical control. Horizontal lathes rely on manual operation to perform various cutting operations, while CNC lathes input a pre-programmed machining program into a CNC system. The CNC system then controls the sequence of movements, amount of travel, and feed rate of the lathe's feed motion components via servo motors on the X and Z axes. Combined with the spindle speed and direction of rotation, this allows for the machining of various shapes of shafts or disc-shaped rotating parts. Therefore, CNC lathes are currently the most widely used CNC machine tools.
2.2 Main Drive System of CNC Lathe
The transmission system diagram of the MJ-50 CNC lathe is shown in Figure 1. The main motion transmission system is driven by an 11/15KW AC servo motor, which drives the spindle via a 1:1 belt drive, enabling stepless speed regulation of the spindle within the range of 35-3500 r/min. The gear transmission mechanism inside the spindle box is eliminated. This reduces the impact of the original gears on the spindle and facilitates maintenance.
2.3 Spindle Box Structure
The spindle employs a two-support structure. The front support consists of a double-row cylindrical roller bearing 11 and a pair of angular contact ball bearings 10. Bearing 11 supports radial loads. One large opening of the two angular contact ball bearings faces the front end of the spindle, and the other large opening faces the rear end, to withstand bidirectional axial and radial loads. The clearance of the front support bearings is adjusted using nuts 1 and 6. Screws 17 and 13 serve as anti-loosening devices. The spindle support is front-end positioned, and the spindle extends rearward due to thermal expansion. The double-row cylindrical roller bearings used in both the front and rear supports provide good support rigidity and a high permissible limiting speed. The angular contact ball bearings can withstand larger axial loads and also have a high permissible limiting speed. This support structure meets the needs of high-speed, high-load cutting.
2.4 Feed transmission system and transmission device
The X-axis and Z-axis feeds are driven by stepper motors. A simplified diagram of the X-axis feed transmission device is shown. Stepper motor 15 drives ball screw 6 to rotate via synchronous pulleys 14 and 10 and synchronous belt 12. Nut 7 on the ball screw drives tool holder 21 to move along the guide rail of slide plate 1, realizing the X-axis feed motion. The front support 3 of the ball screw consists of three angular contact ball bearings, one with its large end facing forward and two with their large ends facing backward, bearing axial loads in both directions. The front support is preloaded by nut 2. The rear support 9 of the ball screw is a pair of angular contact ball bearings, with their large ends facing away from each other, and is preloaded by nut 11. This type of support, with both ends fixed, has a more complex structure and manufacturing process, but it ensures and improves the axial stiffness of the screw. Z-axis feed transmission device. Stepper motor 14 is driven to ball screw 5 via synchronous pulleys 12 and 2 and synchronous belt 11. Nut 4 drives slide plate and tool post to move along the rectangular track of bed 13 (as shown in Figure b), realizing the feed motion of the Z-axis. The motor shaft and synchronous pulley 12 are connected without a key by tapered rings, as shown in the enlarged view. 19 and 20 are inner and outer tapered rings with interlocking tapered surfaces. When screw 17 is tightened, the end face of flange 18 presses the outer tapered ring 20, causing it to expand outward, while the inner tapered ring 19 contracts towards the motor shaft under force, thus connecting the motor shaft and the synchronous pulleys.
3. Control System Hardware Design
This paper selects the AT89S51 microcontroller as the core control processor for this CNC system design. Two AT89S51 microcontrollers are used for dual-machine communication. Two external 2764 EPROMs are used to store the control program, batch production workpiece machining programs and data. Two 8kb 6264 RAMs are used to store the trial production small-batch workpiece machining programs and data. Due to system expansion, to ensure unified programming addresses, 74LS373 and 74LS139 decoders are used to perform decoding and addressing of the expansion chips. Figure 1 shows the overall design block diagram of the control system.
Figure 1 Overall block diagram of the control system
Working principle: The microcontroller system is the core of the CNC system of the machine tool. By inputting commands through the keyboard, a series of continuous pulses sent by the CNC device are distributed to each phase winding of the stepper motor in a certain order through a ring distributor, optocoupler and power amplifier, so that each phase winding is energized or de-energized according to the pre-defined control method. In this way, the stepper motor is controlled to drive the worktable to move according to the instructions.
3.1 Communication Interface Design
This paper adopts the RS-485 dual-machine communication interface. RS-485 is a variant of RS-422A. The difference between them is that RS-422A is full-duplex, using two pairs of balanced differential signal lines, while RS-485 is half-duplex, using one pair of balanced differential signal lines. RS-485 is very convenient and relatively inexpensive for multi-station interconnection, so this interface is adopted. Figure 2 shows the dual-machine communication interface diagram in this design.
Figure 2. Dual-machine communication interface diagram
In the diagram above, RS-485 enables bidirectional, half-duplex communication between two machines. Before the AT89S51 microcontroller system sends or receives data, the transmit or receive gate of the SN75176 should be opened. When P1.0=1, the transmit gate is open, enabling the reception of RS-485 levels and the conversion of RS-485 levels to TTL levels.
3.2 Memory Expansion
The crystal oscillator was selected with a working frequency of 12MHz. The main controller was chosen as the AT89S51. Because the programming language for CNC milling machines is quite complex depending on the complexity of the parts being machined, and the data transfer volume is large, the internal storage space of the AT89S51 chip is far from sufficient to meet the requirements. It is necessary to expand the data storage and program memory areas. It is estimated that two 2764 chips will be used as program memory and two 6264 chips as data memory for each AT89S51 chip. Additionally, one 74LS373 address latch and one 74LS139 chip select chip will be used.
Figure 3 2764 Pin Diagram
3.3 Keyboard Display Circuit
According to system requirements, the movement of the machine tool's worktable and spindle speed need to be controlled via keyboard input commands. The worktable's position is displayed using LED digital tubes, with a travel range of 10 meters and an accuracy of 0.000001 meters. Therefore, eight LED digital tubes are used for dynamic display of X, Y, and Z axes. The spindle speed is also displayed dynamically using eight LED digital tubes. The keyboard has nine keys that control the three-axis movement of the worktable, spindle speed, lighting, and coolant and lubrication systems.
3.4 Photoelectric Encoder
An optical encoder is a sensor that converts the mechanical geometric displacement of an output shaft into pulses or digital signals through photoelectric conversion. It is currently the most widely used sensor. An optical encoder consists of a grating disk and a photoelectric detection device. The grating disk has several rectangular holes evenly spaced on a circular plate of a certain diameter. Since the optical encoder disk is coaxial with the motor, it rotates at the same speed as the motor. The detection device, composed of LEDs and other electronic components, detects and outputs several pulse signals. By calculating the number of pulses output per second, the current motor speed can be reflected. Furthermore, to determine the direction of rotation, the encoder disk can also provide two pulse signals with a 90° phase difference. The encoder disk sends the pulse signals to the MAX202 microcontroller, which feeds back the signals to the 51 microcontroller. The microcontroller then displays the motor speed through an LED digital display.
Figure 4 Schematic diagram of the encoder
3.5 Alarm Device
If any workbench moves to the edge of the track in either the X or Y direction, an OR gate will set port P1.4, triggering an over-limit alarm, stopping operation, emitting a buzzer, and illuminating a warning light.
3.6 Power Supply Circuit
This design requires two power supplies with different voltages: +5V and +24V.
1. Analysis of +5V power supply circuit design
The circuit is connected to 220V AC power. A 5V DC voltage is obtained through rectification, filtering, and a 7805 linear regulator. This means the transformer secondary voltage should be 7V. The peak value of a 7V sinusoidal AC voltage is approximately 9.8V. After bridge rectification (resulting in the voltage drop across the two PN junctions of the rectifier diodes), the voltage drops to approximately 7.8V. The 7805 requires an operating voltage greater than 7V, and 7.8V provides a slight margin. Through the 7805 chip's regulation, the final output is the required stable +5V voltage. Figure 5 shows the +5V power supply circuit diagram.
Figure 5 +5V power supply circuit diagram
2. +24V power supply circuit design analysis
The circuit is connected to 220V AC power. A +24V DC voltage is obtained through rectification and filtering. Since this voltage is used to drive the motor and the voltage stability requirement is not high, a linear regulator is not needed. The secondary voltage is stepped down to 26V by a transformer. After passing through a bridge rectifier with losses in the PN junction voltage drop of the two rectifier diodes, it becomes 24V. Filtering then yields a 24V output voltage. Figure 6 shows the +24V power supply circuit diagram.
Figure 6 +24V power supply circuit diagram
4. Software Design and Implementation
Based on the hardware structure and machining instruction format of the overall circuit diagram, the control program is designed using linear-circular interpolation calculation method. The entire control program consists of a main program, a T0 interrupt program, and an external/INTO interrupt program.
4.1 Main Program
The main program first performs system initialization, turning on the lighting equipment. Then, it scans the keyboard cyclically; if a command is entered, it processes it accordingly. If a start command is entered, it performs pre-run preparations and initializes relevant pointers and flags. For interrupt system initialization, T0 requests an interrupt from the CPU, causing the CPU to execute the component machining program. External interrupts are allowed, and component machining stops when the emergency stop key is pressed manually. Next, it cyclically checks the machining end flag. After machining is complete, it waits for a key command or a host command.
4.2T0 Interrupt Service Routine
The T0 interrupt service routine executes the machining program, fetching a new machining instruction only after the previous one is completed, until a stop is encountered, at which point interrupts are disabled and the end flag is set. During the execution of machining instructions, interpolation calculations for straight lines and circular arcs are performed based on the line type.
4.3 Emergency Stop
An emergency stop switch is a type of master control electrical appliance. When the machine is in a dangerous state, the emergency stop switch cuts off the power supply, stopping the equipment and protecting personnel and equipment safety. In this design, the emergency stop switch is connected to the main power supply; pressing it cuts off the main power supply, and the machine stops working.
4.4 Stepper Motor Position Control
The position control of a stepper motor requires two parameters:
The first parameter is the current position parameter of the actuator controlled by the stepper motor, called the absolute position. It has a limit, which is the distance the actuator travels. Exceeding this limit will trigger an alarm.
The second parameter is the distance to move from the current position to the target position. We can convert this distance into the number of steps of the stepper motor. This parameter is input externally via the keyboard.
The general practice for stepper motor position control is as follows: for each step the stepper motor takes, the step count decreases by 1. If no steps are missed, the step count will be exactly 0 when the actuator reaches the target position. Therefore, using a step count of 0 to determine whether the target position has been reached serves as a signal for the stepper motor to stop. The absolute position parameter can be used as a display parameter for human-machine interface. It is related to the direction of rotation of the stepper motor. When the stepper motor rotates forward, the absolute position increases by 1 for each step; when the stepper motor rotates in reverse, the absolute position decreases by 1 with each step.
Figure 7 shows the flowchart of the main control program.
Figure 7 Flowchart of the main control program
5. Conclusion
This paper describes a CNC milling machine control system based on the AT89S51 microcontroller. The system controls the movement of the worktable along the -X, +X, -Y, +Y, -Z, and +Z directions, the activation of lighting, and the spindle speed via keyboard control. It also reads EPROM program instructions. Communication with a PC is possible via serial port. An automatic alarm mechanism is included to detect insufficient coolant or lubricating oil. The X, Y, and Z coordinates and spindle speed are displayed in real-time on an LED digital display.
For more information, please visit the Machine Tool Channel.