Go Down

Topic: Arduino chip as Stepper Controller (Read 12 times) previous topic - next topic

kf2qd

The Arduino chip is inexpensive ($5.50US), which seems to be much cheaper that the PICs.(($30.00US) There is a PIC that has been programmed as a stepper driver - has Step, Direction, Enable, limits, Home and such inputs and 4 outputs for the phases. Basically the 4 pahse outputs tie to 4 transistoer/diodes to drive the stepper motor.

The Arduino would be basically be functioning as an up down counter and outputting to the appropriate digital pin. Patterns for Full Step, Half Step and Wave are easy, don't think the analog outputs would be fast enough for microstepping, but...

Any ideas on how to get eh code fast enough, or is this only for the realm of assembler?

I know it might seem like overkill, but by the time you put the components together it has become hardwasre complex rather than software complex, and software complex is generally easier to change...

Thanks -
Pete

kf2qd

#1
Dec 29, 2011, 11:40 pm Last Edit: Jan 15, 2012, 06:28 pm by kf2qd Reason: 1
Got to thinking about this and came up with some code to test -
Posting it here to see what someone else might think.
Code: [Select]

/*
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;
 }  
}

kf2qd

#2
Dec 30, 2011, 03:26 am Last Edit: Jan 15, 2012, 06:26 pm by kf2qd Reason: 1
Had to make a slight change, now just to see how it works when I hook it up to a computer.
Code: [Select]

/*
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)
 {
 [glow=yellow,2,300]  ctr++;
[/glow]  }
 else
 {
[glow=yellow,2,300]    ctr--;[/glow]
 }
[glow=yellow,2,300]  ctr = ctr  & 3;[/glow]
 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;
 }
}

gharryh

And how do you hook it up to a computer? I dont see any IO going on.

kf2qd

A unipolar stepper driver controller.
At this point Pins 2 & 3 are Step and Direction Inputs. 

Motion programs like Mach3 and other CNC programs provide the step and direction signals, and this would then take those signals and use the outputs to drive the 4 phases of a stepper motor.

There are dedicated chips for doing this, but this would give me more ability to control the function of my stepper controller. THis is just 1:1 stepping, but minor programming would give 2:1 and other ratios could be done by using analog outputs or a device other than a transistor for the final output device.

Go Up