Some code for SMCC stepper driver

We have been playing with the Arduino and the SMCC (V2) stepper driver board. Here is what we have; full step, half step and wave drive. It provides for emergency stop, "status OK" LED, and reads limit switch. One Arduino per axis using this design I'm afraid but that works for us as we're using different motors (and therefore different settings) for each. Also allows the opportunity to "play" with settings. Inputs are Clock and Direction only to suit most software products.

It is too long to display here, but is available from our website here: http://ipresources.com/Stepper_SMCC.pde

// Begin copyright notice /************************************************ /* Bipolar stepper driver using SMCC /* Single axis with limit switch /* /* Version # 1.0 /* for the Arduino 168 platform /* (c) IPResources.com /* /* Set the direction, then clock the ClockPin to /* advance the stepper. /* Has the facility to report digital status, /* provides for two LED's (OK & Error), and /* reads the limit switch (active HIGH). /* /* Distribution in source form and free use permitted /* as long as this entire copyright notice remains /* unchanged /* /***************************************************************************************/ / sig OK | ERR | HLS | STA | DIR | CK | IND | INC | INB | INA | EN2 | EN1 | not used /* Data D13 | D12 | D11 | D10 | D9 | D8 | D7 | D6 | D5 | D4 | D3 | D2 | serial /* pins 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | /****************************************************************************************/ // End copyright notice

// Inputs int ClockPin = 8; // Pin that is clocked to move the stepper int DirPin = 9; // Pin that provides the direction signal int HardLimitSwitch = 11; // Wire the hard limit switch to here, or strap it to +5V // Feedback int StatusOutput = 10; // This pin will be pulled LOW by the Arduino in case of error // LED's int ErrStatusLed = 12; // Red LED to pin 12 int OKStatusLed = 13; // Green LED to pin 13

int EverythingOff = 0; // Turns power off in case of error int Index; // Index into array int StepValue; // Step value to store

// Give enum values to type of stepping that we want to achieve int WAVE = 0; int HALFSTEP = 1; int FULLSTEP = 2;

// Select one of the three below. If you select more, the last one will win... int StepType = WAVE; // Set step type to wave drive //int StepType = HALFSTEP; // Set step type to half step //int StepType = FULLSTEP; // Set step type to full step

boolean SysStatus; // Current System status boolean Direction; // Current direction boolean oldDirection; // Previous direction boolean Clockwise = LOW; // Clockwise value = DirPin LOW boolean DebugIsOn = false; // You'll probably only want to do this with a manual clock switch... boolean SysOK = 1; // System status OK boolean SysErr = 0; // System status ERROR

byte REVERSE[] = { 7,6,5,4,3,2,1,0};

//set up binary patterns for steps

// WAVE drive

byte WAVE_Clockwise[] = { B10001000, //Step 2 B00010100, //Step 4 B01001000, //Step 6 B00100100, //Step 8 B10001000, //Step 2 B00010100, //Step 4 B01001000, //Step 6 B00100100 //Step 8 }; byte WAVE_CounterClockwise[] = { B00100100, //Step 8 B01001000, //Step 6 B00010100, //Step 4 B10001000, //Step 2 B00100100, //Step 8 B01001000, //Step 6 B00010100, //Step 4 B10001000 //Step 2 };

//set up half step pattern // ONE-TWO-Excitation

byte HALFSTEP_Clockwise[] = { B10101100, // Step-1 B10001000, // Step-2 B10011100, // Step-3 B00010100, // Step-4 B01011100, // Step-5 B01001000, // Step-6 B01101100, // Step-7 B00100100 // Step-8 }; byte HALFSTEP_CounterClockwise[] = { B00100100, // Step-8 B01101100, // Step-7 B01001000, // Step-6 B01011100, // Step-5 B00010100, // Step-4 B10011100, // Step-3 B10001000, // Step-2 B10101100 // Step-1 }; //set up half step pattern // ONE-TWO-Excitation

byte FULLSTEP_Clockwise[] = { B10101100, // Step-1 B10011100, // Step-2 B01011100, // Step-3 B01101100, // Step-4 B10101100, // Step-5 B10011100, // Step-6 B01011100, // Step-7 B01101100 // Step-8 }; byte FULLSTEP_CounterClockwise[] = { B01101100, // Step-8 B01011100, // Step-7 B10011100, // Step-6 B10101100, // Step-5 B01101100, // Step-4 B01011100, // Step-3 B10011100, // Step-2 B10101100 // Step-1 };

void setup(void) {

// Configure the direction registers cfgDDR();

//start with the first step Index = 0;

//set the current direction flag oldDirection = digitalRead(DirPin);

// All systems go SystemStatus(SysOK);

// If debugging, talk to the serial port if (DebugIsOn) { Serial.begin(9600); Serial.println("Serial debug for SMCC stepper module enabled @ 9600 Baud."); }