PSoC® 3 Stepper Motor Control with Precision Microstepping

作者:Isaac Sever

投稿人:Convergence Promotions LLC


Stepper motors are ideally suited for many measurement and control applications. However, their advantages can only be realized through careful circuit design built around an appropriate MCU.


Stepper motors convert electrical energy into discrete mechanical rotation. They are ideally suited for many measurement and control applications where positional accuracy is important. Stepping motors have the following advantages:
  • Full torque when rotation is stopped. This is in contrast to brushed and brushless DC motors, which cannot provide full torque continuously when the rotor is stopped. This aids in maintaining the current position.
  • Precise open-loop positioning and repetition. Stepper motors move in discrete steps as long as the motor stays under the maximum torque and current limits. This allows the rotor position to be determined by the control sequence without additional tracking or feedback. High quality stepping motors have three to five percent precision within a single step.
  • Quick starts, stop, and reverse capability.
  • High reliability because there is no brush or physical contact required for commutation. The life span of a stepping motor is dependent on the performance of the bearings.
  • Microstepping mode can be used allowing direct connection to a load without intermediate gearing.
  • A wide speed range can be controlled by varying the drive signal timing.
Stepping motors also have some drawbacks:
  • Inherent resonance can cause noise, jerky rotation, and at extreme levels, loss of position.
  • It is possible to lose position control in some situations, because no feedback is natively provided.
  • Power consumption does not decrease to zero, even if load is absent.
  • Stepping motors have low-power density and lower maximum speed compared to brushed and brushless DC motors. Typical loaded maximum operating speeds for stepper motors are around 1000 RPM.
  • Complex electronic controls are required.

Stepper motors are synchronous AC motors, and in the same family as brushless DC (BLDC).

Structure of motors

Figure 1: Structure of motors.

Types of stepping motors

There are several basic types of stepping motors:
  • Variable reluctance motors with metal teeth.
  • Permanent magnet motors.
  • Hybrid motors with both permanent magnets and metal teeth.
Variable reluctance motors

Variable reluctance stepping motors have three to five windings and a common terminal connection, creating several phases on the stator. The rotor is toothed and made of metal, but is not permanently magnetized. A simplified variable reluctance stepping motor is shown in Figure 2. In this figure, the rotor has four teeth and the stator has three independent windings (six phases), creating 30 degree steps.

Simple variable reluctance stepping motor

Figure 2: Simple variable reluctance stepping motor.

The rotation of a variable reluctance stepping motor is produced by energizing individual windings. When a winding is energized, current flows and magnetic poles are created, which attracts the metal teeth of the rotor. The rotor moves one step to align the offset teeth to the energized winding. At this position, the next adjacent windings can be energized to continue rotation to another step, or the current winding can remain energized to hold the motor at its current position. When the phases are turned on sequentially, the rotor rotates continuously.

The described rotation is identical to a typical BLDC motor. The fundamental difference between a stepper and BLDC motor is that the stepper is designed to operate continuously stalled without overheating or damage.

Rotation for a variable reluctance stepping motor with three windings and four rotor teeth is illustrated in Figure 3.

Winding sequence:

1, 2, 3, 1 → 3 steps → quarter turn

12 steps per rotation

As shown in Figure 3, energizing each of the windings in sequence moves the rotor a quarter turn, 12 steps are required for a full rotation.

Table 1: Variable reluctance stepper motor in Figure 3.


The three steps shown in Figure 3 move the rotor a quarter turn. A full rotation requires 12 steps for a variable reluctance stepper motor.

Typical variable reluctance motors have more teeth and use a tooth pole along with a toothed rotor to produce step angles near one degree.

Rotation control

Figure 3: Rotation control of variable reluctance stepping motor.

Permanent magnet stepping motor

A permanent magnet stepping motor consists of a stator with windings and a rotor with permanent magnet poles. Alternate rotor poles have rectilinear forms parallel to the motor axis. Stepping motors with magnetized rotors provide greater flux and torque than motors with variable reluctance. The motor, shown in Figure 4, has three rotor pole pairs and two independent stator windings, creating 30 degree steps.

Motors with permanent magnets are subjected to influence from the back-EMF of the rotor, which limits the maximum speed. Therefore, when high speeds are required, motors with variable reluctance are preferred over motors with permanent magnets.

Permanent magnet stepping motor

