# Stepper Motor

Model stepper motor

## Library

Rotational Actuators

## Description

The Stepper Motor block represents a stepper motor. It uses the input pulse trains, A and B, to control the mechanical output according to the following equations:

`${e}_{A}=-{K}_{m}\omega \mathrm{sin}\left({N}_{r}\theta \right)$`
`${e}_{B}={K}_{m}\omega \mathrm{cos}\left({N}_{r}\theta \right)$`
`$\frac{d{i}_{A}}{dt}=\left({v}_{A}-R{i}_{A}-{e}_{A}\right)/L$`
`$\frac{d{i}_{B}}{dt}=\left({v}_{B}-R{i}_{B}-{e}_{B}\right)/L$`
`$J\frac{d\omega }{dt}+B\omega ={T}_{e}$`
`${T}_{e}=-{K}_{m}\left({i}_{A}-\frac{{e}_{A}}{{R}_{m}}\right)\mathrm{sin}\left({N}_{r}\theta \right)+{K}_{m}\left({i}_{B}-\frac{{e}_{B}}{{R}_{m}}\right)\mathrm{cos}\left({N}_{r}\theta \right)-{T}_{d}\mathrm{sin}\left(4{N}_{r}\theta \right)$`
`$\frac{d\theta }{dt}=\omega$`

where:

• eA and eB are the back emfs induced in the A and B phase windings, respectively.

• iA and iB are the A and B phase winding currents.

• vA and vB are the A and B phase winding voltages.

• Km is the motor torque constant.

• Nr is the number of teeth on each of the two rotor poles. The Full step size parameter is (π/2)/Nr.

• R is the winding resistance.

• L is the winding inductance.

• Rm is the magnetizing resistance.

• B is the rotational damping.

• J is the inertia.

• ω is the rotor speed.

• Θ is the rotor angle.

• Td is the detent torque amplitude.

If the initial rotor is zero or some multiple of (π/2)/Nr, the rotor is aligned with the phase winding of pulse A. This happens when there is a positive current flowing from the A+ to the A- ports and there is no current flowing from the B+ to the B- ports.

Use the Stepper Motor Driver block to create the pulse trains for the Stepper Motor block.

The Stepper Motor block produces a positive torque acting from the mechanical C to R ports when the phase of pulse A leads the phase of pulse B.

### Averaged Mode

If you set the Simulation mode parameter to `Averaged`, both for a Stepper Motor block and for the Stepper Motor Driver block that controls it, then the individual steps are not simulated. This can be a good way to speed up simulation. In Averaged mode, under non-slipping conditions, the motor and driver are represented by a second-order linear system that tracks the specified step rate. The demanded step rate is determined directly from voltage across A+ and A-. So, for example, a voltage of +10V across the A+ and A- terminals is interpreted as a step rate demand of ten steps per second. See the Stepper Motor Driver reference page for more information on how to connect the Stepper Motor Driver to your step angle controller.

Averaged mode includes a slip estimator to predict whether the stepper motor would have slipped if running in Stepping simulation mode. Slip is predicted if the motor torque exceeds the Vector of maximum torque values parameter value for longer than one step period, the step period being determined from the current step rate demand. Upon detecting slip, the simulation will proceed or stop with an error, according to the Action on slipping parameter value. If you choose the action that lets the simulation continue, note that simulation results may be incorrect: when slipping occurs, the torque generated by the motor will not generally be the maximum available torque; the maximum torque is only achieved if the stepper controller detects slip and adjusts the step rate command accordingly.

The dynamics of the equivalent second-order system are determined from the values that you specify for the Approximate total load inertia and Maximum step rate command parameters. It is important that you set as accurate values as possible for these parameters, so that the step rate command is tracked, and the block does not generate false slipping warnings or errors.

