Realization of Motion Control of Multi-thread Embroidery Machine under WinCE

Embroidery machines occupy an extremely important position in the sewing equipment industry and have a broad market at home and abroad. Compared with foreign high-end machines in terms of speed, noise, quality, and function, domestic embroidery machines have a large gap, and their competitive advantage is relatively small. Therefore, it is not only the market demand to strengthen the development of embroidery machines, but also helps to improve the nationality. Industry is of great significance. With the continuous development of embedded technologies such as SOC, ARM, FPGA and CPLD, the main controllers of embroidery machines based on embedded systems have occupied the mainstream in China, with faster CPU speed and multi-function module expansion. Making the motion control system of the embroidery machine more powerful, but the development direction of high speed, high precision and high intelligence puts higher requirements on the motion control system of the embroidery machine. On the basis of continuous improvement of the hardware, the performance of the software has become an evaluation system. An important assessment indicator of performance is also one of the difficulties in the development of embroidery machines.
The software implementation of this motion control system is based on a high-speed industrial embroidery machine architecture. The architecture uses an ARM9 processor S3C2440 as the CPU, combined with a CPLD expansion module. The main function is to meet the real-time performance of the embroidery machine at 1200 rpm. Requirements (currently the speed of the domestic mainstream high-speed industrial embroidery machine is 1000 rpm), that is, automatic embroidery, thread trimming and color changing are performed at a high speed to ensure the quality of the embroidery and satisfy some humanized requirements. In this paper, a software implementation scheme of embroidery machine motion control system based on Windows CE5.0 multithreading mechanism is proposed. This program has been applied in the independently developed high-speed industrial embroidery machine and has achieved good results.

1 Real-time requirements and module analysis of motion control system

The embroidering machine motion control system is a strong real-time system. The operating environment selected by the system must be able to respond in real time to the real-time tasks of the embroidering machine motion control system. If the real-time nature of the system response is not enough, the embroidery machine will appear intermittent during automatic operation. Such as instability. Due to the advantages of Windows CE system in terms of interface, human-computer interaction capability, multi-tasking, and openness, the development of an industrial control system based on Windows CE is called a trend.
Windows CE5.0 is a real-time operating system. In Windows CE5.0 system, the proper application of Windows CE multi-threading technology to solve the system's real-time multi-tasking has become the key to the development of technology. Embroidery motion control systems place high demands on the real-time performance of various motors and other modules. Windows CE multi-threading mechanism can meet this requirement because it can perform multiple tasks at the same time. At the same time, it uses an effective interrupt method to enhance the implementation of real-time requirements.
According to the functional requirements of the motion control system, the entire system is mainly divided into the following modules: (1) The spindle control module controls the operation of the spindle motor and drives the needle up and down. (2) XY stepper motor control module, control XY stepper motor, move the frame. (3) The trimming module controls the trimmer motor and completes the trimming operation. (4) The color change module controls the color change motor to complete the automatic color change operation. (5) Photoelectric detection module (A phase Z phase), spindle motor rotation position and count count feedback. (6) Limit processing module to prevent off-step when the stepper motor moves across the frame. (7) Break detection module detects if the thread on the needle is broken. (8) Alarm module, embroidery machine abnormal status alarm. The communication relationship between each module is shown in Figure 1:

2 Application of Multithreading Technology in Motion Control System

Windows CE 5.0 is a multi-threaded, multitasking operating system. A process consists of one or more threads. The thread is responsible for executing the code contained in the process address space. In fact, the operating system allocates CPU time slices for each individual thread in a rotating manner. Objectively, all the threads perform almost at the same time. According to the characteristics of the thread task, in the structure design of the motion control system, tasks that are related to each other and communicate with each other are designed into multiple threads in a process, so that these tasks share the address space of the process and reduce Communication and synchronization overhead. The design of this article is based on this mechanism.
In the entire embroidery machine system. The motion control part is a separate process in which several threads are divided according to the relationship between the various modules in Fig. 1. These threads are mainly composed of two large parts: a strong real-time thread part, including a spindle motor Threads, Stepper Motor Threads, Optical Encoder Threads, Limit Interrupt Threads, and Disconnection Processing Threads; real-time thread sections, including color-change threads, trimmer threads, and alarm threads. Thread synchronization in the system is mainly for strong real-time threads, and real-time threads are implemented by calling them like functions.

