how can i drive 3 steppers at once?

im trying to build a sort of cnc style machine and i need to drive 3 stepper motors simultaneously in varying directions and distances. right now i have them set up using an arduino mega and an l293d driver circuit but when i drive one motor it delays the entire program until the motor has completed its steps. how can i drive them all at once? thanks

It sounds like the structure of your software is "command movement -- wait for it to finish". If you want the appearance of parallel behavior in the motors you have to write more complicated software.

Another, possibly easier, solution is to simply use three Arduinos. This is a pretty common way of implementing 3-axis control: a separate controller+driver for each axis. Then you just have to either have a master controller to send them commands or designate one of them the master and get them to talk to each other over SPI or I2C/TWI.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

Look up the RepRap page that has an example of what you want to do.

http://reprap.org/wiki/Main_Page

It is simply a matter of writing your code correctly.
You work out how many steps you need on each motor to get to where you want to go. The motor with the biggest number of steps you pulse every time. The others will have a fraction of a step every time, this is of course impossible but you keep a float variable incrementing the fractions. When the integer part of this variable changes you then give that motor a pulse. In that way the motor with the furthest to go is running the fastest and the other motors are running slower and they all get to where they are going at the same time.

If you want to do it more efficiently than having floating point operations then look up Bresenham's line algorithm.

use three Arduinos. This is a pretty common way of implementing 3-axis control

I've never seen this, it seems such a waste and a potential headache in getting the speed of three motors to all finish their movements at exactly the same time. Just try drawing a circle with two independent controllers!

im still having problems getting it to work. sure it does work, but its EXTREMELY slow! the program that should be taking microseconds to run is taking SECONDS. im running it in a while loop and just making each motor step when its integer changes as i incrementally change the time during each cycle. any suggestions? or better yet, an example

any suggestions?

Post the code, otherwise we are just guessing at what mistakes you have made. Maybe you didn't understand the method correctly.

oh sorry i thought i had included it. well here it is anyhow. ive tried to lable things but the programs still kinda ugly because it has all my math code in it too

#include <Stepper.h>

#define STEPS 200
Stepper steppera(STEPS, 0, 1, 2, 3); //stepper pins
Stepper stepperb(STEPS, 4, 5, 6, 7);
Stepper stepperc(STEPS, 8, 9, 10, 11);

float side = 12; //base dimensions
float radius = 12;
float bottom = 3.464102;
float o = 0;

float pcirc = 0.618423752;
float ax = 0 - ((side)/2); //sphere x and y coordinates
float ay = 0 - 3.464102;
float az = 0;
float bx = (side)/2;
float by = ay;
float bz = 0;
float cx = 0;
float cy = radius/2;
float cz = 0;
int faz = 0; //integral z value
int fbz = 0;
int fcz = 0;
float det = 0; //most steps
int paz = 0; //past steps
int pbz = 0;
int pcz = 0;

float deta = 0; //speed determinates
float detb = 0;
float detc = 0;
int rpm = 60;
float sps = 1000/((rpm/60)*200);
float difa = 0; //step difference
float difb = 0;
float difc = 0;
int waz = 0; //written steps
int wbz = 0;
int wcz = 0;
int dira = 0; //motor direction
int dirb = 0;
int dirc = 0;

int time = 0; //time monitoring integers
int pwaz = 0;
int pwbz = 0;
int pwcz = 0;

float ex = -2; //calculated z values
float ey = 4;
float ez = -15;

int test = 0;

void setup()
{
steppera.setSpeed(rpm); //sets initial speed
stepperb.setSpeed(rpm);
stepperc.setSpeed(rpm);

Serial.begin(9600);

pinMode(13, OUTPUT);
}

