Share this

Implementation of motion control for an embroidery machine under WinCE multithreading

2026-04-06 05:42:57 · · #1
Abstract: This paper proposes a software design scheme for a motion control system of an embroidery machine based on the multi-threading mechanism of Windows CE5.0. Combining hardware interrupt technology and employing thread synchronization methods, the system achieves the high real-time performance requirements of the embroidery machine motion control system, solving problems such as slow response speed, low stopping control accuracy, and high noise during high-speed operation. This scheme has been applied to a self-developed embroidery machine system, and tests show that the performance of the embroidery machine is significantly improved in all aspects during high-speed operation, demonstrating high engineering value. Keywords: multithreading; Windows CE; interruption; embroidery machine Abstract: This paper proposes an approach for the movement control system of an embroidery machine based on Windows CE 5.0 multithreading. Using hardware interruption technology and thread synchronization methods, it realizes the hard real-time requirements of the movement control system, solving difficulties such as slow response, low precision, and high noise. This approach has been applied in a project, and the experimental results indicate that the machine's capabilities have been improved. It is valuable for project development. Key words: multithreads; Windows CE; interruption; embroidery 1 Introduction Embroidery machines occupy an extremely important position in the sewing equipment industry, with a broad market both domestically and internationally. Compared with high-end foreign machines, domestically produced embroidery machines lag significantly in terms of speed, noise, quality, and functionality, resulting in a smaller competitive advantage. Therefore, strengthening the development of embroidery machines is not only a market demand but also of great significance for improving the national industry. With the continuous development of embedded technologies such as SOC, ARM, FPGA, and CPLD, embedded systems have become the mainstream main controller for embroidery machines in China. The fast processing speed of CPUs and the multi-functional module expansion capabilities have made the motion control system of embroidery machines more powerful. However, the development trend towards high speed, high precision, and high intelligence has placed higher demands on the motion control system. Based on the continuous improvement of hardware, software performance has become an important indicator for evaluating system performance and is also one of the difficulties in embroidery machine development. This paper implements the motion control system software based on a high-speed industrial embroidery machine architecture. This architecture uses the ARM9 processor S3C2440 as the CPU, combined with a CPLD expansion module. Its main function is to meet the real-time requirements of the embroidery machine at a speed of 1200 rpm (the mainstream speed of high-speed industrial embroidery machines in China is currently 1000 rpm), that is, to ensure embroidery quality and meet some user-friendly requirements while completing automatic embroidery, thread trimming, and color changing at high speed. This paper proposes a software implementation scheme for the motion control system of an embroidery machine based on the Windows CE 5.0 multithreading mechanism. This scheme has been applied to a self-developed high-speed industrial embroidery machine and has achieved good results. 2. Real-time Requirements and Module Analysis of the Motion Control System The motion control system of the embroidery machine is a strong real-time system. The operating environment selected by the system must be able to respond promptly to the real-time tasks of the motion control system. If the real-time response of the system is insufficient, it will lead to instability such as intermittent operation during the automatic operation of the embroidery machine. Due to the advantages of the Windows CE system in terms of interface, human-computer interaction capabilities, multitasking, and openness, the development of industrial control systems based on Windows CE has become a trend. Windows CE 5.0 is a real-time operating system. In the Windows CE 5.0 system, the reasonable application of Windows CE multithreading technology to solve the real-time multitasking of the system has become the key to development technology. The motion control system of the embroidery machine places high demands on the real-time performance of various motors and other modules. The Windows CE multithreading mechanism can better meet this requirement because it can execute multiple tasks simultaneously. Combined with the use of effective interrupt methods, the real-time requirements are further enhanced. According to the functional requirements of the motion control system, the whole system is mainly divided into the following modules: (1) Main spindle control module, which controls the operation of the main spindle motor and drives the embroidery needle to move up and down. (2) XY stepper motor control module, which controls the XY stepper motor to move the embroidery frame. (3) Thread cutting module, which controls the thread cutting motor to complete the automatic thread cutting operation. (4) Color changing module, which controls the color changing motor to complete the automatic color changing operation. (5) Photoelectric detection module (A phase Z phase), which counts and provides feedback on the rotation position and number of revolutions of the main spindle motor. (6) Limit processing module, which prevents the stepper motor from overstepping its position when moving the frame. (7) Thread breakage detection module, which detects whether the thread on the embroidery needle is broken. (8) Alarm module, which alarms the abnormal status of the embroidery machine. The communication relationship between the modules is shown in Figure 1: 3 Application of multithreading technology in motion control system Windows CE5.0 is a multithreaded multitasking operating system. A process consists of one or more threads, and the threads are responsible for executing the code contained in the process address space. In practice, the operating system allocates CPU time slices to each independent thread in a round-robin manner, objectively resulting in all threads executing almost simultaneously. Based on the characteristics of thread tasks, when designing the motion control system structure, tasks that are functionally related and communicate frequently with each other are designed as multiple threads within a single process. This allows these tasks to share the address space of the process, reducing communication and synchronization overhead. This design utilizes this mechanism. In the entire embroidery machine system, the motion control part is a separate process. Within this process, based on the relationships between the modules shown in Figure 1, several threads are divided. These threads mainly consist of two parts: a strong real-time thread part, including the spindle motor thread, stepper motor thread, photoelectric encoder thread, limit interrupt thread, and thread breakage handling thread; and a real-time thread part, including the color-changing thread, thread-cutting thread, and alarm thread. Thread synchronization in the system primarily refers to the strong real-time threads, while real-time threads implement their functions by being invoked like functions. 3.1 Setting the priority of multithreaded threads In a multithreaded system, since high-priority threads can interrupt low-priority threads at any time and obtain the right to run, the priority of each thread must be carefully arranged when designing the system. Only by reasonably dividing the priority of application threads can the system reasonably schedule these threads, thereby ensuring the real-time performance requirements of the system. Windows CE5.0 supports a total of 256 priorities from 0 to 255, of which 0 is the highest priority and 255 is the lowest priority. According to the priority hierarchy of threads in the Windows CE operating system, 0 to 96 are threads of high real-time programs [2]. Combined with the task arrangement of the overall system of the embroidery machine, the priority of the thread objects of the motion control system is also mainly arranged at this level. The thread tasks of the motion control part are divided according to the modules in the system. The content and priority arrangement are shown in Table 1. In order to set and obtain the priority of a thread, the CeSetThreadPriority() and CeGetThreadPriority() functions can be used in the system. After the thread is created, its priority is also determined. 3.2 Coordination and communication between threads In a multithreaded system, it is important to synchronize the activities of different threads. Windows CE 5.0 provides various methods for thread coordination and synchronization, including semaphores, critical sections, events, mutexes, and peer-to-peer message queues. Each method has its own characteristics and applicable scenarios. In the motion control system design, thread synchronization is mainly achieved using events and interrupts. 3.2.1 Application of Events Events are widely used synchronization objects. If a thread needs to notify other threads that a certain event has occurred, it can use an event synchronization object. The previous thread sends a notification signal to the event, and other threads interested in the event generally call a wait function to wait at the event. Initialization The thread sets the event to a non-signaled state and then begins initialization. After initialization is complete, the thread sets the event to a signaled state and notifies the next thread to complete the remaining work. The following events are mainly defined in the motion control system: Event_EncoderA // Encoder A phase counting event, indicating the position of the spindle motor (100° and 220°) Event_MotorX // X-axis motor movement event, indicating that the X-axis motor has finished running. Event_MotorY // Y-axis motor movement event, indicating that the Y-axis motor has finished running. Event_EncoderZ // Encoder Z-phase interruption event, indicating that the motor has completed one revolution. Event_Limit // Limit interruption event, indicating that the embroidery frame has exceeded the limit. Event creation is implemented using the CreateEvent() function, and the event must be initialized after creation. 3.2.2 Interrupt handling in motion control system In motion control system, interrupt handling is an important part. Event creation is also for interrupt handling, and interrupt response is implemented based on event triggering. The configuration of interrupt source is operated by OAL (OEM adaptation layer) in Windows CE [3][5]. OAL maps physical interrupt number to logical interrupt number and associates it with specific event. The implementation method is as follows: (1) Request a logical interrupt number of IRQ_EINT8 for g_Count1sysint: KernelIoControl (IOCTL_HAL_REQUEST_SYSINTR, &IRQ_EINT8, sizeof(UINT32), &g_Count1sysint, sizeof(UINT32), NULL); (2) Associate the logical interrupt number g_Count1sysint with the event Event_MotorX: InterruptInitialize(g_Count1sysint, Event_MotorX, 0, 0); The same operation is performed to request logical interrupt numbers and associate events with other physical interrupt numbers. The relationship between physical interrupts, logical interrupts, events and threads is shown in Figure 2. Each event corresponds to an interrupt response in the system. When an event is triggered, it is processed according to the event type and time. The interrupt handling thread is the key to driver programming, and its efficiency is directly related to the real-time performance of the system. 3.2.3 Implementation of Thread Communication The implementation of the motion control system software must be closely integrated with the mechanical characteristics of the servo motor and the working principle of each motor in the embroidery machine. The entire program revolves around how the main spindle motor can communicate and cooperate with other modules during one revolution. This mainly includes the stage where the motor can move between 220° and 100° (approximately 240°) as a stepper motor and the stage where the stepper motor is prohibited between 100° and 220° (approximately 120°). The relevant interrupt handling in the two stages is responded to by setting event bits to achieve synchronization between the threads. In the entire system, the spindle motor operates as the main thread of the software. During its execution, it uses interrupt events to wait for, notify, and call other threads to complete the embroidery operation. The flowchart of the spindle motor thread is shown in Figure 3, and the flowchart of the stepper motor thread is shown in Figure 4. The spindle motor thread determines the movement modes such as thread cutting, color changing, skipping stitches, and embroidery based on the control codes in the pattern file. When in normal embroidery mode, the spindle motor thread is in a blocked state and can only move after the Event_MotorX and Event_MotorY events are set. During the movement of the spindle motor, because the photoelectric encoder thread has a higher priority than the spindle motor thread, it can respond to A... When the encoder interrupts, Event_EncoderA(100°) and Event_EncoderA(220°) are set. This triggers a stepper motor thread with a higher priority than the spindle motor thread, completing the 220° to 100° movement phase and disabling stepper motor operation between 100° and 220°. Afterward, the stepper motor thread initializes Event_EncoderA(100°) and Event_EncoderA(220°), sets Event_MotorX and Event_MotorY to notify the spindle motor thread to run, while the stepper motor thread returns to a blocked state, waiting for the Event_EncoderA(100°) and Event_EncoderA(220°) events to be set. At this point, the embroidery machine has completed one stitch. During stepper motor operation, if the embroidery frame goes out of bounds, the motion control system will respond with an interrupt, setting Event_Limit, executing a high-priority limit violation thread, and triggering an alarm. During the operation of the spindle motor, the system will also respond to the disconnection detection interrupt; if a disconnection occurs, an alarm will be triggered. 4. Experimental Testing This article utilizes the Windows CE5.0 multi-threading mechanism to implement the motion control system function of the computerized embroidery machine. Under this system, the integrated system has relatively low overhead in control, scheduling, communication, and synchronization. Combined with interrupts, it effectively meets the system's strong real-time requirements. This solution has been applied to a self-developed high-speed industrial embroidery machine. During the experiment, we observed that the embroidery machine starts quickly during normal operation, runs smoothly and reliably at a high speed of 1200 rpm with low noise, and can stop precisely. During the embroidery process, the various functions execute harmoniously, and the embroidery quality and efficiency are greatly improved. All aspects of the system's performance met the expected goals. 5. Conclusion The innovation of this paper lies in combining the multi-threading mechanism of Windows CE5.0 with hardware interrupt technology in the motion control system of an embroidery machine with strong real-time requirements. This achieves its intended functions with minimal computational resource consumption, meeting the system's real-time requirements while avoiding resource waste and improving the system software's operating efficiency. Tests show that the embroidery machine exhibits significant improvements in response speed, control accuracy, and noise reduction during high-speed operation, demonstrating high engineering value. References [1] Su Jing. 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. Practical development technology of Windows CE [M]. Beijing: Electronic Industry Press, 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-threading technology [J]. Microcomputer Information, 2007, 6-2: 243-245. [5] Huang Dan, Shao Huihe. Multi-threaded programming based on Windows CE platform [J]. Microcomputer Information, 2007, 12-2: 53-55. Implementation of motion control of embroidery machine under WinCE multi-threading
Read next

CAN Interface Design of Smart Instruments

Abstract: Currently, there are more than a dozen types of fieldbuses, each with different specifications and applicable ...

Articles 2026-02-22
CATDOLL Cici Hard Silicone Head

CATDOLL Cici Hard Silicone Head

Articles
2026-02-22
CATDOLL 108CM Coco

CATDOLL 108CM Coco

Articles
2026-02-22