2.1 Multithreading Priority Settings

In a multi-threaded system, since high-priority threads can interrupt low-priority threads at any time and gain the right to run, the priority of each thread must be carefully planned when designing the system, and only the application thread's priority can be reasonably divided. The system can properly schedule these threads to ensure the system's real-time performance requirements.
Windows CE 5.0 supports a total of 256 priorities from 0 to 255, with 0 being the highest and 255 being the lowest. According to the priority arrangement of threads in the Windows CE operating system, 0-96 is the thread of the high real-time program [2]. In combination with the task arrangement of the overall system of the embroidery machine, the priority of the thread object of the motion control system is also mainly Arrange at this level. The threading tasks of the motion control section are divided according to the modules in the system. The content and priority arrangement are shown in Table 1:


To set and get the priority of a thread, you can use the CeSetThreadPriority() and CeGetThreadPriority() functions in the system. After the thread is created, its priority is also determined.

2.2 Coordination and Communication Between Threads

In a multithreaded system, it is important to synchronize the activities of different threads. WindowsCE5.0 provides a variety of ways to achieve coordination and synchronization between threads, with semaphores, critical sections, events, mutexes, peer-to-peer message queues, etc. . Each method has its own characteristics and applicable occasions. In the design of the motion control system, thread synchronization is mainly implemented using events and interrupts.

2.2.1 Application of Event Event

Events are more widely used synchronization objects. If a thread needs to notify other threads that a certain time occurs, events can be synchronized using the event. The previous thread sends a notification signal to the time. Other threads interested in the event are generally The call wait function waits in time. The initialization thread starts initialization after setting the event to no signal state. When initialization is complete, the thread sets the event to signaled, informing the next thread to complete the rest of the work. The following events are mainly defined in the motion control system:
Event_EncoderA //Encoder A phase count event, marking the position of the spindle motor (100° and 220°)
Event_MotorX //The X-axis motor movement event marks the X-axis motor running.
Event_MotorY //Y-axis motor movement event, indicating that Y-axis motor is running.
Event_EncoderZ // Encoder Z phase interrupt event, marking the motor rotation for one week.
Event_Limit // limit interrupt event, mark the border of the frame.
The event creation is implemented using the CreateEvent() function, which is initialized after creating the event.

2.2.2 Motion Control System Interrupt Handling

In motion control systems, interrupt handling is an important part. The creation of an event is also prepared for interrupt processing. The interrupt response is implemented based on the event trigger. The configuration of the interrupt source is performed by the OAL (OEM Adaptation Layer) in Windows CE [3][5]. The OAL maps the physical interrupt number to a logical interrupt number and correlates specific events. The implementation method is as follows:
(1) Applying g_Count1sysint to the IRQ_EINT8 logical interrupt number: KernelIoControl (IOCTL_HAL_REQUEST_SYSINTR, &IRQ_EINT8, sizeof(UINT32), &g_Count1sysint, sizeof(UINT32), NULL);
(2) Logical interrupt number g_Count1sysint Associated event Event_MotorX: InterruptInitialize(g_Count1sysint, Event_MotorX, 0, 0); The same operation applies for the logical interrupt number of other physical interrupt number and the event correlation. The relationship among physical interrupts, logical interrupts, events and threads is shown in Figure 2.


Each event corresponds to an interrupt response in the system. When the event is triggered, it is processed according to the event type and time. Interrupt processing thread is the key to driver programming, and its efficiency is directly related to the real-time performance of the system.

2.2.3 Implementation of Thread Communication