If you run the motor in Averaged mode with the optional thermal ports exposed (see Thermal Ports), then heat is added to the thermal ports assuming that the windings are always powered, even when the step rate command is zero. The block makes adjustments for half stepping and for reduced torque (and winding currents) at higher speeds. For these adjustments to be correct, the Vector of maximum torque parameter values must be correct. For half stepping, at zero speed the heat generated by the block is the average of that generated when stopped at a half step and at a full step.

If you simulate or predict slip, MathWorks recommends that you do some validation runs comparing Stepping and Averaged modes before using the averaged model representation for simulation studies.

### Thermal Ports

The block has three optional thermal ports, one for each of the two windings and one for the rotor. These ports are hidden by default. To expose the thermal ports, right-click the block in your model, and then from the context menu select Simscape > Block choices > Show thermal port. This action displays the thermal ports on the block icon, and adds the Temperature Dependence and Thermal Port tabs to the block dialog box. These tabs are described further on this reference page.

Use the thermal ports to simulate the effects of copper resistance and iron losses that convert electrical power to heat. For more information on using thermal ports in actuator blocks, see Simulating Thermal Effects in Rotational and Translational Actuators.

## Basic Assumptions and Limitations

The model is based on the following assumptions:

• This model neglects magnetic saturation effects and any magnetic coupling between phases.

• When you select the Start simulation from steady state check box in the Simscape™ Solver Configuration block, this block will not initialize an Initial rotor angle value between –π and π.

• To use Averaged mode, the Stepper Motor block must be directly connected to a Stepper Motor Driver block also running in Averaged mode.

• The Averaged mode is an approximation, and exact step tracking compared to the Stepping mode should not be expected.

• Slip detection in Averaged mode is approximate, and depends on a good estimate for load inertia and maximum step rate. Incorrect values may result in false slip detection.

• When simulating slip in Averaged mode, it is assumed that the stepper motor controller adjusts the step rate command so as to achieve maximum possible torque.

## Dialog Box and Parameters

### Electrical Torque Tab

Simulation mode

Select `Stepping` or `Averaged`. Use `Averaged` only if the block is connected directly to a Stepper Motor Driver block also running in Averaged mode. The default value is `Stepping`.

Phase winding resistance

Resistance of the A and B phase windings. This parameter is visible only if Simulation mode is set to `Stepping`. The default value is `0.55` Ω.

Phase winding inductance

Inductance of the A and B phase windings. This parameter is visible only if Simulation mode is set to `Stepping`. The default value is `0.0015` H.

Motor torque constant

Motor torque constant Km. This parameter is visible only if Simulation mode is set to `Stepping`. The default value is `0.19` N*m/A.

Detent torque

The amplitude of the sinusoidal torque variation observed when rotating the shaft of the unpowered motor. This parameter is visible only if Simulation mode is set to `Stepping`. The default value is `0` N*m.

Magnetizing resistance

The total magnetizing resistance seen from each of the phase windings. This parameter is visible only if Simulation mode is set to `Stepping`. The value must be greater than zero. The default value is `Inf`, which implies that there are no iron losses.

Vector of rotational speeds

Vector of rotational speeds at which to define maximum torque values, for slip prediction. This parameter is visible only if Simulation mode is set to `Averaged`. The default value is `[0 1000 3000]` rpm.

Vector of maximum torque values

Vector of maximum torque values, to be used for slip prediction in conjunction with the Vector of rotational speeds parameter. The maximum torque values are often given on a datasheet, and should correspond to the supply voltage and stepping type (half step or full step) specified in the driver. This parameter is visible only if Simulation mode is set to `Averaged`. The default value is `[2 2 1]` N*m.

Action on slipping

Select the action for the block to perform during simulation upon detecting slip:

• `none` — Continue simulation, limiting the load torque according to the Vector of maximum torque values.

• `warn` — Continue simulation, limiting the load torque according to the Vector of maximum torque values, and generate a warning that the rotor is slipping.

• `error` — Stop the simulation and generate an error message that the rotor is slipping.

Note that if you choose an action that lets the simulation continue, simulation results may be incorrect: when slipping occurs, the torque generated by the motor will not generally be the maximum available torque; the maximum torque is only achieved if the stepper controller detects slip and adjusts the step rate command accordingly.