Figure 4: Permanent magnet stepping motor.

Rotation of a permanent magnet stepping motor is produced by energizing individual windings in a positive or negative direction. When a winding is energized, a north and south pole are created, depending on the polarity of the current flowing. These generated poles attract the permanent poles of the rotor. The rotor moves one step to align the offset permanent poles to the corresponding energized windings. At this position, the next adjacent windings can be energized to continue rotation to another step, or the current winding can remain energized to hold the motor at its current position. When the phases are turned on sequentially the rotor is continuously rotated.

Rotation for a permanent magnet stepping motor with two windings and three pairs of permanent rotor poles (six poles) is shown in Figure 5.

Winding in sequence:

1 +/-, 2 +/-, 1 -/+, 2 -/+ → 3 steps → quarter turn

12 steps per rotation

Table 2: Permanent magnet stepping motor in Figure 5.


With one winding energized, the three steps move the rotor a quarter turn. A full rotation requires 12 steps for a permanent magnet stepper motor (bipolar) with both windings energized in each step. As shown in Figure 5, energizing each winding in sequence through each polarity moves the rotor a quarter turn. As before, 12 steps are required for a full rotation.

Rotation control of PM stepping motor

Figure 5: Rotation control of permanent magnet stepping motor, sequencing individual windings.

Another alternative to rotate a permanent magnet rotor is to energize both windings in each step. The vector torque generated by each of the coils is additive; this doubles the current flowing in the motor, and increases the torque. More complex control is also required to sequence the turning on and off of both windings.

As shown in Figure 6, energizing two windings in each step, sequencing through each combination of polarities moves the rotor a quarter turn. As before, 12 steps are required for a full rotation.

Table 3: Permanent magnet stepping motor in Figure 6.

Both Windings Rotation control of PM stepping motor

Figure 6: Rotation control of permanent magnet stepping motor using both windings together.

Typical permanent magnet motors have more poles to create smaller steps. To make significantly smaller steps down to one degree, permanent magnet rotors can add metal teeth and toothed windings. This hybrid motor is described in the next section.

Hybrid stepping motor

Hybrid stepping motors combine a permanent magnet and a rotor with metal teeth to provide features of the variable reluctance and permanent magnet motors. Hybrid motors are more expensive than motors with permanent magnets, but they use smaller steps, have greater torque, and have greater maximum speeds.

A hybrid motor rotor has teeth placed on the directional axes. The rotor is divided into parts between constant magnet poles. The number of rotor pole pairs is equal to the number of teeth on one of the rotor’s parts. The hybrid motor stator has teeth creating more poles than just the main poles containing windings. The rotor teeth provide a smaller magnetic circuit resistance in some rotor positions, which improves static and dynamic torque. This is provided by corresponding teeth positioning; some parts of the rotor teeth are placed opposite the stator teeth and the remaining rotor teeth are placed between the stator teeth. Dependence between the number of rotor poles, the stator equivalent poles, and the phase number define step angle:

Hybrid stepping motor

Figure 7: Hybrid stepping motor.

Rotation of a hybrid stepping motor is produced with the same control method as a permanent magnet stepping motor, by energizing individual windings in a positive or negative direction. When a winding is energized, a north and south pole are created, depending on the polarity of the current flowing. These generated poles attract the permanent poles of the rotor and the finer metal rotor teeth. The rotor moves one step to align the offset magnetized rotor teeth to the corresponding energized windings.

Stepping motor control

A step motor is a synchronous electric motor. Its fixed rotor equilibrium position occurs when aligned with the stator magnetic field. When the stator changes position, the rotor rotates to occupy a new equilibrium position.

There are several stepper motor drive modes:
  • Full-step mode.
  • Double-step mode.
  • Half-step mode.
  • Microstep Mode.

Each of these modes controls stepping motor phases in different ways.

Rotation control

Stepping motors can be controlled in a variety of ways, trading off implementation requirements with greater accuracy and smoother transitions. Rotation control with full-steps, half-steps, and microsteps is described as follows:

Full-step mode
Full-step mode for a permanent magnet and hybrid stepping motor is detailed in the Stepper Motor Introduction. Figure 5 illustrates one-phase full-step mode in which only one winding is turned on at a time. In this mode, the rotor’s balanced position for each step is in line with the stator poles. With only half of the motor coils used at a given time, the full torque obtained is limited.

