Stepper Motor? Encoder? It’s Both!

We always think it is interesting that a regular DC motor and a generator are about the same thing. Sure, each is optimized for its purpose, but inefficiencies aside, you can use electricity to rotate a shaft or use a rotating shaft to generate electricity. [Andriyf1] has a slightly different trick. He shows how to use a stepper motor as an encoder. You can see a video of the setup below.

It makes sense. If the coils in the stepper can move the shaft, then moving the shaft should induce a current in the coils. He does note that at slow speeds you can miss pulses, however. Again, the device isn’t really optimized for this type of operation.

The circuit uses an opamp-based differential amplifier to read the pulses from the coil. Two opamps on two coils produce a quadrature signal just like a normal encoder. When the shaft turns in one direction, one pulse will lead the other. In the other direction, the lead pulse will be reversed.

There’s code to let an Arduino read the pulses. And here’s plenty of code that will read quadrature on an Arduino or other processors. We’ve seen similar hacks done with hard drive motors which are quite similar, by the way.

22 thoughts on “Stepper Motor? Encoder? It’s Both!

  1. @Al Williams, I was suitably outraged by the alleged Patreon paywall. But then I read the Instructable, and the example code appears to be freely available as linked from the page. The Patreon link is just an invitation to support the author’s work. Either I’m missing something, or you may be doing the author a disservice–can you please double-check?

    1. I was remembering the same thing on the ETC Impression…I was just going to go down and pop the lid on one of the ones we have in storage and see if I was remembering correctly.

  2. Hard disk spindle motors can be two phase stepper motors, or three phase BLDC motors, mostly on more recent drives I think.

    I’ve always found the “this pulse leads the other” confusing; both channels have long series of pulses, all indistinguishable from each other. How can you say one channel leads the other?

    If you state instead that the first channel is low on the rising edge of the second channel for one direction, and high for the other, it makes perfect sense. From there, is not hard to see how the direction would be determined, why an encoder doesn’t lose track of the position when it’s moving back and forth on an edge, and how this can be extended to count all four edges for maximum resolution.

  3. The circuit in this article uses the forward voltage of a (Blue) LED as a reference voltage. LEDs make a lot of noise so that may be why it skips steps when turned slowly.

    I saw another circuit in the comments here and it was better at dealing with the back EMF but it had no hysteresis.

    Here are another who examples, each only one channel of the two needed.

    https://cdn.hackaday.io/images/7088311531693504394.png

    Both use the ratio of R4/R5 (R9/R10) to set the hysteresis to 1/100 or 0.05 Volts. The hysteresis needs to be higher than the noise level. and that ratio ban be adjusted.

    The other differences are how the diodes are arranged. In both cases they will limit the input to the op-amp to 2.5 Volts +/- 0.6 Volts.

    In both cases the PIV (Peek Inverse Voltage) is protected bu the Vf (Forward Voltage) of the other diode so you don’t need to worry about PIV.

    In the top circuit most of the back EMF is absorbed by the 100k resistor R3 so D1 and D2 can be small signal diodes like a 1N4148,

    In the bottom circuit the diodes (D3, D4)shunt all the current from the back EMF so perhaps they should be something like 1N4001 or the more common 1N4004.

    Because the back EMF is shunted in this way in the bottom circuit, turning the stepper will feel more notched and that may be desired feature.

  4. This is another use of a stepper to provide mechanical feedback for a Jog/Shuttle knob in a video editing set-up from 1989/90. https://photos.app.goo.gl/RBLTAW8LeL1DDjvr7 There is quite a long description to go with the photo, but basically the custom keyboard with the coloured keys has the editing controls. The Jog/Shuttle knob has an optical shaft encoder for position data, and a stepper motor to provide mechanical feedback. In Jog mode the knob could spin continuously, and the stepper provided both a “cogging” effect for slow speed feel, and a brake to stop it when you let go. Pressing the knob or one of the buttons above it would switch to Shuttle mode, and the stepper would then provide end stops and a return to centre “spring” effect. The action was the best I have ever used, but it cost me an additional £750 on top of the £15K for the computer, the editing software, the VTR interfaces and a video preview switcher.

  5. Great Scott tried something similar last year with a 3 phase motor: https://www.youtube.com/watch?v=tjCJ3MlFt7g It had the same downsides.

    That gave me an idea back then. What if you drive one phase with a small AC signal (square wave from a MCU) and check for the EM coupling on the other two? Basically the motor is used as a low res. inductive encoder. If you turn the rotor, the “output” signals will be asimmetric. I tried it once, and it was indeed significant, measurable with an oscilloscope. But I didn’t have the patience to go any further since then.
    You could have an encoder which works at single steps and has a nice tunable haptic feedback.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.