Sunday, January 29, 2017

DRV8825: nHOME, part 2

Continuing on with the nHOME investigation, I discovered that there is no pin on the carrier board that the nHOME pin can be broken out to easily.
I thought I could replace the nFAULT pin with it, but it ends up that pin is connected directly to the logic supply (5V) on most host boards (RAMPS, etc.) I next looked at the nSLEEP pin, but for some insane reason this pin is pulled down internally, so it *must* be pulled up externally, or your motor driver board will never turn on. At this point I gave up on bringing nHOME out to a pin on the carrier board... it would be mostly for physical security anyway, since it will need to be wired to a logic pin somewhere else on the board. So, blue wiring it is!

I tried some new stuff during the hookup: I've had an unused Arduino CNC shield for a while, and I figured that would be the easiest way to test a carrier board. It uses the standard Uno pin naming, and breaks out the pins from the carrier sockets to male headers, which is perfect if you want to sample those lines with an o-scope while a carrier board is plugged in.
I also found an interesting new stepper driver library (it's called StepperDriver) that can track the microstepping for you, and lets you move the motor by degrees instead of just steps. (I used neither of those features for this round of testing, but I might use them in the next one.)

Test setup
I made an Arduino sketch that steps 200 times in the forward direction, pausing for 500ms between each step. After 200 steps, it pauses for 1s and then repeats in the other direction. I pulled the nHOME pin up to Vcc via a 10k resistor. I hooked a scope probe to the step and nHOME pins. The microstepping was set to 1/1, or one full step per pulse.

Expected result
If I read the DRV8825 datasheet correctly, the nHOME pin should assert once per revolution at 45°. Being a standard 1.8°/step motor, 200 steps should be one full rotation. I expected to hit it once in the fwd direction, and a second time in reverse.

Actual result
My, was I surprised! The nHOME pin didn't just assert once per rev, but actually it was pulled down once for every four steps! The delay between pulses was too long; capturing a full rotation made my scope's screen refresh take forever. But I have no reason to think I wasn't getting normal behavior on that end (I measured stepping frequency at 1.25Hz). If this nHOME behavior is not due to an error on my part, that means not only is the assert count not 1/360°, but it's actually 1/7.2°, or 50 pulses per rev.
I bought these drivers off eBay, I believe, and I've always been curious if they were genuine TI parts. It's likely they are knock-offs and this nHOME behavior is either

an error, or due to a mis-translation of the datasheet (like the famous bug in nrf24 clones). I actually think it may be more useful this way, as I was thinking I'd need to physically align the steppers so that 45° would be near where the endstop hit. Hopefully a bit more investigation will determine if it's truly the driver or some error in my setup.




Next steps
I want to re-run what I just did, minus the delay between steps. I should be able to capture all the pulses for a full rotation more easily, at the same time eliminating the delay() function as a culprit for any timing weirdness.
I'd also like to try out larger microstepping values. If I understand the datasheet correctly (and I'm 0/1 so far), the nHOME pulses are related to the physical position of the stepper, which would mean it will assert at the same spots, regardless of how many steps it took to get there. My guess is changing the microstepping to 1/2 will make the nHOME assert once every 8 step pulses.

Time for more science!

1 comment:

  1. Hey, you seem to be mixing up the mechanical angle of the motor and the electrical phase angle of the winding currents (notice that the table in the DRV8825 datasheet contains the heading "electrical angle"). The electrical angle refers to a specific state in the cycle of voltage and current that the driver outputs. If you draw out the voltage/current waveforms for all four outputs, you will see that they repeat after a sequence of four full steps (or eight 1/2-steps, or sixteen 1/4-steps, etc.); therefore, four steps are equivalent to a full cycle of electrical states, or an electrical angle of 360 degrees.

    The motor driver has no way of knowing what the motor's step size is and how much it moves physically per electrical cycle. If your stepper motor had a 90 degree step angle (4 steps per revolution), the mechanical angle would correspond directly with the electrical angle. But since your motor has a 1.8 degree step angle (200 steps per revolution), it takes 50 electrical cycles to produce each mechanical cycle (revolution), and that is why you saw nHOME assert 50 times per revolution.

    - Kevin

    ReplyDelete