How to Program a Stepper Motor Controller

by GreenPAK™ in Circuits > Electronics

28 Views, 0 Favorites, 0 Comments

How to Program a Stepper Motor Controller

cover.jpg

Stepper motors are among the most widely used actuators for high precision motion. They are used in routing systems, 3D printers, robots, etc.

For similar applications, servo motors were used in the past; but today, compared to stepper motors, they have higher costs and complexity because of the additional components needed to make them (position sensors and error amplifiers, etc.). This is why today, the ideal choice is often a stepper motor because it’s simpler to control and it has good accuracy, good torque, moderate speed, and a low cost.

A stepper motor-based application needs two more components:

  • Controller: This is an IC capable of generating step pulses continuously for the driver to make the motor rotate.
  • Driver: It is the interface between the controller’s step signals and the necessary current for the motor windings. There are various types of drivers; a frequently used one is the H-bridge.

There are several ways to implement a stepper motor controller. One of them is by using a microcontroller. In such a scenario, the user has to program his own firmware to control the speed and direction. Generally, a dedicated microcontroller is used as the main controller because generating step pulses is a continuous task.

Another way to control the stepper motor is by using a dedicated standalone integrated circuit (IC). There are several different brands of commercial ICs that implement the step pulses based on an external clock and control signals. In such a case, the user has to configure the direction of motion and has to provide a clock signal.

For the most common applications, microcontroller-based solutions are more expensive and complex because the user must also include all the external components such as crystal, resistors, transistors, diodes, and decoupling capacitors to run the firmware. The commercial IC, instead, is designed to do the same task without the need to program anything.

In this Instructable, an SLG46531V will be configured to run as a commercial IC controller. The step pulses will be generated based on the external signals which set the direction of the motion. Also, the user will have the ability to enable or disable the motion externally and there will be a need to provide an external clock to define the speed of motion.

Below we described steps needed to understand how the solution has been programmed to design a stepper motor driver. However, if you just want to get the result of programming, download GreenPAK™ Designer Software, a part of the Go Configure™ Software Hub, to view the already completed GreenPAK Design File. Plug the GreenPAK Development Kit to your computer and hit the program to design the solution.

Stepper Motor Description

1.PNG
2.PNG

A stepper motor is called so because the rotor moves with discrete steps, instead of rotating continuously like a conventional motor. There are two basic winding arrangements for the motor coils in a two-phase stepper motor (the traditional ones): Unipolar and bipolar.

A unipolar stepper motor has singular winding with a center tap per phase. On each section of the winding, a unidirectional flow current can be used to determine the direction of the magnetic field. In Figure 1, a schematic can be seen. To rotate, the user must apply sequential current with the correct direction to each half of the winding.

A bipolar stepper motor has a single winding per phase. The current in the winding needs to be reversed in order to reverse a magnetic pole for rotating the rotor. In Figure 2, another schematic can be seen. To rotate, the user must apply current to each winding sequentially, inverting the flow current direction in each step.

In this Instructable, we will use a bipolar stepper motor, since the current flows across the entire coil, and they have more torque. If a unipolar stepper motor is to be used, slight modifications will have to be done to the driver circuit; the controller, however, can be used without modifications.

There are three typical ways of controlling the winding current steps in a bipolar motor.

The Full Step method is the usual method for driving the motor. The two phases are always energized (with the corresponding current direction) ensuring that the rotor always aligns itself between the two pole positions. This way, the motor will provide its maximum torque.

The Wave Drive method energizes only one phase at a time. It has the same number of steps as the full step drive, but the motor will have significantly lesser torque. It is, thus, rarely used.

The Half Step method energizes one phase, then two, then one, and so on.

This ensures that the motor moves with half-step increments. With this method, the angular resolution gets incremented but the torque is considerably lesser when compared with that of the Full Step method.

One of the parameters of a stepper motor is the step angle per revolution. It indicates how many steps need to be done to make a revolution of the motor; this, in turn, defines how many times the sequence of the driving method has to be repeated for a given distance.

To interface the step pulses with the motor, an H-bridge is used to provide the current. There are several commercial H-Bridge integrated circuits or we can implement it using GreenPAK ICs.

This Instructable will implement the Full Step method and the Half Step method so the user may be able to select one of them with input from the controller.

Logic Description and Schematic Diagram

3.PNG
table1.PNG
4.PNG
5.PNG

The design implemented in this Instructable can be described with the schematic shown in Figure 3.

The inputs and outputs of the system along with the simplified schematics of the H-Bridges can be seen in Figure 3. The inputs and outputs are described in Table 1.

