Example Program

Homing to a hard stop


System designers often want to home an axis to a hard stop to avoid the additional complexity and expense of a home sensor. The usual problem with this approach is that the stepper motor produces torque based on its position within its electrical and mechanical cycles. When it stalls, those cycles cause the motor to move back and forth against the stop. When motion is stopped, the motor may come to rest some distance from the stop. This distance is can be random. If this position were used as a home position, poor accuracy would result.

The following sample code uses an iterative approach to try to capture the position closest to home that the motor reaches as it repeatedly hits the hard stop. Since the capture loop in the program runs quickly and asynchronously to the motor’s motion, the lowest value can be captured. This can be tested by stopping the motor, setting the hold current, HC, to zero, and moving the axis manually to the stop and checking the position register (PR P). This is the value we are trying to find. Once we find that value, we move a fixed distance from that value using an absolute move to that value +/- a set amount. We do this because we cannot move to the exact position of the hard stop. Once at this position, we either set the position to zero (P=0), or to some offset value X (P=X).


  • Closed Loop/Encoder

Applicable Product

  • MDrive Linear Actuator
  • MDrive Plus

Resource Files

Program Example

MDrive MCodeLexium MCode - hMT On