Issue with Stepper Motor with Builtin Decoder

mjs513

Senior Member+
Been having fun learning about stepper motors but running into an issue when using the built-in encoder in the steppermotor. Will explain in great detail but first some basic info.

StepperMotor:
STEPPERONLINE Nema 17 Closed Loop Stepper Motor 23oz.in w/ Magnetic Encoder: https://www.omc-stepperonline.com/n...etic-encoder-1000ppr-4000cpr-17hs08-1004-me1k. The specs are in the attached PDF. But basically its a 200ppr stepper rated at 1amp per datasheet with a 4000 count encoder.

Motor and Encoder Connection

Motor​
A+​
A-​
B+​
B-​
Wire​
Red​
Black​
Yellow​
Blue​

Encoder​
VCC​
EGND​
EA+​
EA-​
EB+​
EB-​
EZ+​
EZ-​
Wire​
Red​
Black​
BRN​
ORG​
Blue​
Green​
Yellow​
White​

The motor is connected to a Teensy 4.0 using a Pololu DRV8825 (splurge and buy the real one - had issues with the knock off). The encoder is connected to a T4.1 so I can read the encoder as the motor is running.

Stepper wiring:
1746792432667.png

GNDs connected to GND on T4.
M0 - 5
M1 - 6
M2 - 7
Reset/Sleep - 3.3v
STEP - 14
Dir - 15
A1/A2/B1/B2 connected to motor through a interface board Picture below

Vref on the DRV8825 is set to 0.4v which is about 0.8 amp versus the 1.0amp rated current.

Encoder connections:
A+ - pin 2
B+ - pin 3
Z+ - pin 5
power - 5v
gnd - gnd
goes through a pololu level shifter to the T4.1 :)

Driver library:
None. Rolled my own as a learning exercise. See attached sketch for stepper motor
Encoder sketch - using the simple_encoder example sketch.


ISSUE:
When the motor is running the encoder is showing counts that go up and down as opposed to a continuous increase as would normally be expected. The graphs below that in gory detail at least for the first bunch of pulses:
Microstep = 1/2 1/4
1746793356668.png
1746793395012.png


The interesting thing though at the end of a revolution the total counts is 4000 which is what it should be.

Decided to put a LA on the encoder pins to see whats happening and you can see where phase B goes out of synch:
1746793579187.png


No clue what the issue could be. But as a test with the motor disconnected and turning the shaft manually not seeing it to that extent only once or twice which could have been me.
1746793664203.png


I do have a Sparkfun Prodriver coming with is what the interface board was designed for (no clue where I put the original).

1746793965475.png
 

Attachments

  • 17HS08-1004-ME1K_Full_Datasheet (1).pdf
    166.8 KB · Views: 11
  • teensyEncStepper_test-250509a.zip
    1.7 KB · Views: 11
Sounds like a project!
Yep - one of those things that has been on my to do list - better understanding of steppers and interfacing with the Quadencoder library. Always see questions about steppers.

Last time I did stuff with motors and encoders... I cheated and used a RoboClaw.
Something like: https://www.basicmicro.com/roboclaw-2x30a-motor-controller_p_9.html
But that was for Brushed motors...
I have seen that before when I was looking at motor controllers for my robotics projects.

Have played with the Sparkfun Prodriver: https://www.sparkfun.com/sparkfun-prodriver-stepper-motor-driver-tc78h670ftg.html and the Adafruit Motor/Stepper/Servo Shield: https://www.adafruit.com/product/1438. Never tried the DRV8825's or the A9488's so was curious (which always gets me in trouble).

At some point was thinking about writing some sort of post on what I did and how things work but thats for another day. Found a several interesting tidbits and lessons along the way.
 
ISSUE:
When the motor is running the encoder is showing counts that go up and down as opposed to a continuous increase as would normally be expected.
I deduce you have no mechanical damping so the motor is actually bouncing back and forth on each step - use 1/16 microstepping or so and you will probably solve this. Bouncing around won't cause mis-counting with quadrature, that's the reason quadrature is used.

Alternatively you might have some backlash between the motor and the encoder, but this is unlikely with an integrated unit.
 
I deduce you have no mechanical damping so the motor is actually bouncing back and forth on each step - use 1/16 microstepping or so and you will probably solve this. Bouncing around won't cause mis-counting with quadrature, that's the reason quadrature is used.
Hi Mark

Tried it just laying on desk and holding it tightly in hand (since just testing 1 Rev).. Do have a couple of brackets on order to mount on a flat board.

Alternatively you might have some backlash between the motor and the encoder, but this is unlikely with an integrated unit.
Was thinking about that but as you said its an integrated unit. Kind of the reason why I bought a stepper with a integrated encoder. But at any rate tried it at 1/16 and still there:
1746813866252.png

and you still see it even at 1/32
 
Try 500, I suspect its all smoothed out at higher speeds due to inertia. More microstepping ought to reduce this kind of vibration - perhaps also try and 1rpm. Steppers behave worse at middle speeds where the natural resonance of the rotor matches step rates - there's even a term for it, "mid-band resonace"
 
Ok tried at 1RPM and Microstep = 4 notl seeing the issue, running at 500rpm not seeing it except at the end of turn which seeing an interesting affect:
1746817489698.png
Microseteps = 16.
With a microstep of 8 not seeing it either at speed 500.

Actually just realised something. In my sketch have to set MS before speed. So with a MS=8 and S=100: Not seeing issue of originally identified but with M<4 yes. Even with
Code:
Microsteps set to: 4
PPR: 200, MPR: 4, RPM: 100
TPR: 800, PPS: 1333.333252, PW(us): 750
not seeing issue but still seeing the oscilations at 4000 ( at end of movement)

Interesting effects.

Never came across this in any of the readings on steppers so far. Wish all this was in one place

thanks for resolving the one issue.

PS now that its working correctly stepper is getting hotter :)

Have to experiment a bit more now that I have a starting point
 
Last edited:
Steppers at full rated current get very hot. Its normal to drop the drive current to about 50% when stationary so the heat goes down by a factor of 4ish. The stationary torque is a lot higher than dynamic torque so this usually isn't a problem.
 
Steppers behave funky, even with some load. I have seen this on my electronic lead screw on my lathe. I'm using 4 microsteps/step. The even microsteps are different in size than the odd. That's just how the stepper driver is. I can't do anything about it. I had a 1um resolution digital read out on my Z axis, and I could clearly see that the step sizes translated to displacement had resonances in them at certain speeds, or just were uneven. That's how the real world is, for motors and sensors, they are imperfect. In my case the step sizes are 2.5um on average, but the evens are more like 1.5, and the odds 3.5. Oh, and motor full steps aren't all perfect 1.8 degrees either. But 200 full steps, or 800 microsteps does come out to be exactly one revolution.
 
Thanks for the confirmation. I learned this the hard way :)
Me too.;)
Mid-band resonance sounded like there was gravel in my gearbox, it really sounded terrible, like things were irreparably broken. In my case, I pushed mid-band resonance to a higher frequency by increasing the inertial load on the motor. (Added an aluminum disk to the motor pulley, to increase the moment of inertia.). No more resonance.
 
going to have to try something like that - have to add it to my to do list :)
I added a 4" diameter disk, about 1/2" thick, coaxial with the bore of the timing pulley. Was good enough to drive the resonance from about 1200 RPM to over 2200 RPM, which was good enough for my application. (Max spindle speed on my lathe is 2200 RPM.) Downside, is it takes a little longer to stop. But no resonance from 0-2200 RPM now.
PXL_20250513_001139493.jpg
 
Last edited:
Back
Top