• Permanently deleted user

Agreed. Been asking for stepper motors for a while now.

• Cleared

Thanks

• Reginaldo Caze

Where are the stepper motors?

• Cleared

Need basic steppers.

• Cleared

• Cleared

• Witold Rozak

• Karl Hansen

Ditto.

Just need two generic 2-phase instances, one with 200 steps per revolution, the other with 400 steps per revolution.

BOTH with encoders and zero-index.

The math behind how they work is pretty simple for an ideal-model stepper:

https://en.wikipedia.org/wiki/Stepper_motor#Bipolar_motors

http://hades.mech.northwestern.edu/index.php/Stepper_Motor_Theory   (If you want a model which handles both unipolar and bipolar, see last paragraph of this link.)

Internal logic:

1. Connections: PhaseA+, PhaseA-, PhaseB+, PhaseB-, EncGround, EncPower, EncAOut, EncBOut, EncIndex
2. Store a floating-point angle
3. Store number of steps per revolution.
4. Store encoder pulses per revolution.
5. Store width (in degrees) of index pulse. Index is presumed high between (0 - width) and zero and low otherwise. The transition from high-to-low is the zero-degree position.
6. Store resistance between the +/- connections on the phases.

Behavior:

1. Ignoring inductance effects, phase magnetic field-strength is proportional to current magnitude and direction between +/- phase connections. The current is V(phase) / R(phase) and will be positive or negative depending on whether V(phase) is positive -- e.g. (PhaseA- < PhaseA+) -- or V(phase) is negative -- e.g. (PhaseA- > PhaseA+).
2. Step direction is controlled by the polarity and field-strength ratio between phase A and B. Typically A is driven by sin(+/-X) values and B is driven by cos(+/-X) values,
3. Micro-stepping is achieved by driving both phases with different applied voltages.  The step size is controlled by how many discrete positions are used in the sin/cos drive values.

In the stepper model, you increment or decrement the stored Angle based on the step size, and step size is controlled as described in Behavior. The degrees-per-step is trivially calculated from the steps-per-revolution.

EncA and EncB values are trivially calculated from the Angle, Enc pulses-per-revolution, and the presumption that at zero degrees EncA == EncB == 0.

Index state is trivially calculated from the Angle, index pulse width in degrees, and the pulse direction as described above.

Initial state of stepper is indeterminate or random.

Calibration:

Note that "positive" direction can be either clockwise or counter-clockwise depending on motor. Zero degrees is where the hi-to-lo index transition occurs while stepping in the "positive" direction.

1. Step motor in positive direction until index hi-to-lo transition occurs.  This locates the zero-degree position for the motor. Record the values for EncA and EncB.
2. Continue stepping in same direction hi-to-lo index transition occurs again.  While stepping count the positive AND negative edges on EncA and EncB. Also record these counts when index transitions lo-to-hi.
3. The counts for EncA and EncB must agree, otherwise there is an encoder error.  Also EncA and EncB should be in the same state recorded in step 1.
4. The difference between the final counts and the counts recorded at the lo-to-hi index transition give the encoder-edge width for the index pulse.