void loop()
{ //math
float circlea = (pow(ex-ax, 2)) + (pow(ey-ay, 2)) - (pow(radius, 2));
float circleb = (pow(ex-bx, 2)) + (pow(ey-by, 2)) - (pow(radius, 2));
float circlec = (pow(ex-cx, 2)) + (pow(ey-cy, 2)) - (pow(radius, 2));

float a = 1;
float b = 2*ez;
float ac = (pow(ez, 2))+circlea ;
float bc = (pow(ez, 2))+circleb ;
float cc = (pow(ez, 2))+circlec ;

az = -(((-b)-sqrt(pow(b, 2)-(4ac)))/2a);
bz = -(((-b)-sqrt(pow(b, 2)-(4bc)))/2a);
cz = -(((-b)-sqrt(pow(b, 2)-(4cc)))/2a);

faz = (az/pcirc)*200;
fbz = (bz/pcirc)*200;
fcz = (cz/pcirc)*200;

Serial.print(" az= "); //serial test values
Serial.print(az, 6);
Serial.print(" bz= ");
Serial.print(bz, 6);
Serial.print(" cz= ");
Serial.print(cz, 6);
Serial.print(" test= ");
Serial.println(test) ;

det = faz; //finds which motor moves the farthest
if(faz < fbz) det = fbz;
if(det < fcz) det = fcz;

deta = faz/det; //finds neccisarry speed of each motor
detb = fbz/det;
detc = fcz/det;

difa = faz - paz; //finds difference in present and past steps
difb = fbz - pbz;
difc = fcz - pcz;

if(difa < 0) { //finds direction of each motor
dira = -1;
}
else {
dira = 1;
}

if(difb < 0) {
dirb = -1;
}
else {
dirb = 1;
}

if(difc < 0) {
dirc = -1;
}
else {
dirc = 1;
}

while(difa != waz and difb != wbz and difc != wcz) { //writes to motors
test = test+1;

waz = ((time/(spsdeta))-pwaz); //finds if enough time has passed for a step
wbz = ((time/(sps
detb))-pwaz);
wcz = ((time/(sps*detc))-pwaz);

if(difa != waz){ //fail-safe write
steppera.step(waz*dira);
}

if(difb != wbz){
stepperb.step(wbz*dirb);
}

if(difc != wcz){
stepperc.step(wcz*dirc);
}

Serial.print("t- ");
Serial.print(difa);
Serial.print(" a- "); //print values
Serial.print(pwazdira);
Serial.print(" etd- ");
Serial.print(((pwaz
dira)/200)3.14159);
Serial.print(" b- ");
Serial.print(pwbz
dirb);
Serial.print(" etd- ");
Serial.print(((pwbzdirb)/200)3.14159);
Serial.print(" c- ");
Serial.print(pwcz
dirc);
Serial.print(" etd- ");
Serial.print(((pwcz
dirc)/200)*3.14159);
Serial.print(" tm- ");
Serial.println(time) ;

time = time+1; //add to clock
pwaz = pwaz+waz; //add number of steps written
pwbz = pwbz+wbz;
pwcz = pwcz+wcz;

}

digitalWrite(13, HIGH);

delay(1000);
digitalWrite(13, LOW);

paz = faz; //set previous values
pbz = fbz;
pcz = fcz;

time = 0; //time reset
pwaz = 0;
pwbz = 0;
pwcz = 0;

}

Try and use the # button not the quote one.

No wonder it is taking such a long time you are including all your calculations every time you go round the loop. Sort out those you only need to make once at the start and call them in the setup. Don't define your variables in the loop unless they are going to change.
You see every time round the loop you calculate:-
float circlea = (pow(ex-ax, 2)) + (pow(ey-ay, 2)) - (pow(radius, 2));
There is simply no need.

i actually just found an error so he is the corrected code

and the calculations must be included as a couple of variables will change nearly everytime. think cnc machine with changing coordinates.
however the calculations dont affect the stepper motors turning seeing as theyre in the while loop

#include <Stepper.h>

#define STEPS 200
Stepper steppera(STEPS, 0, 1, 2, 3); //stepper pins
Stepper stepperb(STEPS, 4, 5, 6, 7);
Stepper stepperc(STEPS, 8, 9, 10, 11);

float side = 12; //base dimensions
float radius = 12;
float bottom = 3.464102;
float o = 0;

float pcirc = 0.618423752;
float ax = 0 - ((side)/2); //sphere x and y coordinates
float ay = 0 - 3.464102;
float az = 0;
float bx = (side)/2;
float by = ay;
float bz = 0;
float cx = 0;
float cy = radius/2;
float cz = 0;
int faz = 0; //integral z value
int fbz = 0;
int fcz = 0;
float det = 0; //most steps
int paz = 0; //past steps
int pbz = 0;
int pcz = 0;

float deta = 0; //speed determinates
float detb = 0;
float detc = 0;
int rpm = 60;
float sps = 1000/((rpm/60)*200);
float difa = 0; //step difference
float difb = 0;
float difc = 0;
int waz = 0; //written steps
int wbz = 0;
int wcz = 0;
int dira = 0; //motor direction
int dirb = 0;
int dirc = 0;

