This post assumes that the reader is familiar with programming and using SPI. This post will cover how to use the Dual L6470 Stepper Controller that we manufacture.
To program the L6470 use the dSPIN Library which can be obtained here: dSPIN. It is derived from work done by Mike Hord over at Sparkfun and as such remains in the public domain.
Connecting to the Dual Stepper Controller
The Dual Stepper Controller has the following connectors:
- 2 x 4 pin outputs for the stepper motors
- 2 pin input which can be used for stepper voltage input Vs
- 14 pin header for control – Vs can also be supplied via this header.
It is important that a voltage is applied to VS in order for the L6470 to operate correctly.
The SDI pins are:
MOSI, MISO and CLK.
For Channel A and B:
- CSx – Slave Select A/B
- RSTx – Reset A/B
- FLAGx – Flag A/B
These pins all have 10K pull ups.
Finally we come to code. In order to access the L6470 you need to have SPI initialized. The following code can be placed in your setup() function, it initializes SPI for communication with the L6470.
// Set SPI port modes
// start up SPI
// configure SPI settings for L6470
Once SPI is initialized it is possible to communicate with the L6470.
The easiest method of using dSPIN is to just derive a class from it – this will make it easier to keep track of variable for each controller. The code below initializes a linear stepper – this can be seen from the acceleration and deceleration speed – typically you would ramp up and down depending on the inertia of the system.
There is also a function to move the stepper N steps forward or in reverse depending on the value of the number of steps passed – negative will move the stepper in reverse.
class Stepper: public dSPIN
Stepper(int SSPin, int BusyPin, int ResetPin)
:dSPIN( SSPin, BusyPin, ResetPin)
if( Configure_dSPIN_Controller() != 0 )
Serial.println( F("ERROR configuring dSPIN") );
// Turn the table forward by the specified steps (this does not check to see if the step count was matched)
// Success: Returns 0
// Failure: Returns dSPIN status register
int moveSteps( int iSteps, bool hold )
Move( (iSteps>0) ?FWD:REV, abs(iSteps) );
while( IsBusy() );
int Configure_dSPIN_Controller(bool initial=1)
unsigned long ulMyParam = GetParam(dSPIN_CONFIG);
if ( ulMyParam == 0x2E88 )
// Serial.println("STAT1 Good 0x2E88 (11912d)");
if( __bDebugOutput )
Serial.print(F("\n\nSTAT1 Bad: "));
Serial.println(F("Possibly no communication."));
m_iLastError = GetParam(dSPIN_STATUS); // Store the status flags into the error code
SetParam(dSPIN_STEP_MODE, !dSPIN_SYNC_EN | dSPIN_SYNC_SEL_1);
dSPIN_CONFIG_PWM_DIV_1 | dSPIN_CONFIG_PWM_MUL_2 | dSPIN_CONFIG_SR_290V_us
| dSPIN_CONFIG_OC_SD_ENABLE | dSPIN_CONFIG_VS_COMP_DISABLE
| dSPIN_CONFIG_SW_HARD_STOP | dSPIN_CONFIG_INT_16MHZ);
} // Configure_dSPIN_Controller()
As you can see the most complex portion of setting up your L6470 is selecting the parameters – these can be determined from the datasheet, or trial and error. often it is just a case of decreasing or increasing the acceleration/deceleration profile to get a good response from your stepper motor.
The L6470 dSPIN is a very powerful stepper controller and has the ability to go from 1/128th of a step to full steps. It is also highly configurable to match almost any stepper profile that you need.