An Optimization Scheme and Circuit for Driving a Stepper Motor with the Index Control Mode

An optimized control scheme for driving a stepper motor with the index control mode is proposed and analyzed in this paper to control the stepper motor more accurately and effectively. Based on the built-in five-digit digital-to-analog signal converter (DAC), six stepper motor operating modes, namely 1/32 micro steps, 1/16 micro steps, 1/8 micro steps, 1/4 step, 1/2 step, and full step, can be selected. Only four control ports are required for switching of operating mode and motor steering. The simulation results show the optimized circuit can output accurate current signals to control the stepper motor.


Introduction
With the increasing prominence of global energy consumption and environmental problems, electric vehicles, as a clean, efficient, and environmentally friendly means of transportation, gradually replacing traditional fuel vehicles [1][2].Stepper motor control systems are mainly composed of microcontrollers and drivers.The traditional method is that the microcontroller modulates and outputs the PWM signal by sampling and analyzing the signal.Finally, the driver drives the H bridge to control the stepper motor in the way of constant voltage or constant current.The stepper motor is controlled by modulating the PWM signal, which takes up a lot of resources and signal ports of the microcontroller.Therefore, it is difficult for stepper motors to achieve micro-step control.
Although the method in [10] does not occupy too many resources of the microcontroller, it uses too many switches of the transmission gate.When the transmission gate is closed, it is in a state of high resistance, which is connected to a bus.Therefore, not only will crosstalk occur but also mistakenly touching will occur too, when the ground interference is large, resulting in logic disorder.In this paper, an optimization scheme with fewer resources and strong logic is proposed for the control module of the stepper motor, and the precision control can reach 1/32 subdivision.

Logic control circuit description
Figure 1 shows the stepper motor control circuit.The movement and direction of the stepper motor are controlled by the step and dir pins, and the M1 and M0 pins are used to switch the subdivision mode of the motor, which controls the rotation angle of the stepper motor.The control system only needs to control the above four ports to achieve full control of the stepper motor, which greatly reduces resource occupation.The index module designed in this paper contains a five-digit R-2R structure DAC and a five-digit counter that can be increased, decreased, and switched bits.When the rising edge of each step signal arrives, the counter controls the increment or decrement count according to the signal at the dir pin, and the number of bits at the output according to the signal at the M1 and M0 pins.When the signal of the dir pin does not change, the counting direction can also be changed automatically according to the size of the winding current.The DAC sends the corresponding value according to the output of the counter to the current comparator, which generates the PWM signal to regulate the stepper motor winding current by controlling the switch of the H bridge, to achieve the purpose of controlling the motor rotation angle.

Indexer circuit design
The core of the optimization scheme proposed in this paper is the indexer module.Its main structure includes a five-digit counter with increasing, decreasing, and switchable bits and a five-digit R-2R structure DAC, which can be used together with other logic circuits to realize the normal operation of the stepping motor.The functional circuit of the indexer is shown in Figure 2, the subdivision mode is controlled by the output of the mode detector, and the module outputs six control signals according to the states of M0 and M1 pins to determine the subdivision mode of the stepper motor.The details are shown in Table 1 Since M0 has a high resistance state input in addition to the logic high and low-level input, the module also contains a high-impedance state identification function, which is shown in Figure 3.
If the status of the input port is in high resistance, the current cannot pass through the resistor R1, which makes both comparator outputs become zero, and the output is the logic high level through the NOR gate.If the input signal is logically high or low, the output of the NOR gate will be logically low.
The counter module is shown in Figure 4. To achieve an incremental count, for the lowest position, let it simply flip the level with the stepping signal.For other count bits that are higher, if all count bits lower than them are high level, the level will be flipped when the step signal arrives.To achieve a decreasing count, the lowest count is the same as the increasing count.For other higher-count bits, if the lower-count bits are all low-level, the level will be flipped when the stepping signal arrives.To realize the subdivision mode switch, it is actually to switch each count bit to the corresponding register, so that the counting of the switching mode at the same time still starts from the switching mode, to ensure the smooth operation of the stepper motor.The output needs to be fed back to the input for the next operation, so the feedback also needs to switch the input count bit.

Direction control circuits design
In a rotation cycle, the motor winding current will change from small to large and from large to small twice.During this period, if the signal of the control direction DIR pin is not changed, the indexer will need to change the direction automatically, that is, the counter increasing or decreasing mode is changed to guarantee proper operation of the stepper motor.The simulation results of changing direction automatically are shown in Figure 5.

Digital-to-analog converter (DAC) circuit design
The DAC structure is shown in Figure 6, consisting of resistance values R and 2R and a single pole double throw transmission gate forming a repetitive cascade structure.The five-digit output of the counter controls the required voltage of the DAC, which provides a reference voltage for the current limiting comparator, thus achieving the purpose of controlling the current.When switching the subdivision mode, we simply set the unwanted bit of gate input to the logic low level.This kind of structure only needs R and 2R resistors, which can not only greatly reduce the influence of resistance mismatch, but also reduce the difficulty of the layout.It is relatively easy to produce equivalent matching resistors, so the precision of the circuit is improved.Figure 6.The circuit structure of a digital-to-analog converter

Simulation verification and result analysis
All power supplies in the simulation are 3.3 V, transient simulation is performed for different subdivision modes, the entire simulation time is set to 100 ms, the cycle of the step signal is set to 1 ms, the power supply power-up time is 100 us, and the reset time is 50 us after power-on.Through the simulation results, it is determined whether the indexer can output according to different subdivision modes.The simulation results of all subdivision modes are as follows: The simulation results of the indexer set to the full step mode are shown in Figure 7.The winding current of the stepper motor in full-step mode will not change, so the current direction can be changed when the motor's running direction changes.
The simulation results of the indexer set to 1/2 step mode are shown in Figure 8.   From Figure 8 to Figure 12, it can be seen that the indexer can automatically output the H-bridge control signal under different subdivision modes.The indexer can automatically flip the direction when the counter is increased to the highest count or decreased to the lowest count, and the indexer can still flip the direction when the DIR signal changes in any state.

Conclusion
The stepper motor control optimization scheme and its implemented circuit are proposed in this article and can be applied to most two-phase stepper motor control.Compared with the control method in [3][4][5][6][7][8][9], there are fewer I/O ports for control operation, and the microcontroller resources are less occupied, resulting in significantly reduced cost for the operation of the microcontroller while the motor control is completed.In [10], the counter is fully realized by a logic gate circuit, which has a strong logic control.In addition, crosstalk and mistakenly touching will not occur when the ground interference is strong, so it has a strong anti-interference ability.Therefore, the control method and realization circuit designed in this paper has a wider application prospect.

Figure 2 .
Figure 2. Functional circuit of indexer Figure 3. High resistance state identification circuit

Figure 5 .
Figure 5. Changes in motor current

Figure 7 .
Figure 7. Full-step mode Figure 8. 1/2 step mode The simulation results of the indexer set to 1/4 step mode are shown in Figure 9.The simulation results of the indexer set to 1/8 micro steps mode are shown in Figure 10.

Figure 9 . 1 /
Figure 9. 1/4 step mode Figure 10.1/8 micro steps mode The simulation results of the indexer set to 1/16 micro steps mode are shown in Figure 11.The simulation results of the indexer set to 1/32 micro steps mode are shown in Figure 12.