int time = 0; //time monitoring integers
int pwaz = 0;
int pwbz = 0;
int pwcz = 0;

float ex = -2; //calculated z values
float ey = 4;
float ez = -15;

int test = 0;

void setup()
{
steppera.setSpeed(rpm); //sets initial speed
stepperb.setSpeed(rpm);
stepperc.setSpeed(rpm);

Serial.begin(9600);

pinMode(13, OUTPUT);
}

void loop()
{ //math
float circlea = (pow(ex-ax, 2)) + (pow(ey-ay, 2)) - (pow(radius, 2));
float circleb = (pow(ex-bx, 2)) + (pow(ey-by, 2)) - (pow(radius, 2));
float circlec = (pow(ex-cx, 2)) + (pow(ey-cy, 2)) - (pow(radius, 2));

float a = 1;
float b = 2*ez;
float ac = (pow(ez, 2))+circlea ;
float bc = (pow(ez, 2))+circleb ;
float cc = (pow(ez, 2))+circlec ;

az = -(((-b)-sqrt(pow(b, 2)-(4ac)))/2a);
bz = -(((-b)-sqrt(pow(b, 2)-(4bc)))/2a);
cz = -(((-b)-sqrt(pow(b, 2)-(4cc)))/2a);

faz = (az/pcirc)*200;
fbz = (bz/pcirc)*200;
fcz = (cz/pcirc)*200;

Serial.print(" az= "); //serial test values
Serial.print(az, 6);
Serial.print(" bz= ");
Serial.print(bz, 6);
Serial.print(" cz= ");
Serial.print(cz, 6);
Serial.print(" test= ");
Serial.println(test) ;

det = faz; //finds which motor moves the farthest
if(faz < fbz) det = fbz;
if(det < fcz) det = fcz;

deta = faz/det; //finds neccisarry speed of each motor
detb = fbz/det;
detc = fcz/det;

difa = faz - paz; //finds difference in present and past steps
difb = fbz - pbz;
difc = fcz - pcz;

if(difa < 0) { //finds direction of each motor
dira = -1;
}
else {
dira = 1;
}

if(difb < 0) {
dirb = -1;
}
else {
dirb = 1;
}

if(difc < 0) {
dirc = -1;
}
else {
dirc = 1;
}

while(difa != pwaz and difb != pwbz and difc != pwcz) { //writes to motors
test = test+1;

waz = ((time/(spsdeta))-pwaz); //finds if enough time has passed for a step
wbz = ((time/(sps
detb))-pwaz);
wcz = ((time/(sps*detc))-pwaz);

if(difa != waz){ //fail-safe write
steppera.step(waz*dira);
}

if(difb != wbz){
stepperb.step(wbz*dirb);
}

if(difc != wcz){
stepperc.step(wcz*dirc);
}

Serial.print("t- ");
Serial.print(difa);
Serial.print(" a- "); //print values
Serial.print(pwazdira);
Serial.print(" etd- ");
Serial.print(((pwaz
dira)/200)3.14159);
Serial.print(" b- ");
Serial.print(pwbz
dirb);
Serial.print(" etd- ");
Serial.print(((pwbzdirb)/200)3.14159);
Serial.print(" c- ");
Serial.print(pwcz
dirc);
Serial.print(" etd- ");
Serial.print(((pwcz
dirc)/200)*3.14159);
Serial.print(" tm- ");
Serial.println(time) ;

time = time+1; //add to clock
pwaz = pwaz+waz; //add number of steps written
pwbz = pwbz+wbz;
pwcz = pwcz+wcz;

}

digitalWrite(13, HIGH);

delay(1000);
digitalWrite(13, LOW);

paz = faz; //set previous values
pbz = fbz;
pcz = fcz;

time = 0; //time reset
pwaz = 0;
pwbz = 0;
pwcz = 0;

}

Please please use the hash key when posting code.

Remove all the debug printing from the stepping loop that is killing you.

sorry, i just used the copy for forum option

and i thought the same thing too so i replaced it with the led function so i could still have a visual but it still takes absolutely forever

When you post code you should only post code that shows the problem.

So looking again I see you are handling time in a very odd way. You are just using a loop counter. This means that the motor's perception of time it totally dependent on how many stepping motors stepped. Replace the incrementing of time with the value you get from the elapsed timer millis();.
Also you are using a stepping library and you don't know what that does.