Double-step mode
Two-phase, full-step mode shown in Figure 6 uses both windings energized in each step. This doubles the current through the motor and provides 40 percent more torque than when only one phase is used at a time. With two windings energized, the rotor’s balanced position for each step is halfway between the two energized stator poles.

Half-step mode
The full-step and double-step drive modes can be combined to generate half-steps of rotation for half-step mode. First one winding is turned on, and then the second winding is energized, moving the rotor half a step towards the second, as shown in Figure 8.

A half-step with the combination of one and two windings energized in full-step mode produces higher resolution, but does not provide constant torque throughout rotation.

Three half steps, 1/8 of a rotation

Figure 8: Three half steps, 1/8 of a rotation.

Microstep mode
Microstepping mode is an extension of the half-step drive mode. Instead of switching the current in a winding from on to off, the current is scaled up and down in smaller steps. When two phases are turned on and the current of each phase is not equal, the rotor position is determined by the current phase ratio. This changing current ratio creates discrete steps in the torque exerted on the rotor and results in smaller fractional steps of rotation between each full-step. Microstep mode reduces torque ripple and low-speed resonance present in the other modes and is required in many situations.

Microstepping creates rotation of the rotor by scaling the contributions of the two additive torque vectors from the two stepper motor windings.

Torque in microstepping control mode

Figure 9: Torque in microstepping control mode.

The total torque exerted on the rotor is the vector addition of the torque from the two rotors. Each of the torques is proportional to the position of the rotor and the sine/cosine of the step angle.


These equations can be combined and solved for the position of the rotor.



Fractional steps are created by scaling torque contributions between windings. Because torque is proportional to magnetic flux that is proportional to the current in the winding, the position of the rotor can be controlled by controlling the current flowing in each winding. To create smooth microsteps between full-steps, the current is varied sinusoidally with a 90 degree phase shift between the two windings as shown in Figure 10.

The current is scaled by controlling the root mean square (RMS) current using a current mode buck converter, commonly called a chopper drive when used with stepper motors. The phase current is converted into a voltage using a sense resistor in each phase ground path. This voltage is routed to a comparator that disables the output whenever the phase current rises above a reference. The comparator reference is provided by a voltage digital-to-analog converter (VDAC). By changing the VDAC supplied current limit for each microstep, the total motor torque remains approximately constant for each step of the sinusoidal current waveform.

VDAC current limit for microstep mode

Figure 10: VDAC current limit for microstep mode.

Microstepping allows the rotor position to be controlled with more accuracy and also has advantages in the rotation. Advantages of microstepping are:
  • Position is controlled with more accuracy.
  • Rotation can be stopped at specific fraction of a step.
  • Transitions are smoother.
  • Damp resonance creates fewer oscillations as motor steps (especially at startup and slowdown).
The smoother transitions are shown in Figure 11. The position and transitions vary from ideal calculations due to non-idealities in the system such as resistance losses, static friction, and the approximation of the sinusoidal current limits. Microstep resolutions in excess of 16 may not be noticeable due to motor friction and the effects of mechanical error.

Smooth transitions

Figure 11: Smooth transitions between steps and limited oscillations and settling in microstep mode.

PSoC 3 introduction

The CY8C3866AXI device is in the PSoC 3 architecture. A block diagram of the device is shown in Figure 12 with the blocks used in the stepper application highlighted.

PSoC 3 (CY8C3866AXI) block diagram

Figure 12: PSoC 3 (CY8C3866AXI) block diagram.


Digital subsystem
The PSoC 3 digital subsystem provides unique configurability of functions and interconnects. The stepper motor control uses these digital resources to implement timers, pulse width modulator (PWM) blocks, control registers, and a hardware lookup table (LUT).

Analog subsystem
The PSoC 3 analog subsystem provides the device the second half of its unique configurability. The stepper motor uses dedicated comparators, voltage DACs, and programmable gain amplifiers (PGA).

Stepper motor control based on PSoC 3

The block diagram of the stepper motor control based on the CY8C3866AXI is shown in Figure 13. The PSoC Creator™ schematic is shown in Figure 14.

PSoC 3 stepper motor controller

Figure 13: Block diagram of PSoC 3 stepper motor controller.

