Introduction
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.

Dual Stepper Control interface
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.
Initializing L6470
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
// Set SPI port modes pinMode(MOSI, OUTPUT); pinMode(MISO, INPUT); pinMode(SCK, OUTPUT); // start up SPI SPI.begin(); // configure SPI settings for L6470 SPI.setBitOrder(MSBFIRST); SPI.setClockDivider(SPI_CLOCK_DIV4); SPI.setDataMode(SPI_MODE3); |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
class Stepper: public dSPIN { public: 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 ) { GetStatus(); Move( (iSteps>0) ?FWD:REV, abs(iSteps) ); while( IsBusy() ); if(hold) HardStop(); else HardHiZ(); CHECK_FOR_dSPIN_ERROR_AND_RETURN } protected: int m_iLastError; int Configure_dSPIN_Controller(bool initial=1) { unsigned long ulMyParam = GetParam(dSPIN_CONFIG); if ( ulMyParam == 0x2E88 ) { // Serial.println("STAT1 Good 0x2E88 (11912d)"); } else { if(!initial) return 0; if( __bDebugOutput ) { Serial.print(F("\n\nSTAT1 Bad: ")); Serial.println(ulMyParam); Serial.println(F("Possibly no communication.")); } m_iLastError = GetParam(dSPIN_STATUS); // Store the status flags into the error code if(!m_iLastError) m_iLastError=-1; return m_iLastError; } SetParam(dSPIN_STEP_MODE, !dSPIN_SYNC_EN | dSPIN_SYNC_SEL_1); SetParam(dSPIN_MAX_SPEED, MaxSpdCalc(500)); SetParam(dSPIN_FS_SPD, FSCalc(100)); SetParam(dSPIN_ACC, AccCalc(0xfff)); SetParam(dSPIN_DEC, AccCalc(0xfff)); SetParam(dSPIN_OCD_TH, dSPIN_OCD_TH_6000mA); SetParam(dSPIN_CONFIG, 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); GetStatus(); HardHiZ(); CHECK_FOR_dSPIN_ERROR_AND_RETURN } // 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.
Conclusion
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.