Got to thinking about this and came up with some code to test -
Posting it here to see what someone else might think.
/*
Step & Direction Stepper Driver
Pins 9, 10, 11, 12 are tied to transistors
for each of the motor phases.
Pins 2 & 3 are used as interrupts,
Pin 2 as Step and 3 as Direction.
*/
int pin1 =9;
int pin2 = 10;
int pin3 = 11;
int pin4 = 12;
int pinDir = 3;
volatile int ctr;
volatile int dir;
void setup()
{
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pinDir, INPUT);
ctr=0;
dir = 0;
attachInterrupt(0, Step, RISING);
attachInterrupt(1, Direction, CHANGE);
}
void loop()
{
}
void Step()
{
if (dir)
{
ctr++ & 3;
}
else
{
ctr-- & 3;
}
switch (ctr){
case 0:
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
break;
case 1:
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
break;
case 2:
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,LOW);
break;
case 3:
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,HIGH);
break;
}
}
void Direction()
{
if ( digitalRead(pinDir) )
{
dir = 0;
}
else
{
dir=-1;
}
}