Finally can say I have an ATMel chip - the ATtiny2313 functioning as a stepper driver.
I got it working in Arduino, the assembler version still has some strange behavious (and the assembler version of the code is hareder to troubleshoot in hardware. In the Simulator it works just fine, but in hardware.....
Here's the Arduino version.
By my count it will run in excess of 140RPM running in Half Step mode when driven by a simple Arduino program.
/*
Step & Direction Stepper Driver
Pins 8, 9, 10, 11 are tied to transistors
for each of the motor phases.
Pins 2 is used as interruptfor the steps
and 3 is the Direction.
*/
// the following 3 arrays contain the bit patterns to drive the transistors
// to in turn drive each of the phases of the stepper
int patSimple[] = {
B0011,B0010, B0100, B1000, B0001, B0010, B0100, B1000};
int patWave[] = {
B0011, B0110, B1100, B1001, B0011, B0110, B1100, B1001};
int patHalf[] = {
B0001, B0011, B0010, B0110, B0100, B1100, B1000, B1001};
int pinDir = 5;
volatile int ctr;
volatile int dir;
void setup()
{
DDRB = B1111 ; // this enables Port B Bits 0 - 3, Arduino I/O 8, 9, 10, 11 as outputs
pinMode(pinDir, INPUT);
ctr=0;
dir = 0;
attachInterrupt(0, Step, FALLING); // Depending on the application FALLING might be a better choice.
}
void loop()
{
// Nothing to see here...
}
void Step()
{
if (digitalRead(5))
{
ctr++ ;
}
else
{
ctr-- ;
}
ctr = ctr & 7;
// 2 of the following 3 lines must be commented.
// PORTB = patsimple[ctr]; // Simple Stepping
// PORTB = patWave[ctr]; // Wave Stepping
PORTB = patHalf[ctr]; // Half Stepping
}
And I was testing it with code that looks like this in my Arduino-
int steps;
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(3,HIGH);
}
void loop() {
for (steps=0;steps<400;steps++)
{
digitalWrite(2, HIGH); // set the LED on
digitalWrite(2, LOW); // set the LED off
delay(1); // wait for a second
}
}
Still want to crack the assembly code...