Share this

Stepper motor program control

2026-04-06 07:22:38 · · #1
Abstract: Stepper motors have the characteristics of simple control and accurate positioning. With the development of science and technology, they are widely used in many fields. In view of the poor portability of traditional pulse systems, this paper proposes a microcomputer control system to replace the pulse generator and pulse distributor, and uses software to generate control pulses. Through software programming, the speed, rotation angle, number of rotations and the operating state of the stepper motor can be set arbitrarily. This simplifies the control circuit, reduces production costs, and improves the operating efficiency and flexibility of the system. On this basis, a hard interface circuit, program flowchart and assembly program for the program control of a double three-beat stepper motor are proposed. Keywords: stepper motor; microcontroller; hardware interface circuit; assembly language Stepper motors are commonly used execution components in automatic control systems. The input signal of a stepper motor is a pulse current, which can convert the input pulse signal into a step-type angular displacement or linear displacement. Therefore, a stepper motor can be regarded as a serial digital-to-analog converter. Since stepper motors can directly accept digital signals without digital-to-analog conversion, it is very convenient to use a microcomputer to control stepper motors [1]. Stepper motors have the following advantages: (1) They can usually control position and speed without feedback; (2) Position errors do not accumulate; (3) They are compatible with array devices and can directly receive digital signals; (4) They can start and stop quickly. There are many types and specifications of stepper motors. According to their structure and working principle, they can be divided into four main types: reluctance motors (also known as reactive or variable reluctance motors), hybrid motors, permanent magnet motors, and special motors. Stepper motors can accurately position themselves without displacement sensors, so they are widely used in precision positioning systems. Currently, stepper motors are used in typewriters, computer peripherals, CNC machine tools, fax machines, and other equipment. With the development of electronic computer technology, stepper motors will surely play their role in convenient and accurate control and achieve wider application in fields such as industrial control. 1. Working principle of stepper motors Taking the reluctance stepper motor as an example, the working principle of stepper motors is introduced. Figure 1.1 is a schematic diagram of the working principle of the reluctance stepper motor. It has six poles on the stator and four poles on the rotor. Three sets of windings are wound on the stator poles, each set consisting of two coils connected in series. One set of windings is called a phase. Therefore, the motor shown in Figure 1.1 is a three-phase stepper motor. The DC power supply drives the current to flow through the windings wound on the stator through switches I, II and III. In state (1), switch I is closed and phase A is energized. Due to the excitation of the phase A winding, a magnetic field appears in the air gap as shown by the arrow. The two stator poles and two rotor teeth on phase A are aligned, and the rotor is in a balanced state. If switch R is closed again to excite phase B, as shown in state (2), the stator poles of phase B generate a magnetic field in the same way. Under the tension of the magnetic lines of force, a counterclockwise torque is generated. Thus, the rotor rotates counterclockwise by a fixed angle and reaches state (3). In the figure, the angle rotated is 15°. If switch I is now opened to remove the excitation of phase A, the rotor will rotate another 15° and reach state (4). Therefore, the angular position of the rotor can be controlled by this switching method. If the switch is switched in a certain timing sequence, the rotor can rotate continuously in a stepping motion; if the speed of the timing switch is further adjustable, the average speed can also be controlled by this switching method. [align=center] Figure 1.1 Working principle of reluctance stepper motor[/align] In fact, the switch that drives the stepper motor is a transistor, and the switch signal is generated by a digital integrated circuit or microcomputer. As can be seen from the previous introduction, the stepper motor is an actuator that transforms the change of switch excitation into a precise rotor position increment motion [2] [3]. 2. Design of stepper motor program control 2.1 Transmission mode of stepper motor 2.1.1 Three-phase single three-beat working mode In this working mode, the three phases A, B, and C are energized in turn, the current switches three times, the magnetic field rotates once, and the rotor rotates forward by one tooth pitch angle. Therefore, this energizing mode is called three-phase single three-beat working mode. At this time, the step angle θb (degrees) is given by the formula: m ── number of stator phases; z ── number of rotor teeth. 2.1.2 Three-phase six-step operation mode In this operation mode, firstly, phase A is energized, and the rotor teeth are aligned with the stator teeth of phase A. In the second step, phase A continues to be energized, and phase B is simultaneously connected. The magnetic fields established by A and B respectively form a composite magnetic field. At this time, the rotor teeth are not aligned with phase A or phase B, but with the bisector of the angle between the axes of A and B, so that the rotor teeth rotate 1/6 of the tooth pitch, i.e., 1.5°, relative to the stator teeth of phase A. In the third step, phase A is disconnected, and only phase B remains connected. At this time, the magnetic field established by phase B is the same as that in the case of phase B being energized in the single three-step operation. Following this pattern, the windings switch six times in the sequence A—AB—B—BC—C—CA—A (or reverse sequence). For each rotation of the magnetic field, the rotor advances one tooth pitch. Each switch causes the rotor to rotate 1.5°. Therefore, this energizing method is called the three-phase six-phase operating mode. Its step angle θb is: 2.1.3 Double three-phase operating mode. In this mode, two phases are always conducting, and the two-phase windings are under the same voltage, energized in the sequence AB—BC—CA—AB (or vice versa). Therefore, it is called the double three-phase operating mode. With this energizing method, the rotor teeth are positioned at positions equivalent to the three positions after removing the single three-phase control method in the six-phase control mode. Its step angle calculation formula is the same as that for the single three-phase method. From the above analysis, it can be seen that for a reluctance stepper motor to have working capability, the minimum condition is that the stator pole pitch angle cannot be divided by the tooth pitch angle, and the following equation should be satisfied: Further simplification yields the number of teeth z: z = q (mR + k) (2 - 3) Where: m──number of phases; q──number of poles per phase; k──positive integer ≤ (m - 1); R──positive integer, 0, 1, 2, 3. According to the selected number of phases and different number of poles, the number of rotor teeth can be calculated from the above equation. Because three-phase double three-step stepper motors are less prone to step loss and have relatively high control accuracy, this paper controls a three-phase double three-step stepper motor. The stator has three pairs of magnetic poles, and two pairs are energized simultaneously during operation, cyclically driving the rotor to rotate. 2.2 Hardware Interface Circuit Traditional stepper motor control systems use hardware for control. A pulse generator generates a pulse signal with varying frequency, and a pulse distributor converts the direction control signal and the pulse signal into a ring pulse with a certain logical relationship. After being amplified by the drive circuit, it can drive the stepper motor. In this control, the stepper motor pulse hardware circuit generates the pulse. If the system changes or different types of stepper motors are used, the hardware circuit needs to be redesigned, and the system's portability is not good [4] [5]. By replacing the pulse generator and pulse distributor with a microcomputer control system, the speed, rotation angle, number of rotations and the operating state of the stepper motor can be arbitrarily set according to the system needs through software programming. This simplifies the control circuit, reduces production costs, and improves the system's operating efficiency and flexibility. Figure 2.1 is the schematic diagram of the microcontroller control stepper motor interface. [align=center] Figure 2.1 Schematic diagram of the microcontroller control stepper motor interface circuit[/align] 2.3 Pulse Formation To realize the control of the stepper motor, the microcomputer should be able to output control pulses with a certain period. The steps are: first output a high level, delay for a period of time, then input a low level, and then delay again. By changing the length of the delay time, the period of the pulse can be changed. The period of the pulse is determined by the working frequency of the stepper motor [6] [7]. The flowchart of the software to form a circular pulse is shown in Figure 2.2. [align=center] Figure 2.2 Flowchart of the software method to form a pulse sequence [/align] The program is as follows: PULSE: MOV R3, # NUM PUSH A PUSH PSW LOOP: SETB P1.0 ACALL DELAY1 CLR P1.0 ACALL DELAY2 DJNZ R3,LOOP POP PSW POP A RET 2.4 Rotation direction control The rotation direction of the stepper motor is closely related to the energizing sequence and energizing method of the internal windings [8~10]. For the three-phase double three-beat working mode: forward rotation: AB→BC→CA→AB reverse rotation: AB→CA→BC→AB The three-phase double three-beat control model is shown in Table 2.1. (1) Forward rotation control model: (2) Reverse rotation control model 2.5 Speed ​​control The speed control of the stepper motor is actually the frequency of the clock pulse or the commutation period of the control system. That is, during the acceleration process, the output frequency of the pulse is gradually increased; during the deceleration process, the output frequency of the pulse is gradually decreased. The frequency of the pulse signal can be determined by two methods: software delay and hardware interrupt. When using software delay, a subroutine is generally designed according to the required time constant. The subroutine contains certain instructions. The designer must perform rigorous calculations or precise tests on the execution time of these instructions in order to determine whether the delay time meets the requirements. After each delay subroutine ends, the following operation can be performed, or an output signal can be output as a timing output. When using software timing, the CPU is always occupied, so the CPU utilization is low. The programmable hardware timer directly counts the system clock pulse or a clock pulse of a certain fixed frequency, and the count value is determined by programming. When the predetermined number of pulses is counted, an interrupt signal is generated to obtain the required delay time or timing interval. Since the initial value of the count is determined by programming, different timing and counting requirements can be met by changing the program without modifying the hardware, so it is very convenient to use [11-13]. 2.6 Control Program Design The design method of the control program is: to determine the rotation direction of the motor by using the flag bit FLAG, and then output the corresponding control pulse sequence; to determine whether the required pulse signal has been output [14]. The stepper motor control program design completed by the three-phase double three-beat control model is as follows: The flowchart of the three-phase double three-beat control program is shown in Figure 2.3 and Figure 2.4. The forward rotation control models 03H, 06H, and 05H are stored in the memory unit with RM as the starting address, and the reverse rotation control models 03H, 05H, and 06H are stored in the memory unit with LM as the starting address. [align=center] Figure 2.3 Main Program Flowchart Figure 2.4 Timer Interrupt Service Routine Flowchart[/align] The main program is as follows: CON: MOV R3, # N MOV TMOD , # 10H MOV TL1 , # LOW MOV TH1 , # H IGH JNB FLAG ,LEFT MOV R0 , RM AJMP TIME - S LEFT: MOV R0 , LM TIME: SETB EA SETB ET1 SETB TR1 WA IT: SJMP WA IT The interrupt service routine is as follows: INTTO: PUSH A PUSH PSW MOV A , @R0 MOV P1 ,A INC R0 MOV A , # 00H XRL A , @R0 JNZ NEXT MOV A , R0 CLR C SUBB A , # 03H MOV R0 , A NEXT: DJNZ R3 , RETU CLR ET1 CLR EA RETU: POP PSW POP A RETI 3. Summary and Outlook Stepper motors are one of the key components in mechatronics products, and are high-performance digital actuators. With the popularization and deepening of computer application technology, electronic technology, and automatic control technology in various fields of the national economy, the demand for stepper motors is increasing. Data shows that the world's annual production of stepper motors is growing at a rate of over 10%. Domestic demand for stepper motors is also increasing daily. In practical work, many engineers and technicians hope to gain a comprehensive understanding of stepper motors and their control technology. This article discusses the control methods of stepper motors in detail, including the design of hardware interfaces, the design of software schemes, and the writing of assembly control programs. This method is efficient, convenient, and low-cost, and has high practical application value.
Read next

CATDOLL 128CM Dolly (TPE Body with Hard Silicone Head)

Height: 128cm Weight: 19kg Shoulder Width: 30cm Bust/Waist/Hip: 57/52/63cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22