Getting Started with the AutoDriver
This Tutorial is Retired!
This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.
Arduino Library - Operation
Having covered configuring the board to run, let's talk about the commands that actually cause it to perform operations. One common parameter through all of these commands is dir
. Any command which calls for dir
can have passed to it either FWD
or REV
. So long as all of your motors are wired up the same, those values will produce the same rotation in all motors. If you find yourself dissatisfied with the rotational direction produced by the FWD
and REV
constants, the best course of action is to reverse the order of the wires on ONE winding on the motor in question. That will reverse the direction the motor spins.
Any motion will begin at the value defined by the setMinSpeed()
function (unless low-speed optimization is enabled, in which case, the motion starts at 0 steps/s and low-speed optimization is used until MIN_SPEED is reached), and will use both the acceleration and deceleration curve values to reach the final speed.
Basic Operations
void resetDev();
Equivalent to toggling the reset pin, but performed through an internal software register control on the L6470 chip. If you don't want to use a pin for reset, this option is for you.
void busyCheck();
Returns a 1 if the board is "busy", i.e., executing a motion command, or a 0 if not. If the current instance of the AutoDriver board was defined with a busyPin, it checks that pin; otherwise, it reads the internal STATUS register on the board to see if the driver is busy or not.
void run(byte dir, float stepsPerSec);
Turns the motor either FWD
or REV
at stepsPerSecond
rate, forever. The BUSY flag will remain asserted until motion is stopped by either issuing a hard stop or a soft stop.
void move(byte dir, unsigned long numSteps);
Turn the motor FWD
or REV
by numSteps
full steps. numSteps
is internally limited to 22 bits and is unsigned. The motor will use the acceleration profile as mentioned above, and the top speed of the motor during the motion will be the speed set with the setMaxSpeed()
function.
void softStop();
Stop the motor using the value set in the setDec()
function. Motor will come to a nice, gentle halt.
void hardStop();
Stop the motor with "infinite" deceleration. Motor will lurch to a very rapid grinding halt. Good for emergency stops.
void softHiZ();
Execute a soft stop, then put the motor drivers into a high-impedance state where no current flows through the windings. Note that this means the motor will turn freely!
void hardHiZ()
Execute a hard stop, followed by setting the drivers to high-impedance.
Position Operations
There are two registers in the L6470 which can be used for absolute position tracking and motion commands: ABS_POS and MARK. These functions use those registers to provide for motion based on the current and desired position of the motor, measured in steps.
long getPos();
The ABS_POS register in the L6470 chip on the AutoDriver contains a 22-bit signed value (-2097152 to 2097151 steps) tracking the position of the motor. This register starts at 0 on power up or reset. getPos()
returns the current value of that register. It is automatically incremented during moves of FWD
direction, and decremented during moves of REV
direction.
void resetPos();
Zero out the ABS_POS register, resetting home to the current location.
void setMark(long newMark)
Create a new MARK, which can be used as a shortcut for some motion commands. The value in MARK can also be automatically set by some events (such as activity on the switch input), if the device is configured properly. Same limits as set forth in the getPos()
function above.
void setPos(long newPos)
Set the current position to a new, arbitrary value. Same limits as set forth in the getPos()
function above.
void goTo(long pos)
From the current position, move in the shortest possible direction to the position passed by the user. Same limits as set forth in the getPos()
function above.
void goToDir(byte dir, long pos);
Similar to goTo()
, but with a specified direction. Same limits as set forth in the getPos()
function above.
void goHome();
Similar to goTo(0)
but requires less time to send via SPI. If a direction is required, use goToDir()
instead.
Advanced motion operations
void stepClock(byte dir);
Put the device in a "step-per-pulse" mode, where pulses on the STCK line will cause the motor to move one step in the direction indicated by dir
. The ABS_POS register will update, and microstepping will be used to move the motor.
void goUntil(byte action, byte dir, float stepsPerSec);
Start the motor moving, according to the acceleration profile, either FWD
or REV
, at stepsPerSec
rate, until a switch even occurs. When the switch event occurs, one of two things happens, based on the value passed to action
: if RESET_ABSPOS
is sent to action
, the ABS_POS register is reset to zero. If COPY_ABSPOS
is sent, the ABS_POS register is copied into the MARK register.
Either way, once the signal is received, either a hard stop or a soft stop will occur. The mode is determined by the setSwitchMode()
function: passing SW_HARD_STOP
to setSwitchMode()
results in a hardstop, while passing SW_USER
results in a soft stop.
void releaseSw(byte action, byte dir);
Move the motor at minimum speed until the switch is released, then hard stop and perform action
in the same manner as goUntil()
(i.e., copy ABS_POS into MARK or reset ABS_POS).
Parameter Access
Because we understand that you may want to do things the hard way, we've included two extra functions which provide full access to the parameter registers documented in the datasheet.
void setParam(byte param, unsigned long value);
unsigned long getParam(byte param);
Both can be used to arbitrarily read and write the exact contents of the registers in the datasheet. Names for the registers as described in the datasheet have been defined for use here, as well.
int getStatus();
Returns the current contents of the STATUS register on the L6470 chip. This is a good communications sanity check because on boot, the value will be 0x2E88.