Input control signals to the PSoC 3 device are:
  1. Motor Current Sensing: Analog input pins to detect motor phase current on shunt resistor. Used to limit current of the motor phases. See details in the following section.
  2. User Interface Pins
    • User Input: Analog pin to read potentiometer for parameter input. Two digital pins for Menu control buttons.
    • Character LCD: Digital output port (seven pins) to drive the character LCD on the DVK for menu options and user feedback.
Outputs from the PSoC 3 device are power-device driver signals:
  1. PWM signals to the high-side drivers (four digital output pins).
  2. PWM signals to the low-side drivers (four digital output pins).
There are eight total digital output pins used for motor drive.

PSoC Creator schematic

Figure 14: PSoC Creator schematic for stepper motor control.

The PWMs are not used to produce the typical pulse width modulation output used with other motors. Instead, the PWMs act more as a timer to ensure a maximum chopping frequency to avoid overheating the drivers. Additionally, the PWM ‘kill circuit’ natively includes the cycle kill mode that implements the chopper drive method by disabling the drive outputs for the remainder of the current PWM cycle after the comparator trips.

The PWM signals are routed to a look up table (LUT) logic block, along with the current stepping stage index. This logic block implements a LUT using the PLD capabilities of a universal digital block (UDB) and routes the PWM signals to the eight legal output control combinations based on the current polarity of each phase. These control signals are routed through GPIOs to the external power driver circuits that drive the stepper motor. In the demonstrated chopper drive topology, transistors or MOSFETs are typically used to switch the high voltages and currents used to drive the stepper motors. The sequencing of the PWM control signals on the external power drivers produces the step by step rotation of the motor.

A timer generates periodic interrupts that generate each step (or microstep) of the motor. This timer can be used to run the motor at a specific speed, or to a specific position (exact number of steps). To set the speed of the motor, the interrupt period of the timer is updated by firmware.

PSoC 3 also implements current limiting for motor overcurrent protection and microstepping in hardware. This is described in the following section.

Microstepping and current protection implementation

Microstepping limits the current flowing in the motor windings to create smooth and well-controlled transitions between full-steps. This functionality also builds protection in hardware for overcurrent that shields the motor from damage. The block diagram of the system with the current feedback sensing paths is shown in Figure 15.

Overcurrent protection block diagram

Figure 15: Overcurrent protection block diagram for microstepping.

Motor current is measured with two shunt resistors in the ground paths of the power driver MOSFETS (R1 and R2 in Figure 15). This voltage is low-pass filtered on the board and connected to two analog pins on PSoC 3 (labeled Curr_A and Curr_B).

The input voltages are fed into programmable gain amplifiers (PGA) implemented with the analog continuous time (CT) blocks. The PGA buffers the input voltage and drives it to a continuous time comparator. This voltage level from the sense resistor is compared to the current limit, set by an 8-bit voltage DAC. For microstepping the DACs’ output, sine and cosine waveforms are generated from a software lookup table. This limits the motor current sinusoidally for smooth microstepping.

The output of the comparator is connected to the PWM block and kills the PWM output when the current limit threshold is exceeded. This provides cycle-by-cycle current limiting to the motor and creates smooth microstepping transitions. The implementation of the current limiting protection in PSoC Creator is shown in Figure 16.

PSoC Creator schematic

Figure 16: PSoC Creator schematic implementation of current limiting block for microstepping.

The PSoC 3 resources used in current limiting are:
  • Two continuous time (CT) blocks implement the PGAs.
  • Two fixed analog comparators are dedicated analog resources and do not use any SC/CT blocks.
  • Two 8-bit PWMs implemented in UDBs (the same PWMs used to control the power device drivers). The output of the comparator triggers the kill input to the PWM when a current limiting condition is detected.
  • Two 8-bit VDACs. These built in 8-bit voltage DACs are used to set the threshold for the comparator current limit.
The current limits are set to limit the torque generated by each winding and to control the microstep position of the rotor. For each microstep, the current limit for each winding is updated from a sine/cosine LUT, keeping the 90 degree shift between the two (as shown in Figure 17). These current limits also provide protection to the motor, limiting the instantaneous current flowing in the motor and preventing overheating, magnetic flux saturation, or loss of step position.

Shown in Figure 17 are the settings for each DAC and rotation index, and the microstep pointer (ramping 1-128).

Current limit versus time step

Figure 17: Current limit versus time step for 128 step microstepping.

