Using PLC to achieve rapid and precise positioning of stepper motors
2026-04-06 06:06:34··#1
Abstract: Based on the introduction of the speed regulation principle and the method of rapid and accurate positioning of stepper motors, this paper proposes a method to realize the position control function of stepper motors using the high-speed pulse output of a PLC. The control scheme and software implementation method for accurate positioning are given. Keywords:Stepper motor, PLC, Position control, S7-200, Accuracy 0 IntroductionA stepper motor is an actuator that converts electrical pulses into angular displacement. When the stepper driver receives a pulse signal, it drives the stepper motor to rotate a fixed angle (called the "step angle") in a set direction. The rotation proceeds at a fixed angle. The angular displacement can be controlled by controlling the number of pulses to achieve accurate positioning; simultaneously, the speed and acceleration of the motor can be controlled by controlling the pulse frequency to achieve speed regulation. Stepper motors, as a special type of motor used for control, are widely used in various open-loop control systems due to their lack of accumulated error (100% accuracy). Programmable Logic Controllers (PLCs) are industrial control computers designed specifically for industrial environments. They possess significant advantages such as strong anti-interference capabilities, extremely high reliability, and small size, making them ideal control devices for achieving mechatronics integration. Through in-depth research on stepper motor positioning and Siemens PLCs, this paper proposes insights and methods for realizing stepper motor position control using the high-speed pulse output of a PLC. It introduces the stepper motor acceleration and deceleration control principle and the method for achieving rapid and accurate stepper motor positioning using a PLC. A position control system scheme and software design ideas are presented, and the system has been successfully tested in the laboratory. This has high application and reference value for achieving accurate positioning control of related stepper motors in industrial and mining enterprises. 1 Positioning Principle and Scheme 1.1 Stepper Motor Acceleration and Deceleration Control Principle When a stepper motor drives an actuator to move from one position to another, it undergoes acceleration, constant speed, and deceleration processes. When the operating frequency of a stepper motor is lower than its starting frequency, it can be started directly at the operating frequency and run at that frequency. When stopping, it can be reduced directly from the operating frequency to zero speed. When the stepper motor's operating frequency fb > fa (the starting frequency under load), starting directly at the fb frequency will cause the stepper motor to lose steps or even stall. Similarly, when suddenly stopping at the fb frequency, the stepper motor will overshoot due to inertia, affecting positioning accuracy. If the acceleration and deceleration are very slow, although the stepper motor will not experience step loss or overshoot, it will affect the working efficiency of the actuator. Therefore, the acceleration and deceleration of the stepper motor must ensure that it moves to the designated position at the fastest speed (or in the shortest time) without losing steps or overshooting. There are two commonly used stepper motor acceleration and deceleration control methods: linear acceleration and deceleration (Figure 1) and exponential curve acceleration and deceleration (Figure 2). The exponential curve method has strong tracking ability, but its balance is poor when the speed changes significantly. The linear method has good stability and is suitable for rapid positioning with large speed changes. The method of constant acceleration for both lifting and lowering is simple and straightforward, and relatively easy to implement in software; this is the method adopted in this paper. 1.2 Positioning Scheme To ensure the positioning accuracy of the system, the pulse equivalent (the distance moved by the stepper motor in one step angle) cannot be too large, and the acceleration and deceleration of the stepper motor must be slow to prevent step loss or overshoot. However, these two factors combined bring a prominent problem: the positioning time is too long, affecting the working efficiency of the actuator. Therefore, to obtain high positioning speed while ensuring positioning accuracy, the entire positioning process can be divided into two stages: coarse positioning and fine positioning. In the coarse positioning stage, a larger pulse equivalent is used, such as 0.1 mm/step or 1 mm/step, or even higher. In the fine positioning stage, to ensure positioning accuracy, a smaller pulse equivalent is used, such as 0.01 mm/step. Although the pulse equivalent is smaller, the positioning speed is not affected because the fine positioning stroke is very short (approximately one-fiftieth of the total stroke). To achieve this, mechanically, different speed-changing mechanisms can be used. Industrial machine tool control plays a crucial role in industrial automation control, and positioning drilling is a common step. Suppose the tool or worktable wants to move from point A to point C. Given AC = 200mm, AC is divided into two segments, AB = 196mm and BC = 4mm. Segment AB is the coarse positioning stroke, using a pulse equivalent of 0.1mm/step to move rapidly according to the linear frequency increase/decrease law. Segment BC is the fine positioning stroke, using a pulse equivalent of 0.01mm/step, with low-frequency constant speed movement at point B to complete precise positioning. Simultaneously with the transition from coarse to fine positioning, the PLC automatically changes the speed change mechanism. 2. Positioning Program Design 2.1 PLC Pulse Output Instructions Currently, advanced PLCs not only have basic logic instructions that meet the requirements of sequential control but also provide rich functional instructions. The Siemens S7-200 series PLC's PLUS instruction outputs PTO or PWM high-speed pulses in Q0.0 and Q0.1, with a maximum output frequency of 20kHz. Pulse Train Toggle (PTO) provides a square wave output (50% duty cycle), with user-controlled cycle and pulse count. Pulse Width Modulated (PWM) provides continuous, variable duty cycle output, with user-controlled cycle and pulse width. This paper uses a multi-segment pipeline PTO for coarse positioning and a single-segment pipeline PTO for fine positioning, as shown in Figure 3. [align=center] Figure 3 Stepper Motor Positioning Process Diagram[/align] In the above example, it is assumed that the motor's starting and ending frequencies are 2kHz, and the maximum pulse frequency is 10kHz. In the coarse positioning process, 200 pulses are used to accelerate the frequency increase, and 400 pulses are used to decelerate the frequency decrease. When using the PLC's PTO multi-segment pipeline pulse output, the pulse increment value during the frequency increase and decrease process is calculated using the following formula. Period increment of a given segment = (ECT - ICT) / Q Where: ECT = End period time of the segment ICT = Initial period time of the segment Using this formula, the period increment of the acceleration part (segment 1) is 2, and the period increment of the deceleration part (segment 3) is 1. Since the second segment is a constant-speed section, the period increment is 0. If the envelope table of PTO is stored starting from VB500, then Table 1 contains the envelope table values from the example above. [align=center]Table 1 Envelope Table Values for Coarse Positioning PTO Multi-Segment Pipeline[/align] 2.2 Source Program //Main Program LD SM0.1 //First scan is 1 R Q0.0, 1 //Reset image register bits CALL 0 //Call subroutine 0 to initialize coarse positioning parameters LD M0.0 //Coarse positioning complete R Q0.0, 1 CALL 1 //Call subroutine 1 to initialize fine positioning parameters //Subroutine 0, coarse positioning LD SM0.0 MOVB 16#A0, SMB67 //Set control word: enable PTO operation, select ms increment, select multi-segment operation MOVW 500, SMB168 //Specify envelope table start address as V500 MOVB 3, VB500 //Set the number of envelope table segments to 3 MOVW 500, VW501 //Set the initial period of the first segment to 500ms MOVW -2, VD503 //Set the period increment of the first segment to -2ms MOVD 200, VD505 // Set the number of pulses in the first segment to 200 MOVW 100, VW509 // Set the initial period of the second segment to 100ms MOVW 0, VD511 // Set the period increment of the second segment to 0ms MOVD 1360, VD513 // Set the number of pulses in the second segment to 1360 MOVW 100, VW517 // Set the initial period of the third segment to 100ms MOVW 1, VD519 // Set the period increment of the third segment to 1ms MOVD 400, VD521 // Set the number of pulses in the third segment to 400 ATCH 2, 19 // Define interrupt routine 2 to handle PTO completion interrupt ENI // Enable interrupt PLS 0 // Start PTO operation // Subroutine 1, fine positioning LD SM0.0 // Initial scan is 1 MOVB 16#8D, SMB67 // Enable PTO function, select ms increment, set pulse number and period MOVW 500, SMW68 // Set the fine positioning cycle to 500ms MOVD 400, SMD72 // Set the number of pulses to 400 ATCH 3, 19 // Define interrupt program 3 to handle PTO completion interrupt ENI // Enable interrupt PLS 0 // Start PTO operation // Interrupt program 2 LD SM0.0 // Always 1 = M0.0 // Start fine positioning // Interrupt program 3 LD SM0.0 // Always 1 = M0.1 // Implement other functions 3 Conclusion Practice has proven that the method of using PLC to control stepper motors to achieve fast and accurate positioning proposed in this paper is feasible. It has practical and reference value in the fields of CNC machine tools, material metering, printing, film feeding and packaging, etc., where stepper motors are used for positioning control. References [1] Sun Jianzhong, Bai Fengxian. Special motors and their control [M]. Beijing: China Water Resources and Hydropower Press, 2005: P147-178 [2] Wang Yulin, Wang Qiang. Speed regulation method of stepper motor. Motor and Control Application [J], 2006, 33(1): P53-57 [3] SMATIC S7-200 Programmable Controller System Manual P9.35-P9.50, P9.126-P9.134