The motion control system software implementation must be closely integrated with the mechanical characteristics of the servo motor and the working principle of each motor of the embroidery machine. The entire program is realized by how the spindle motor realizes the communication and cooperation with other modules in one revolution, mainly including the motor. Stepping motor phase between 220° and 100° (approx. 240°) and Stepping motor during 100° to 220° (approx. 120°). Sets the event to respond to the relevant interrupts in the two phases. Processing, synchronization between the various threads. In the whole system, the spindle motor runs as the main thread of the software. During the running of the thread, the thread waits, informs, and calls other threads through the interrupt event to complete the embroidery operation. The flow chart of the spindle motor thread program is shown in FIG. 3, stepping. Motor thread flow chart shown in Figure 4:


The spindle motor thread determines the movement modes such as thread trimming, color change, jump stitch and embroidery according to the control code of the pattern file. When it is in the normal embroidery state, the spindle motor thread is in a blocking state, waiting for the events Motor_Event_MotorX and Event_MotorY to finish moving The spindle motor can only be moved after being set. In the process of moving the spindle motor, since the priority of the photoelectric encoder thread is higher than that of the spindle motor thread, it can respond to the A-phase encoder interrupt and set the event Event_EncoderA(100°) and Event_EncoderA. (220°), can trigger stepper motor thread with higher priority than spindle motor thread priority, complete 220°~100° stepper motor stage and 100°~220° stepper motor operation, then stepper motor The thread initializes Event_EncoderA (100°) and Event_EncoderA (220°), sets the Event_MotorX and Event_MotorY events to notify the spindle motor thread to run, and the stepper motor thread goes back to blocking, waiting for Event_EncoderA (100°) and Event_EncoderA (220°) The setting of the event, to this embroidery machine completed the operation of a stitch During the operation of the stepper motor, if the embroidery frame crosses the boundary, the motion control system will respond to the interrupt, set Event_Limit, execute the high-priority limit out-of-bounds thread and alarm. During the operation of the spindle motor, the system also responds to the disconnection detection interrupt. If the line is disconnected, alarm processing will also be performed.

3 Test test

The article uses the Windows CE 5.0 multi-threading mechanism to complete the realization of the function of the computerized embroidery machine motion control system. Under this system, the integrated system has a relatively small overhead in terms of control, scheduling, communication, and synchronization. Combined with the interruption, it satisfies the requirements of the system's strong real-time performance. This solution has been applied to the high-speed industrial embroidery machines developed independently. During the test process, we can see that the embroidery machine starts quickly when it is working normally, it is stable and reliable when it is running at 1200 rpm, and it has less noise, and it can stop accurately. In the embroidery process, each function is executed. Compared with the Concord, the quality and efficiency of embroidery have also been greatly improved, and all aspects of the system have achieved the intended purpose.

4 Conclusion

The innovation of this paper is to combine the multi-threading mechanism of Windows CE 5.0 with hardware interrupt technology in the embroidering machine motion control system with strong real-time requirements, achieving its predetermined function with minimum computational resource consumption, and satisfying the system. Real-time requirements at the same time, to avoid the waste of resources and improve the operating efficiency of the system software. The test shows that the performance of the embroidery machine in response speed, control accuracy, noise reduction, etc. is significantly improved at high speed operation, and has a high engineering value.

references

[1]Su Y. Design and implementation of computer embroidery machine control system [D]. Xi'an: School of Software Engineering, Northwestern Polytechnical University, 2007.
[2] Zhang Dongquan, Tan Nanlin, Wang Xuemei et al. Windows CE practical development technology [M]. Beijing: Publishing House of Electronics Industry, 2006.
[3]He Zongjian. Windows CE Embedded System[M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2006.
[4]JIA Lishan, WANG Liwen, XING Zhiwei, HAN Junwei. 3R Robot Control System Based on Multi-thread Technology[J]. Microcomputer Information, 2007, 6-2: 243-245.
[5] Huang Dan, Shao Huihe. Multithreading Programming Based on Windows CE Platform[J]. Microcomputer Information, 2007.12-2:53-55.

Posted on