Sunday, January 22, 2017

TI DRV8825: There's no place like nHOME

I was comparing TI's DRV8825 and DRV8811 stepper motor drivers when I found a "hidden" feature I hadn't noticed before. Both drivers have an "nHOME" pin that goes active only when the stepper motor is at a specific angle (45°). I immediately thought of several uses for this pin.
The simplest application of the nHOME pin is as a check for your 3d printer's steps/mm settings. Calibrating that setting is critical for producing dimensionally accurate prints, but there's always a bit of guesswork involved. Most cal guides include a complicated function that multiplies step angle by microsteps, # of teeth, gear size, etc. I prefer to skip all that and just print 20mm calibration cubes and adjust the steps/mm with the error. Neither method is very precise, since there are many other factors involved in the final output, like filament diameter and flow rate. But I've found that if you calibrate the extruder motor first, and don't change filament between measurements, my method can result in less than 1% error (when you use a measurement tool with less than 1% error, of course). Regardless of which method you use, the motor parameter is always a constant. A stepper with a standard 1.8° step angle has 200 steps/revolution. It's set in stone. But when you enable microstepping, does a revolution still equal 200*mstep factor? If something is wrong with your driver setup, and your motor is skipping steps, you won't see it until you start printing, at which time there will be a bunch of other possible causes. (If it sounds like I am familiar with this problem, it's because I am. Intimately.)
Being able to verify how many step pulses equal a full revolution of the motor would be a very simple and handy tool in our toolboxes.
The other, and most interesting, application is for closed-loop motor feedback. With no additional components at all, the nHOME pin could be used to verify the motor hasn't skipped steps during printing. It wouldn't be very precise, since you would only be able to check it once per full revolution, but it's still better than no check at all.
Where this really starts to get interesting is when you couple the nHOME pin with an encoder. The most useful (and expensive) encoders report "absolute" positions, meaning they give you the exact position at any time, even at power-up. The cheapest encoders only report "relative" position. Relative encoders tell you how many pulses the motor has moved forwards or backwards. If you stop counting pulses, or power down the system, you don't know where the motor is, and you need to home the motor to get a "zero" position to start from. (This is how most 3d printers work, today, minus the encoder. The system counts how many step pulses it sends to the motor in each direction, so it knows where the motor "should" be, as long as it didn't skip any steps). I've also seen "hybrid" encoders that combine a relative one with a simple two-state detector. You can use the simple detector to give some context to the relative pulses; I've seen kinds that pulse once per revolution, and other types that are on for half the rev and off for the other half. The nHOME pin functions just like the former, meaning you could always correlate the physical position of the motor with the relative pulses. You could even use it to automatically calibrate the encoder, since a relative one still requires a "pulses per distance" number to be useful. (If you're repurposing encoders from other sources, you may not know that exact value.) Counting encoder pulses that occur between two nHOME toggles means you know exactly how many pulses occur for one full rev of the motor! Throw in a move to the endstop to get a zero postion and you'd be able to know the exact position of the motor carriage, (along with the exact angle) at any time! Good stuff!
Unfortunately the nHOME pin isn't broken out to a header on Pololu (or clone) DRV8825 boards, but there are several that nobody ever uses. I'll do some research and see if one of those pins can be swapped out for nHOME.

No comments:

Post a Comment