The H-bridge shown in Figure 3 is a simplified schematic of the circuit. Each bridge controls the current of one phase of the stepper motor, so in this case two H-Bridges will be needed.

The implemented controller generates step pulses at the outputs A, B, C and D if the enable signal is set to high. In this case, signals OFF 1 and OFF 2 are both set to a high level and the sequence of steps is generated depending on the level of signal A/C. If A/C is low, the sequence for an anticlockwise motion is generated, but if it is high, the sequence for a clockwise motion is generated.

Also, the sequence depends on the selected method. If H/F is low, the half-step sequence is generated and if H/F is high, the full-step sequence is generated. For changing the direction or the method, it’s recommendable to disable the motion first.

When the motion is disabled, the signals A, B, C, D, OFF 1, and OFF 2 are set to a low level.

In Figure 4, the step pulses’ sequence for the Half Step method is shown.

In Figure 5, the step pulses’ sequence for the Full Step method is shown.

To implement the sequence, a sequential signal generator with the ASM module of the GreenPAK will be used.

Implementation

6.PNG
7.PNG
8.png
8.png
10.png
11.png
12.png

As described earlier, a stepper motor motion is based on a sequence of steps. To implement it, the Asynchronous State Machine module of SLG46531V is used.

The ASM module is configured for the largest sequence (half step method), as it can be seen in Figure 6. There are 8 states; one for every step.

The ASM is a linear sequencer that can go from State 0 to State 7 or from State 7 to State 0 for implementing clockwise or anticlockwise motion.

In Figure 7, the ASM output configuration is shown.

A, B, C, and D are configured with the corresponding values of the outputs of the system for the Half Step Method; so in the case of this method, the GreenPak outputs copy these values.

Ao, Bo, Co, and Do are bit flags for the Full Step Method. Because in this method both coils are always energized, these bits indicate the output that has to be high in the steps, corresponding to the one energized coil of Half Step method.

These flags are used later in the output logic. The clock control module can be seen in Figure 8, with 4-bit LUT1 configuration in Figure 9.

The transition between the ASM states is controlled by the 4-bit LUT1 output and the 2-bit LUTs.

To change from an even state to an odd state, the output of the 4-bit LUT1 must be low. To change from an odd state to an even state, the output of the 4-bit LUT1 must be high.

To implement this, in the case of Half Step method (H/F input in a low state), the clock input is connected to the DFF4, which is configured as a T-type FF. The 4-bit LUT1 copies the output of the FF (this is defined by the H/F connected to IN2).

In the case of Full Step method (H/F input in a high state), the clock is directly copied by the 4-bit LUT1. With this logic, the ASM in the Half Step method changes its state on every rising edge of the clock (each rising edge is a DFF4 output transition from either low to high or from high to low).

In the Full Step Method, the ASM changes its state on both edges of the clock, so each motor’s step (each clock cycle) corresponds to two states of the ASM. 2-bit LUT0, LUT1, LUT2, and LUT3 determines whether the transition is to be made to the next state or to the previous state, depending on the direction of the motion selected by the pin A/C.

The output module can be seen in Figure 10, with a 4-bit LUT0 configuration in Figure 11.

The logic of each output depends on the corresponding pin’s ASM output (A), the corresponding ASM flag output (Ao), the enable signal and the motion direction signal. If the Half Step method is selected, the pin copies the pin output of the ASM. If the Full Step method is selected, the pin is high when the corresponding ASM output is high or when the corresponding ASM flag output is high. In this way, the output is high in two states of the same step.

In other words, considering that the ASM changes to another state on both edges of clock and that every full step corresponds to two states of the ASM, a full step is done on every rising edge of the clock.

For outputs B, C, and D, the same logic is used but is implemented with two 3-bit LUTs because GreenPAK doesn’t have more 4-bit LUTs.

All the outputs and the clock module also depend on the Enable signal. The Enable signal determines whether the output signal of the modules is always low (when the user disables the controller) or whether the outputs are enabled.

Also, this input is copied to OFF 1 and OFF 2 outputs. The entire implementation is shown in Figure 12.

Tests and Conclusion

13.PNG
14.PNG

To test the implementation signals Clock, A, B, C, and D were registered (in this order) with a logic analyzer.

The half-step method outputs can be seen in Figure 13 and the Full Step method outputs can be seen in Figure 14.

In this Instructable, a stepper motor controller was implemented using SLG46531V. The user must set the direction and the controlling method and must also provide a clock to make the motor rotate.

Steps are done on every rising edge of the clock and the outputs are designed to control the driver circuit of the motor coils. With this implementation, the user only has to provide a clock signal without any other external circuit or controlled logic to generate step pulses.