Stepper motor and encoder

i have a stepper motor nema 17 and sometimes it skips steps. so i would like to use an encoder to count the steps to ensure that it cannot skip steps. could someone help me write a code or explain to me how to do this or where i can find this

What do you mean by "skips steps"? If it isn't a defective stepper and there aren't mechanical reasons, it shouldn't "skip" steps, so there's no need for a feedback ecnoder.
How did you determine that "sometimes" looses steps? And "sometimes" means...?
Where are you using this stepper (e.g. a short description of the project)?
Could you also show here your code (at least the stepper controlling sections)?

An encoder maybe could help you somehow, but IMHO not much, because first of all you need one with at least the same resolution of the steppere (e.g. 0.9°). And, not knowing your project, it is generally difficult to give you advice for the code, you must first choose which encoder you'd like to use.

on another forum a member said modern avionic instruments are driven with stepper motors but use encoders to verify their position.

It's generally a better idea to understand why a problem is occurring before trying to fix it.

Stepper motors in normal operation should not skip steps, so something is wrong. First understand what is causing the motor to skip steps and then try to address that. If those solutions fail, or you need additional security, then I'd say adding an encoder is warranted.

The most common reasons for a stepper-motor to loose steps are

  • mechanical overload of the stepper-motor
  • too fast acceleration
  • too high start-frequency of the step-pulses
  • too high end-frequency of the step-pulses
  • too less current (though you can't exceed the manufactorer's rating for max current)
  • too low supply-voltage
  • poor performing stepper-driver-circuit

Without knowing the details of your project the real rason can't be narrowed down.
This is the reason why you should post

  • your complete sketch

  • datasheet of the stepper-motor

  • datasheet of the stepper-motor-driver

  • specs of your stepper-motor power-supply voltage / amperage

  • a description of what your steppermotor is used for

If the Stepper is using a cogged belt drive, I can see that you might have a problem getting an exact position. I used cogged belts to position my 3-axis wood router, with an 400 PPR x4 encoder. it is very accurate, my dial mike says so. If the stepper is direct drive then driver setup could be an Issue or power supply issues.

I used an LS7266 chip to interface my Nano to the encoder, it uses SPI to communicate values to the processor. see the attached text file. It is old code but it works and can easily be modified to suit.
LS7266 Encoder interface Code.txt (6.2 KB)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.