# Closed loop control of a stepper motor (i.e. servo system)

Crucial to the performance of a CNC is its ability to precisely, accurately and quickly move to the directed position. Stepper motors are perhaps the most popular (and therefore cheapest) motors available for position control as they can be controlled without feedback. However, it is possible for stepper motors to lose position and accuracy. Additionally, attempting to drive a stepper motor faster reduces precision. A closed loop stepper motor controller/driver needs to be designed and built so that the stepper motors can operate at peak levels (power/torque and speed) without losing accuracy or precision. It is recommended to make use of a Nema17 stepper motor capable of 0.5Nm. The designer should determine the accuracy, precision and speed required.

the design is based on arduino and grbl. i used proteus. the problem is i don't know how to add a feedback.

• If you want a "closed-loop" system for the "stepper motor", you will need a "servo system"...and therefore position control in this case. And rethink all the software ... although this is already planned, it seems to me by the control of accelerations (see internal parameters in GRBL). Also rethink the "mechanics" because, when you control stepper motors more quickly, you must also provide oscillation "shock absorber" on their axes ... Commented May 14, 2022 at 16:17

I would question the assumptions of your homework.

If you design an open-loop stepper system with end-stop feedback for "datum" or zero position calibration, with care, there is no need for step-by-step feedback.

That is done by design or testing and with trim on the parameters in order to prevent skipped steps. This means you have excess torque for a known target friction and/or acceleration a=F/m with known momentum p=mv and stored energy E=0.5mv^2. But it could also mean it's slow and noisy.

Thus it is possible to seek times for performance without skipped steps unless there is an unexpected force exceeding torque to make the step transition. In most cases, increasing current limit and acceleration reduces damping from transient impedance changes and natural mechanical resonance. In clever designs, I have seen rotary oil-filled brass in plastic disk wheels attached to the stepper motor to add mechanical damping.

The clue for optimal performance is to have a smooth velocity change with a controlled-acceleration change or jerk level. The electronic method also used in sensorless vector-controlled BLDC motors is to measure impedance from the vector transformation of voltage and current.

I have not done this, but you need to compare the expected transient current for each step to ensure a slip back has not occurred. Other methods might use an optical rotary encoder at great expense, but this is not used even in my Mercedes SUV tailgate which has a smart stepper control.

Each step will vary in current according to mass, acceleration, velocity, phase control, friction, R/L slew rate, mechanical resonance, electrical resonance, and active current limit.

A phase current monitor for feedback, therefore, can be able to compare the expected current shape with the actual one on a step-by-step basis. When moving near maximum velocity or acceleration or a jerk with transient friction, the risk of slipping steps increases. The challenge is, therefore, to recover from slipped steps by sensing motor impedance by current, and thus BEMF changes with velocity so as to slow down after recovering from a missed step and then adjust the limits so as not to slip after some worst-case calibration.

The normal response is to halt when a fault occurs. Then a manual recal to the home switch to rezero. Home switches may be optical or mechanical if precise. For safety switches can used for each end or current limited and stopped before damage. (magnetic cogging effect)

Trial and error methods can also work well if known for different mass loads and limited by a=F/m , but in robotic work, this can sometimes be unknown. Thus it is a question of safety margins and damage on how you choose to sense position error by expensive sensor feedback or by the design of current profile feedback from repetitive motions with smart fault detection and recovery.

We know the unloaded open-loop velocity creates a back EMF voltage (BEMF) just as DC BLDC motors have an unloaded kV/RPM while RPM or velocity reduces with the mechanical load. This also affects the current step shape from the applied voltage or current limit and the voltage feedback from each applied step. Since both could change a multiplier is needed to compute V(t)/I(t)=Z(t) and compare it with the expected response under all conditions.

There is an electrical time constant for the T= (RdsOn(2)+ DCR)/L for a locked rotor that has no BEMF with some thermal sensitivity. There is another time constant with almost no load and a 2nd order torque spring-mass response that changes with load inertia. Damping can be mechanical or electrically dampened also to reduce acoustic noise effects by synchronizing the step interval and reducing the settling time of resonance. Half-stepping also reduces noise but also reduces torque and speed.

Assumptions are the core saturation limits are known and do not occur from the imbalanced full bridge which would reduce L or excessive temp rise and also reduces L with forced air cooling for high duty factor work.

Start by making a list of assumptions and measurement specs by verifying the motor no- load impedance with alternating pulse steps with constant acceleration and variable current limits and fixed voltage over a variable position range with velocity limits. Record and store the Z=V/I and P=V*I results for each case. (steps with measured initial conditions)

Choose an EMI robust twisted pair cables and current sense method (Hall or 50 mV shunts). Choose a good operating system with control over every variable. I recommend GCODE PANEL (open source written by a pro) which has constants for dozens of variables with USB to any Windows OS with a Gcode interpreter uploaded to any Arduino with a CNC shield for a Windows laptop.

The motor is your choice and there are many ranges. 12V 2A is common, with higher voltage for more power. I was able to make my unloaded gantry seek 1m in < 0.5 seconds with 2 moving X motors and 1 Y Nema17 motor. This max speed must be reduced with added mass.

Nema17 just means the American dimensions of 1.7" square but NEMA17 can also be "any" length which controls the torque and winding resistance and R/L time constant. That's your choice.

Start with an inexpensive mechanical kit but make it more mechanically robust.

Try to define specs for goals then add more detail to each goal into design specs from the variables.

• I am controling the position of a stepper motor. now i am planning to use l297 and l298 drive. the problem is to add a feedback and to select components Commented May 16, 2022 at 19:08
• What part did you not understand in my answer with your present understanding? Commented May 16, 2022 at 19:36
• Do you have time to order a better driver? usa.banggood.com/… How will you sense current or motor phase? Commented May 16, 2022 at 19:38
• the first thing is to do calculations. I am using nema 17 stepper motor. so I need calculation of accuracy, speed of a motor. Commented May 18, 2022 at 20:31