In the CNC machine tool system, the functional modules can be divided into two parts: one part is the functions with low real-time requirements, such as human-machine interface interaction management, etc.; the other part is the functions with high real-time requirements, mainly servo control, interpolation calculation, etc. According to this feature, the system adopts a two-level control structure, using the rich software resources of IPC to provide a graphical human-machine interaction environment; using the high real-time and stability of the embedded execution controller to achieve fast and reliable control, giving full play to the advantages of both. The two levels use the serial port for real-time communication. This paper mainly introduces the implementation of the embedded execution controller.
1 Hardware structure of CNC machine tool system
The hardware structure of the CNC machine tool system is shown in Figure 1. The IPC is the upper computer, which is installed with special software to realize human-machine interaction; the embedded execution controller composed of the C8051020 chip and its peripheral circuits is the lower computer, responsible for real-time and reliable control. The execution controller receives the command information (including: interpolation command, switch control command) from the upper computer through the serial port, and then converts this information into control signals and transmits it to the corresponding execution components. For example, the interpolation command is converted into a series of interpolation signals and sent to the motor control component; the switch control command is converted into an output signal and sent to the corresponding switch controller through the I/O drive isolation interface board. The execution controller also has two detection tasks: one is to detect whether the tool moves to the limit position of each axis, and the other is to detect the gap voltage. These two pieces of information will provide a basis for automatic adjustment control during movement. The execution controller is also responsible for assembling the running status information into frames and transmitting it to the host computer in real time.
2. Porting of μC/OS-Ⅱ on C8051F020
To use μC/OS-Ⅱ, you must first successfully port this kernel to C8051F020. The porting of μC/OS-Ⅱ mainly modifies the three files OS_CPU.H, OS_CPU_A.ASM and OS_CPU_C.C. The specific modifications are introduced below.
2.1 Modification of OS_CPU.H file
OS_CPU.H includes processor-related constants, macros and type definitions defined by #define. Among them, the parts that need to be modified are as follows:
2.2 Modification of OS_CPU_A. ASM file
This file contains 4 assembly language functions.
(1) OSStartHighRdy() function is called in the multi-task system startup function OSStart(). Its function is to set the system running flag OSRunning = TRUE; load the stack pointer of the highest priority task in the ready list into SP, and force the interrupt to return.
(2) OSCtxSw() function is called in the task-level switching function. Its function is to save the environment variables of the current task, store the current SP in the task TCB, load the SP of the highest priority task ready, restore the environment variables of the highest priority task ready, and return from the interrupt. In this way, the task-level switching is completed.
(3) OSIntCtxSw() is called in the exit interrupt service function OSIntExit(). Its function is to implement interrupt-level task switching.
(4) OSTIcklSR() system clock beat interrupt service function, the size of its cycle determines the minimum time interval service that the kernel can provide to the application system. The interrupt is completed by the TO timer of C8051F020, and the timing time is set to 20 ms. The modified code is as follows:
Where: TOVAL is the time constant of the 16-bit timer T0. The system uses a 25 MHz external crystal oscillator and mode 1 (16-bit) timing.
2.3 Modification of OS_CPU_C. C file
This file defines 10 C functions, as follows:
Among them, the most important is OSTaskStklnit(), which is used to initialize the stack, return the lowest address of the stack, and the length of the stack, which is convenient for assembly language to implement task switching. The other 9 functions have no specific functions yet, and their functions can be added as needed when the system kernel is expanded.
3 Design of CNC machine tool system based on μC/OS-Ⅱ
3.1 Execution controller software structure
As shown in Figure 2, the system is generally divided into three functional blocks, namely: communication with IPC, command interpretation and command execution. Among them, communication has two aspects: sending and receiving; when interpreting commands, the switch control command is directly executed; during command execution, interpolation calculation, detection of gap voltage and limit switch status and processing monitoring are required. [page]
3.2 Task division and its priority are indeed sufficient
(1) Sending task
The embedded execution controller sends two types of information to the IPC: contact signals and running status information. When the embedded execution controller is in standby state, it regularly sends contact signals to the IPC to determine whether the IPC is working properly. If the IPC is running normally, the IPC will send a response signal back to the embedded execution controller after receiving the contact signal. If no response is received after sending multiple contact signals, it is considered that the IPC has an error. When the embedded actuator is in the processing state, it sends the running status information to the IPC in a fixed format regularly. After receiving the information, the IPC converts it into graphics, text and other information for display and provides it to the operator, so that the processing status can be grasped in real time. The real-time requirements of the sending task are low.
(2) Receiving task
The embedded execution controller receives three types of information sent by the IPC: contact, response and command. If a contact signal or a response signal is received, the receiving task directly processes it (sends a response signal or refreshes the contact status bit); if it is neither a contact signal nor a response signal, it is considered to be a command message. After the receiving task receives the command completely, it closes the write receive buffer and activates the command interpretation task. The receiving task is triggered by the communication port receiving interrupt, and its real-time requirement is high.
(3) Command interpretation task
The command interpretation task first verifies and interprets the command information in the receiving buffer. After the processing is completed, the receiving buffer is cleared and opened to allow the reception of new commands. The purpose of this is to avoid the accumulation of multiple commands in the receiving buffer. Before the current command interpretation is completed, no new command is received to improve the response speed of the embedded execution controller to the command. According to the length of the command execution time, the commands are divided into two types: switch control commands and interpolation commands. The execution time of the switch control command is short, so it is directly executed after the command interpretation to reduce the time consumption of task switching. The interpolation command is a processing command with a long running time. It is executed by a special processing monitoring task. The command interpretation task is only responsible for activating the processing monitoring task after the command interpretation is completed. The command interpretation task has high real-time requirements.
(4) Processing monitoring task
The processing monitoring task activates the interpolation calculation task according to the current working status (manual mode or automatic mode) and monitors the processing status. In manual working mode, the operator manually controls the tool to move in six directions of -x, +x, -y, +y, -z, +z, the tool returns to the reference point, the end face is aligned, and the hole center is located on the PC. In automatic working mode, the operator transmits linear and circular motion commands to the controller, and the controller automatically completes the linear motion. The real-time requirements of the processing monitoring task are relatively high.
(5) Interpolation calculation task
The interpolation calculation task is to calculate the coordinate value of the middle point between the starting point and the end point of the contour. This system uses the point-by-point comparison method for interpolation. Each execution of the interpolation task generates one stroke increment, and each stroke increment is output to the stepper motor in the form of one pulse. The running cycle of the interpolation task may be lower than the operating system clock, reaching thousands of times per second, so timer 1 is used as the interpolation motion time controller. The interpolation calculation task has the highest real-time requirements in this software.
(6) Gap voltage detection and limit switch status detection tasks
This system is used for EDM wire cutting CNC machine tools. The gap voltage is the discharge voltage between the tool (electrode wire) and the workpiece during EDM. This data is an important parameter for real-time detection of the EDM process and needs to be collected in real time. The limit switch refers to a state switch triggered when the tool moves to the boundary position of the processing table. When the tool reaches this induction switch, it should stop working to play a protective role, that is, to limit the displacement of the movement. This information also needs to be collected in real time. These two tasks have the characteristics of high real-time performance, frequent execution, and short execution time, so they are set as a detection task. Similar to the interpolation task, since the running cycle of the detection task is lower than the operating system clock, timer 3 is used as the time trigger of the detection task. The
above functions are divided into 6 tasks, the functions of these tasks are introduced, and their real-time requirements are analyzed. The above task division is shown in Table 1.
3.3 Communication between tasks
After completing the task division, it is also necessary to consider the communication and synchronization of tasks. The sending task is independent of the detection task, and the receiving task, command interpretation task and processing monitoring task are related, as shown in Figure 3. Here, semaphores and mailboxes are needed to solve the communication synchronization between tasks.
(1) Command semaphore SemCmd. When the receiving task receives a command message, it sends out the semaphore, which is received by the command interpretation task. After taking out and interpreting the command, it clears the semaphore and allows receiving new commands.
(2) Processing start message mailbox Mbox. When the command interpretation task finds that the command message is an interpolation command, it translates the message into a specified format and stores it in the mailbox, sends it out, and the processing monitoring task receives it.
4 Experimental results
In the experimental test, the IPC sends the linear interpolation command G01X1000Y2000\LF to the execution controller through the serial port, as shown in Figure 4. Observe the x and y axis coordinates in the returned information. The points are basically distributed around the straight line between point (O, O) and point (1000, 2000), and the error is less than 1 motion equivalent, which shows that the whole system is running normally.
5 Conclusion
The C8051F020 processor has rich hardware resources and powerful processing performance. μC/OS-Ⅱ has the characteristics of high real-time performance, good versatility, and convenient transplantation and expansion. Based on this software and hardware platform, the complexity of the system can be reduced and the speed of product development can be increased. It has been verified that the hardware and software system can meet the requirements of the CNC system and is feasible.
Keywords:C8051 μCOS-Ⅱ
Reference address:Realization of Embedded Execution Controller for CNC Machine Tools Based on C8051 and μC/OS-Ⅱ
1 Hardware structure of CNC machine tool system
The hardware structure of the CNC machine tool system is shown in Figure 1. The IPC is the upper computer, which is installed with special software to realize human-machine interaction; the embedded execution controller composed of the C8051020 chip and its peripheral circuits is the lower computer, responsible for real-time and reliable control. The execution controller receives the command information (including: interpolation command, switch control command) from the upper computer through the serial port, and then converts this information into control signals and transmits it to the corresponding execution components. For example, the interpolation command is converted into a series of interpolation signals and sent to the motor control component; the switch control command is converted into an output signal and sent to the corresponding switch controller through the I/O drive isolation interface board. The execution controller also has two detection tasks: one is to detect whether the tool moves to the limit position of each axis, and the other is to detect the gap voltage. These two pieces of information will provide a basis for automatic adjustment control during movement. The execution controller is also responsible for assembling the running status information into frames and transmitting it to the host computer in real time.
2. Porting of μC/OS-Ⅱ on C8051F020
To use μC/OS-Ⅱ, you must first successfully port this kernel to C8051F020. The porting of μC/OS-Ⅱ mainly modifies the three files OS_CPU.H, OS_CPU_A.ASM and OS_CPU_C.C. The specific modifications are introduced below.
2.1 Modification of OS_CPU.H file
OS_CPU.H includes processor-related constants, macros and type definitions defined by #define. Among them, the parts that need to be modified are as follows:
2.2 Modification of OS_CPU_A. ASM file
This file contains 4 assembly language functions.
(1) OSStartHighRdy() function is called in the multi-task system startup function OSStart(). Its function is to set the system running flag OSRunning = TRUE; load the stack pointer of the highest priority task in the ready list into SP, and force the interrupt to return.
(2) OSCtxSw() function is called in the task-level switching function. Its function is to save the environment variables of the current task, store the current SP in the task TCB, load the SP of the highest priority task ready, restore the environment variables of the highest priority task ready, and return from the interrupt. In this way, the task-level switching is completed.
(3) OSIntCtxSw() is called in the exit interrupt service function OSIntExit(). Its function is to implement interrupt-level task switching.
(4) OSTIcklSR() system clock beat interrupt service function, the size of its cycle determines the minimum time interval service that the kernel can provide to the application system. The interrupt is completed by the TO timer of C8051F020, and the timing time is set to 20 ms. The modified code is as follows:
Where: TOVAL is the time constant of the 16-bit timer T0. The system uses a 25 MHz external crystal oscillator and mode 1 (16-bit) timing.
2.3 Modification of OS_CPU_C. C file
This file defines 10 C functions, as follows:
Among them, the most important is OSTaskStklnit(), which is used to initialize the stack, return the lowest address of the stack, and the length of the stack, which is convenient for assembly language to implement task switching. The other 9 functions have no specific functions yet, and their functions can be added as needed when the system kernel is expanded.
3 Design of CNC machine tool system based on μC/OS-Ⅱ
3.1 Execution controller software structure
As shown in Figure 2, the system is generally divided into three functional blocks, namely: communication with IPC, command interpretation and command execution. Among them, communication has two aspects: sending and receiving; when interpreting commands, the switch control command is directly executed; during command execution, interpolation calculation, detection of gap voltage and limit switch status and processing monitoring are required. [page]
3.2 Task division and its priority are indeed sufficient
(1) Sending task
The embedded execution controller sends two types of information to the IPC: contact signals and running status information. When the embedded execution controller is in standby state, it regularly sends contact signals to the IPC to determine whether the IPC is working properly. If the IPC is running normally, the IPC will send a response signal back to the embedded execution controller after receiving the contact signal. If no response is received after sending multiple contact signals, it is considered that the IPC has an error. When the embedded actuator is in the processing state, it sends the running status information to the IPC in a fixed format regularly. After receiving the information, the IPC converts it into graphics, text and other information for display and provides it to the operator, so that the processing status can be grasped in real time. The real-time requirements of the sending task are low.
(2) Receiving task
The embedded execution controller receives three types of information sent by the IPC: contact, response and command. If a contact signal or a response signal is received, the receiving task directly processes it (sends a response signal or refreshes the contact status bit); if it is neither a contact signal nor a response signal, it is considered to be a command message. After the receiving task receives the command completely, it closes the write receive buffer and activates the command interpretation task. The receiving task is triggered by the communication port receiving interrupt, and its real-time requirement is high.
(3) Command interpretation task
The command interpretation task first verifies and interprets the command information in the receiving buffer. After the processing is completed, the receiving buffer is cleared and opened to allow the reception of new commands. The purpose of this is to avoid the accumulation of multiple commands in the receiving buffer. Before the current command interpretation is completed, no new command is received to improve the response speed of the embedded execution controller to the command. According to the length of the command execution time, the commands are divided into two types: switch control commands and interpolation commands. The execution time of the switch control command is short, so it is directly executed after the command interpretation to reduce the time consumption of task switching. The interpolation command is a processing command with a long running time. It is executed by a special processing monitoring task. The command interpretation task is only responsible for activating the processing monitoring task after the command interpretation is completed. The command interpretation task has high real-time requirements.
(4) Processing monitoring task
The processing monitoring task activates the interpolation calculation task according to the current working status (manual mode or automatic mode) and monitors the processing status. In manual working mode, the operator manually controls the tool to move in six directions of -x, +x, -y, +y, -z, +z, the tool returns to the reference point, the end face is aligned, and the hole center is located on the PC. In automatic working mode, the operator transmits linear and circular motion commands to the controller, and the controller automatically completes the linear motion. The real-time requirements of the processing monitoring task are relatively high.
(5) Interpolation calculation task
The interpolation calculation task is to calculate the coordinate value of the middle point between the starting point and the end point of the contour. This system uses the point-by-point comparison method for interpolation. Each execution of the interpolation task generates one stroke increment, and each stroke increment is output to the stepper motor in the form of one pulse. The running cycle of the interpolation task may be lower than the operating system clock, reaching thousands of times per second, so timer 1 is used as the interpolation motion time controller. The interpolation calculation task has the highest real-time requirements in this software.
(6) Gap voltage detection and limit switch status detection tasks
This system is used for EDM wire cutting CNC machine tools. The gap voltage is the discharge voltage between the tool (electrode wire) and the workpiece during EDM. This data is an important parameter for real-time detection of the EDM process and needs to be collected in real time. The limit switch refers to a state switch triggered when the tool moves to the boundary position of the processing table. When the tool reaches this induction switch, it should stop working to play a protective role, that is, to limit the displacement of the movement. This information also needs to be collected in real time. These two tasks have the characteristics of high real-time performance, frequent execution, and short execution time, so they are set as a detection task. Similar to the interpolation task, since the running cycle of the detection task is lower than the operating system clock, timer 3 is used as the time trigger of the detection task. The
above functions are divided into 6 tasks, the functions of these tasks are introduced, and their real-time requirements are analyzed. The above task division is shown in Table 1.
3.3 Communication between tasks
After completing the task division, it is also necessary to consider the communication and synchronization of tasks. The sending task is independent of the detection task, and the receiving task, command interpretation task and processing monitoring task are related, as shown in Figure 3. Here, semaphores and mailboxes are needed to solve the communication synchronization between tasks.
(1) Command semaphore SemCmd. When the receiving task receives a command message, it sends out the semaphore, which is received by the command interpretation task. After taking out and interpreting the command, it clears the semaphore and allows receiving new commands.
(2) Processing start message mailbox Mbox. When the command interpretation task finds that the command message is an interpolation command, it translates the message into a specified format and stores it in the mailbox, sends it out, and the processing monitoring task receives it.
4 Experimental results
In the experimental test, the IPC sends the linear interpolation command G01X1000Y2000\LF to the execution controller through the serial port, as shown in Figure 4. Observe the x and y axis coordinates in the returned information. The points are basically distributed around the straight line between point (O, O) and point (1000, 2000), and the error is less than 1 motion equivalent, which shows that the whole system is running normally.
5 Conclusion
The C8051F020 processor has rich hardware resources and powerful processing performance. μC/OS-Ⅱ has the characteristics of high real-time performance, good versatility, and convenient transplantation and expansion. Based on this software and hardware platform, the complexity of the system can be reduced and the speed of product development can be increased. It has been verified that the hardware and software system can meet the requirements of the CNC system and is feasible.
Previous article:ATMEL8051 Series MCU Selection Guide
Next article:Application design of single chip microcomputer in intelligent power cabinet
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
Guess you like
- Three-cell lithium battery charging management IC-VAS5176 charging current test
- USB TYPE C interface problem urgent help
- Notice on the extension of ON Semiconductor and Avnet IoT Innovation Design Competition
- RTC timekeeping function + GPIO control LCD12864 display
- On-chip memory resources of RSL10
- UART Protocol Timing Summary
- Non-inverting proportional amplifier feedback resistor setting
- I encountered a problem about Keil today
- Cumulative error analysis and clock frequency optimization for UART communication in MSP430FR2311
- [Shanghai Hangxin ACM32F070 development board + touch function evaluation board] Voltage meter implementation and ADC performance rough test