The currents flowing in the two windings are measured with small sense resistors between the power devices and ground. The value of the current detection shunt resistor is a trade-off between power efficiency and robustness of the detection blocks. For a given current limit, enough change in voltage must be generated by the motor current to accurately detect the change with the comparator, but increasing the resistor increases heat and reduces efficiency.

The current limiting protection mechanism implemented in PSoC 3 hardware is an on-chip low-cost solution.

Rotation control

The output PWM drivers are controlled by a hardware lookup table. The table takes inputs from the two PWM blocks and a control register that holds the rotation index (as shown in Figure 18).

In Table 4, the PWM control hardware LUT receives the stage index and PWM signals as inputs and outputs the eight PWM driver signals.

Table 4: PWM control hardware LUT.

PSoC Creator schematic

Figure 18: PSoC Creator schematic LUT implementation of PWM output control.

When operating with microstep drive mode, the PWM outputs for PWM_A and PWM_B cycle through 01, 10, and 11. When the stepper motor operates under full-step mode, both PWMs are on (11). In this case, the LUT simplifies to the following table the rotation sequence described in the full-step descriptions earlier.

In Table 5, the simplified MPhase output control hardware LUT receives the stage index and PWM signals as inputs and outputs the eight PWM driver signals.

Table 5: MPhase output control hardware LUT.

Speed control

The stepper motor can be run at a fixed speed or to a desired position. To run at a fixed speed, the timer period that triggers each step (or microstep) is adjusted. The 16-bit timer terminal count triggers an interrupt that is used to initiate each step. Input frequency of the timer is 100 kHz to ensure precision speed control. PSoC 3 is also able to receive step pulse commands from an external controller such as a PLC.

In Figure 19, the timer terminal count triggers an interrupt that initiates each step.

PSoC Creator schematic implementation

Figure 19: PSoC Creator schematic implementation of speed control timer.

Position control

To run in position control mode, the stepper motor turns a specific number of steps and then stops. (Position control mode is not supported with the user interface in the stepper motor demo). An internal counter is used to count the desired steps. When the desired position is reached, the step control from the timer interrupt is masked until the user requests another action.

When the motor stops, phase current is lowered automatically to save power and reduce heating.

The ability to control the position in an open loop configuration by counting steps (or microsteps) is dependent on the stepper motor operating within the torque and motor load limits. If the torque/load limits are exceeded, the motor can miss steps and the absolute rotational position information is lost.

Firmware architecture

There is one main loop and one interrupt service routine (ISR) for control of the motor, the timer ISR. The timer ISR generates an interrupt that triggers the step control function (see Figure 19). Each time the step function is called, the motor takes one step (or microstep). The step function looks up the sinusoidal values from a table and sets the DAC output voltage to control the phase currents. A flow chart of the firmware operation is shown in Figure 20. Other ISRs for the UART and ADC are also used for the demo project UI and GUI interfaces.

Stepper motor control firmware flow chart

Figure 20: Stepper motor control firmware flow chart.

PSoC resource utilization

The stepper motor uses resources from the digital and analog portions of the PSoC 3 device. The highest use of resources stem from the VDACs and comparators. Two VDACs and two comparators are used for the stepper motor microstepping control. This constraint limits the CY8C3866AXI-040 device to a maximum of two stepper motor controllers.

Table 6: Stepper motor demo CY8C3866AXI-040 resource utilization (blocks with none used are not shown).

Table 7: Stepper motor demo on CY8C3866AXI-040 memory utilization (Keil™ Complier, Level-5 optimization)

Summary

Cypress’ stepper motor control with PSoC 3 incorporates current limiting and microstepping control for an optimized solution. Up to 128 microsteps is suitable for precision position control. The PSoC 3 stepper motor control solution has low total system cost and leaves significant PSoC 3 resources available for additional system functions.

References
  1. Cypress Application Note AN2229, “Motor Control - Multi-Functional Stepping Motor Driver” by Victor Kremin and Ruslan Bachinsky.
Convergence Logo

免责声明:各个作者和/或论坛参与者在本网站发表的观点、看法和意见不代表 DigiKey 的观点、看法和意见,也不代表 DigiKey 官方政策。

关于此作者

Isaac Sever

Article authored by Isaac Sever of Cypress Semiconductor.

关于此出版商

Convergence Promotions LLC