This parameter is visible only if Simulation mode is set to `Averaged`.

Approximate total load inertia

The approximate total load inertia, including the rotor inertia. This value is used to help predict when slipping will occur due to rapid acceleration demands. This parameter is visible only if Simulation mode is set to `Averaged`. The default value is `1e-4` kg*m^2.

Maximum step rate command

The maximum step rate that your system will command. It is used to determine a suitable bandwidth for the second order system approximation to the stepper motor and driver. This parameter is visible only if Simulation mode is set to `Averaged`. The default value is `10` Hz.

Full step size

Step size when changing the polarity of either the A or B phase current. The default value is `1.8`°.

### Mechanical Tab

Rotor inertia

Resistance of the rotor to change in motor motion. The default value is `4.5e-05` kg*m2. The value can be zero.

Rotor damping

Energy dissipated by the rotor. The default value is `8e-04` N*m/(rad/s). The value can be zero.

Initial rotor speed

Speed of the rotor at the start of the simulation. The default value is `0` rpm.

Initial rotor angle

Angle of the rotor at the start of the simulation. The default value is `0` rad.

### Temperature Dependence Tab

This tab appears only for blocks with exposed thermal ports. For more information, see Thermal Ports.

Resistance temperature coefficients, [alpha_A alpha_B]

A 1 by 2 row vector defining the coefficient α in the equation relating resistance to temperature, as described in Thermal Model for Actuator Blocks. The first element corresponds to winding A, and the second to winding B. The default value is for copper, and is ```[ 0.00393 0.00393 ]``` 1/K.

Measurement temperature

The temperature for which motor parameters are defined. The default value is `25` °C.

### Thermal Port Tab

This tab appears only for blocks with exposed thermal ports. For more information, see Thermal Ports.

Winding thermal masses, [M_A M_B]

A 1 by 2 row vector defining the thermal mass for the A and B windings. The thermal mass is the energy required to raise the temperature by one degree. The default value is `[ 100 100 ]` J/K.

Winding initial temperatures, [T_A T_B]

A 1 by 2 row vector defining the temperature of the A and B thermal ports at the start of simulation. The default value is ```[ 25 25 ]``` °C.

Rotor thermal mass

The thermal mass of the rotor, that is, the energy required to raise the temperature of the rotor by one degree. The default value is `50` J/K.

Rotor initial temperature

The temperature of the rotor at the start of simulation. The default value is `25` °C.

Percentage of magnetizing resistance associated with the rotor

The percentage of the magnetizing resistance associated with the magnetic path through the rotor. It determines how much of the iron loss heating is attributed to the rotor thermal port HR, and how much is attributed to the two winding thermal ports HA and HB. The default value is `90`%.

## Ports

The block has the following ports:

`A+`

Top A-phase electrical connection

`A-`

Lower A-phase electrical connection

`B+`

Top B-phase electrical connection

`B-`

Lower B-phase electrical connection

`C`

Mechanical rotational conserving port

`R`

Mechanical rotational conserving port

`HA`

Winding A thermal port. For more information, see Thermal Ports.

`HB`

Winding B thermal port. For more information, see Thermal Ports.

`HR`

Rotor thermal port. For more information, see Thermal Ports.

## Examples

See the Controlled Stepper Motor and Stepper Motor Averaged Mode examples.

## References

[1] M. Bodson, J. N. Chiasson, R. T. Novotnak and R. B. Rekowski. "High-Performance Nonlinear Feedback Control of a Permanent Magnet Stepper Motor." IEEE Transactions on Control Systems Technology, Vol. 1, No. 1, March 1993.

[2] P. P. Acarnley. Stepping Motors: A Guide to Modern Theory and Practice. New York: Peregrinus, 1982.

[3] S.E. Lyshevski. Electromechanical Systems, Electric Machines, and Applied Mechatronics. CRC, 1999.