FPGA-based stepper motor sinusoidal microstepping driver design
2026-04-06 07:59:11··#1
1. Introduction A stepper motor is an electromechanical component that converts electrical pulse signals into corresponding angular displacement (or linear displacement). It is widely used in industrial control due to its simple structure, robustness, durability, and reliable operation. However, the discontinuous nature of the pulses causes many shortcomings in stepper motor operation, such as low-frequency oscillation, high noise, low resolution, and poor reliability of the drive system, severely limiting its application range. Microstepping control of stepper motors effectively solves this problem. However, most traditional stepper motor drive systems use a microcontroller as the control chip, supplemented by discrete digital logic circuits and analog circuits. Limited by the microcontroller's operating frequency, the microstepping resolution is not very high, resulting in low control accuracy and less than ideal control performance. With the emergence of high-performance digital signal processors (DSPs), using DSPs as the control core and implementing motor control in software has become a research hotspot. In recent years, the rapid development of programmable logic devices (PLDs) has led to increasingly powerful PLDs, prompting the emergence of highly integrated, high-precision drivers. Therefore, this paper proposes a fully digital stepper motor control system based on SOPC on-chip programmable logic. This system uses an FPGA as the core controller, successfully integrating the drive logic module and controller onto the FPGA. It fully leverages the high-speed parallel processing capability of the hardware logic circuit for digital signals, enabling stepper motor winding current subdivision to reach 4096, with automatic adjustment of the subdivision number. This significantly improves control accuracy and driver integration, while reducing driver size. 2. Stepper Motor Subdivision Drive Principle The subdivision control of a stepper motor essentially controls the current in the stepper motor's excitation winding. In ordinary driving mode, the drive circuit simply "opens" and "closes" the excitation current of the motor winding, causing the stepper motor rotor to rotate in steps according to its own step angle. The stepper motor operates using the electromagnetic force between the stator and rotor magnetic poles. When it operates in a "double-step" state, its positioning position is exactly in the middle of the two electromagnetic poles, achieved by the balance of the electromagnetic attraction between the two poles. Therefore, it can be inferred that if the magnitude of the electromagnetic attraction between the two magnetic poles can be further carefully controlled, the rotor magnetic poles can obtain more balanced positioning positions due to the difference in the electromagnetic attraction between the two phase stator magnetic poles. The microstepping drive method of stepper motors applies this principle. During microstepping, the microstepping controller gradually increases and decreases the current in each phase excitation winding, allowing the rotor to be in multiple magnetic equilibrium states, making the resulting magnetic field inside the motor a uniform circular rotating magnetic field. This achieves the goal of reducing the step angle and refining the motor's rotation. The amplitude of the resulting magnetic field vector determines the magnitude of the motor's rotational torque, and the angle between two adjacent resulting magnetic field vectors determines the step angle. For a three-phase stepper motor, if sinusoidal currents with a phase difference of 2/3π and the same amplitude are applied to windings A, B, and C respectively (Figure 1), the resulting current vector rotates in space with a constant amplitude, and its corresponding resulting magnetic field vector also rotates accordingly, thus forming a rotational torque (Figure 2). Under microstepping drive, the control accuracy of the stepper motor is significantly improved due to the small step angle. Simultaneously, this drive method effectively suppresses noise and oscillations generated during low-speed operation. 3. Overall Controller Design Scheme The current in the three-phase windings of the stepper motor is a sinusoidal stepped current. Variable microstepping can be achieved by changing the number of steps in each change of the given current. The driver's task is to control the winding current, making it change according to the sinusoidal stepped wave pattern. With each step pulse, the current in the A, B, and C phase windings advances one step along the sinusoidal stepped wave, and the motor rotates by one step angle. The main circuit diagram of the stepper motor drive is shown in Figure 3. IA and IB are two Hall elements. Six IGBTs are integrated into the power control module IPM. [align=center] Figure 3 Main Circuit Diagram of Stepper Motor Drive[/align] The block diagram of the stepper motor control system is shown in Figure 4. An FPGA is used as the main control chip, integrating the digital circuitry of the controller and driver onto a single FPGA. To control the winding current, a current-tracking closed-loop feedback is introduced into the design. The feedback current and the given sinusoidal current (discrete sine table) are modulated by an improved proportional-integral (PI) control and then subjected to SPWM modulation, outputting six PWM waves to control the on/off switching of the six IGBTs on the three bridge arms of the drive circuit. If dead time is ignored, the two PWM waves of the upper and lower half-bridges of each bridge arm are complementary; that is, when the upper half-bridge PWM wave is high/low, the lower half-bridge PWM wave is low/high. The system uses a 14-bit wide 200MHz counter to generate the PWM carrier at a frequency of 12.2kHz. All current data is discretized with 14-bit precision. The 200MHz clock is generated by multiplying a 50MHz clock by a PLL. The PWM waves output from the FPGA are amplified by the power module and then control the stepper motor. The stepper motor's operating status (speed and direction) is indicated by LEDs. The stepper motor speed is determined by the lookup table speed; CP determines the lookup table frequency. With a fixed microstepping level, a higher CP speed results in a faster motor speed. If the motor rotates at high speed with high microstepping, the CP pulse frequency will be very high, resulting in an excessively small PWM pulse width. This causes the IGBT control arm of the power module to switch frequently, resulting in a significant increase in switching losses and overheating of the power module. High microstepping does not offer significant advantages when the stepper motor is rotating at high speed. Therefore, without affecting the motor's operating accuracy, the system automatically adjusts the microstepping accuracy between 4096, 2048, 1024, 512, 256, 128, 64, and 32 based on the rotational speed, making the motor run more smoothly and reliably. [align=center] Figure 4 Control System Block Diagram[/align] 3.1 FPGA Structure Design This system adopts a hierarchical development approach, with the top-level module composed of multiple sub-modules. The FPGA design system block diagram is shown in Figure 5. The system consists of a Nios II microprocessor module and a digital logic module. [align=center] Figure 5 FPGA Design System Block Diagram[/align] The controller uses a 32-bit Nios II CPU soft core, generated by SOPC Builder. It is used to receive external control signals, process the signals and send them to the pulse generator, and control the LEDs through the output port to indicate the system's operating status. The system's top-level design diagram is shown in Figure 6. The system consists of a CPU soft core (stepmotor_controller), a CP generator (PatternGenerator), a sine lookup table control module (interface), an A/D current sampling module (currenttop), a C-phase current calculation module (Current_c), an adjustment module, a PI adjustment module (pimodule), and a PWM generation module (PWM). The functions of each module are as follows: CPU: Receives external control signals, processes the signals to obtain the corresponding microstepping level and speed-corresponding control signals, sends them to the CP generator, processes the steering signal and sends it to the lookup table control module, and sends the speed and steering signals to the LED digital tube and light-emitting diode to indicate the motor's operating status; CP generator: Receives speed control signals, emits CP pulses corresponding to the speed, and provides the optimal microstepping level for the corresponding speed; Sine lookup table control module: Generates reference current by performing a lookup based on the CP pulses and microstepping level, and determines the lookup direction based on the steering control signal to achieve steering control; A/D current sampling module: Acquires the A and B phase current values of the stepper motor; C-phase current calculation module: Based on Kirchhoff's current law, the sum of the currents in phases A, B, and C is zero. The C-phase current is calculated from the currents in phases A and B acquired by the A/D converter. PI adjustment module: The difference between the reference sinusoidal current and the feedback current is PI-regulated. To prevent the IGBTs in the upper and lower half-bridges of the IPM from conducting simultaneously, causing a short circuit in the IPM, a dead time is set in the PI module. [align=center] Figure 6 System top-level design diagram[/align] Top-level interface description: AD_in_a and AD_in_b are the digital signals output by the AD1674 converter; AD_CE, AD_RD, and AD_STS are the AD control signals; clk and reset are the system clock input port and system reset port, respectively; the enable port is the PWM generator enable terminal. When the power module temperature is too high, the thermal protection will activate and set enable to 0 to stop PWM wave generation, protecting the driver; setspeet and rotate_dirc are the speed and steering control ports, respectively; led_sel, speeddisplay, and led_indicator are the operating status indicator circuits. pl_a, ph_a, pl_b, ph_b, pl_c, and ph_c are the upper and lower half-bridge control terminals of the A, B, and C three-phase bridge arms; 3.2 Nios II Soft Core Design In this controller, the flexible functions of the CPU are used to receive and process external control signals and then send the processed control signals to various functional modules. Therefore, the Nios II soft core adopts the economical Nios II/e, and adds input/output ports (PIO) and on-chip memory modules. The controller program flowchart and software program workflow are shown in Figure 7. [align=center] Figure 7 CPU Control Flowchart[/align] The CPU internal program is written in C++ and a class is established for the motor control state. By operating on the motor control state object, various control commands can be output to the interface module and CP pulse generation module to control the motor state; at the same time, the user's various inputs are monitored in the main program loop, and the member variables of the motor control state object are updated. 3.3 The CP generator module and the PatternGenerator module generate corresponding CP pulses and the most suitable microstepping level at that speed based on the set motor speed, and transmit these signals to the lookup table control module. The CP generator module and the lookup table control module are shown in Figure 8. [align=center] Figure 8 CP Generator Module and Lookup Table Control Module[/align] The lookup control module (interface) internally instantiates a read-only memory to store a sine wave data table for one cycle. The width of the sine wave table data is consistent with the width of the system data stream, therefore a 14-bit width is chosen. The depth of the sine wave table determines the maximum microstepping level of the driver, expressed as: NMAX = 2N. When N = 12, the highest microstepping level of 4096 microsteps is reached. After external input of CP and CCW signals, the given data of the three-phase phase current can be retrieved by sequentially providing the address data corresponding to the three-phase windings, and the three given data registers are updated simultaneously and sent to the next stage. Direction switching is also implemented in this module. The input CCW signal controls a path selector, controlling the lookup direction of the sine wave table to change the direction of the stepper motor. This module determines the increment size of the address data of the three-phase windings for each step by the input microstepping level signal and the CP pulse signal. When the microstepping level is the highest, the address counter increments or decrements by 1 each time; when it is not at the highest microstepping precision, the address counter increments by a power of 2, where N is determined by the current microstepping level. 3.4 The AD sampling module and the C-phase current calculation module collect the A and B phase currents of the stepper motor through Hall elements. The AD sampling module converts the analog quantities of the A and B phase currents of the motor into digital quantities by collecting the voltage on the sampling resistor. The C-phase current module calculates the current using Kirchhoff's current law ia + ib + ic = 0. Figure 9 shows the ports of the two modules. [align=center] Figure 9 AD sampling module and C-phase current calculation module[/align] 3.5 PI control module The PI control module performs discretization PI control on the given data and feedback data. The data width of the module is uniformly 14 bits, that is, the given data/feedback data/control data are all represented by 14-bit unsigned integer data. This module implements a PI controller function, as shown in Figure 10. [align=center] Figure 10 PI control logic block diagram[/align] The PI control discretization formula is shown in equation (4). I(K) = I(K-1) + KP*(E(K)-E(K-1)) + KI*E(K) (4) Where 1500≤I(K)≤14384, I(0) = 8192, E(K)=IREF-IOUT. After receiving the start signal, the module first registers the given data/feedback data, then performs a signed subtraction on the two with widened sign bits, and starts the KI multiplier to calculate the result of KI multiplied by the error e. The absolute value of the subtraction result is taken and compared with the threshold (constant comparator), and the comparison result is stored in the register. The error increment of e is calculated, i.e., E(K)-E(K-1), and the result of KP multiplied by the error increment is calculated using the KP multiplier. The result calculated by the KI multiplier is first sent to the accumulator, and then the result calculated by the KP multiplier is sent to the accumulator; the accumulator of the module will perform overflow handling and data exceeding the boundary handling each time it accumulates, and will be set to the boundary value (maximum/minimum value) in either case. 3.6 PW The M-generator module converts the data output after PI regulation into a PWM waveform and outputs it to the IGBT module. The IGBT's on/off switching adjusts the phase voltage, thereby changing the phase current according to a given value. The PWM waveform is generated by comparing the given control data and carrier data, determining the high/low level of the PWM waveform based on their magnitudes, thus achieving PWM modulation, as shown in Figure 11. [align=center] Figure 11 Overall Block Diagram of the PWM Module[/align] A sawtooth wave is used as the PWM carrier, with a driving clock frequency of 200MHz and a 14-bit register width. To reduce the carry chain length of the counter, a counter is used, split into a 3-bit counter and an 11-bit counter, reducing combinational logic delay. The dead-time protection generator module outputs the input PWM signal as PH and PL signals based on the given dead-time length data, corresponding to the upper and lower bridge arms of the IGBT, respectively. Dead-time protection is inserted at the rising edge of the PH and PL data (simultaneously set to low level). The inserted dead-time protection is implemented through rising and falling counters, ensuring that the upper and lower bridge arms do not conduct simultaneously. 4 Simulation Results Functional simulation of the PWM module was performed, and the simulation waveform is shown in Figure 12. Analysis shows that the six PWM waves meet the timing and dead-time protection requirements, achieving the design objectives. Enlarging Figure 12 reveals the IGBT dead-time, as shown in Figure 13. [align=center] Figure 15 Current waveform during stepper motor reversal[/align] Experimental results show that the three-phase current phase difference of the stepper motor is 120 degrees, the three-phase current is sinusoidal, the motor runs smoothly, and the reverse phase lookup table is used during motor reversal, resulting in a short response time and small current fluctuations during direction switching. 6 Conclusion This controller uses an Altera FPGA with an embedded Nios II processor soft core to implement sinusoidal variable microstepping control of the stepper motor, greatly improving system reliability and reducing design costs. The control section uses Nios II... The CPU soft core makes system control more convenient and flexible. The CPU and various control modules are integrated into a single FPGA, greatly improving driver integration and reducing driver size. This significantly improves microstepping accuracy, enabling stepper motors to operate at low speeds with a high microstepping of 4096, eliminating the low-frequency oscillation problem inherent in stepper motors, and significantly improving control precision. It has broad application prospects in high-precision CNC machine tools.