stepper motor programming.....help me

Status
Not open for further replies.

nuar

Newbie level 2
Joined
Dec 15, 2005
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
hi...
can anybody check my programming...my programming cannot be run...
i dont know what is the error....please check and inform me a.s.a.p..

i suggest, copy my programming and run it in c programming..so u will see clearly my programming...please help me..

kindly help...

p/s : i want to control stepper motor through parallel port


* STEPPER MOTOR MOTION */

#include <stdio.h>
#include <time.h>
#include <dos.h>
#include <conio.h>
#include <process.h>
#include <stdlib.h>



#define Data 0x378
#define outportb(Data,Bits)





void delay(clock_t hundredthsec)
{
clock_t delay, q;

delay = hundredthsec * (CLOCKS_PER_SEC / 100);
q = clock() + delay;

// Delay interval
while (clock() < q);
}


int full_stepping(int,int,int);
int high_torque_stepping(int,int,int);
int half_stepping(int,int,int);

main(void)

{

int speed,steps_mode,direction,rotation,steps;
char yesno;

printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
printf("\n@ @");
printf("\n@ ~ StEPPer MOtoR cONtrol ~ @");
printf("\n@ @");
printf("\n@ @");
printf("\n@ @");
printf("\n@ represent by Shaiful Anwar Ismail @");
printf("\n@ metric no. : KEC 020045 @");
printf("\n@ department : CAD/CAM and Manufacturing @");
printf("\n@ faculty : Engineering @");
printf("\n@ university : University of Malaya @");
printf("\n@ supervisor : Mr. Azuddin Mamat @");
printf("\n@ date : 27 December 2005 @");
printf("\n@ @");
printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");


printf("\n\nControl Motor ? [y/n] :");
scanf("%c",&yesno);

while((yesno!='n')&&(yesno!='N'))
{


printf("\n\nStepper Motor requires 48 steps per revolution");
printf("\nso 1 step = 7.5 degrees");


printf("\nplease set the delay between signal ( 1 for fast,5 for slow ) :");
scanf("%d",&speed);


while(speed<1||speed>5)
{
printf("\n\nplease enter the right number :");
scanf("%d",&speed);
}

printf("\nplease choose type of steps mode");
printf("\n 1 for full stepping");
printf("\n 2 for high torque stepping");
printf("\n 3 for half stepping");
printf("\n what is your selection : ");
scanf("%d",&steps_mode);

while(steps_mode<1||steps_mode>3)
{
printf("please enter the right number :");
scanf("%d",direction);
}




if(steps_mode==1)
{
printf("\n\nYour selection is full stepping mode");
full_stepping(direction,steps,speed);
}

else if(steps_mode==2)
{
printf("\n\nYour selection is high torque stepping mode");
high_torque_stepping(direction,steps,speed);
}

else if(steps_mode==3)
{
printf("\n\nYour selection is half stepping mode");
half_stepping(direction,steps,speed);
}

else
{
printf("\n\please enter the right number :");
scanf("%d",&steps_mode);
}
}



printf("\nQuitting........");
printf("\nThank You");
exit (0);
}




int full_stepping(int direction,int steps,int speed)
{

int rotation;

printf("\n\nplease set number of rotation :");
scanf("%d",rotation);

steps = 12 * rotation;

printf("\nplease choose the direction for stepper motor");
printf("\nclockwise = 1 or counterclockwise = 0");
printf("\nwhat is your selection :");
scanf("%d",direction);

while((direction!=0)&&(direction!=1))
{
printf("please enter the right number :");
scanf("%d",direction);
}

if(direction==1)
{
int k=1;

printf("\n Start rotating.....clockwise direction");

for(int z=0;z<steps;z++)
{
{
for (int a=0;a<1;a++)
delay(speed);
outportb(0x378,a);
{
for (int b=0;b<2;b++)
delay(speed);
outportb(0x378,;
{
for (int d=0;d<4;d++)
delay(speed);
outportb(0x378,d);
{
for (int f=0;f<8;f++)
delay(speed);
outportb(0x378,f);
}

}
}
}
}

printf("\nEnd rotation.....\n");
return 0;
}

else
{
int k=1;

printf("\n Start rotating.....counterclockwise direction");

for(int z=0;z<steps;z++)
{
{
for (int f=0;f<8;f++)
delay(speed);
outportb(0x378,f);
{
for (int d=0;d<4;d++)
delay(speed);
outportb(0x378,d);
{
for (int b=0;b<2;b++)
delay(speed);
outportb(0x378,;
{
for (int a=0;a<1;a++)
delay(speed);
outportb(0x378,a);
}

}
}
}
}

printf("\nEnd rotation.....\n");
return 0;
}
}

int high_torque_stepping(int direction,int steps,int speed)
{

int rotation;

printf("\n\nplease set number of rotation :");
scanf("%d",rotation);

steps = 12 * rotation;

printf("\nplease choose the direction for stepper motor");
printf("\nclockwise = 1 or counterclockwise = 0");
printf("\nwhat is your selection :");
scanf("%d",direction);


while((direction!=0)&&(direction!=1))
{
printf("please enter the right number :");
scanf("%d",direction);
}



if(direction==1)
{
int k=1;

printf("\n Start rotating.....clockwise direction");

for(int z=0;z<steps;z++)
{
{
for (int c=0;c<3;c++)
delay(speed);
outportb(0x378,c);
{
for (int e=0;e<6;e++)
delay(speed);
outportb(0x378,e);
{
for (int h=0;h<12;h++)
delay(speed);
outportb(0x378,h);
{
for (int g=0;g<9;g++)
delay(speed);
outportb(0x378,g);
}

}
}
}
}

printf("\nEnd rotation.....\n");
return 0;
}

else
{
int k=1;

printf("\n Start rotating.....counterclockwise direction");

for(int z=0;z<steps;z++)
{
{
for (int g=0;g<9;g++)
delay(speed);
outportb(0x378,g);
{
for (int h=0;h<12;h++)
delay(speed);
outportb(0x378,h);
{
for (int e=0;e<6;e++)
delay(speed);
outportb(0x378,e);
{
for (int c=0;c<3;c++)
delay(speed);
outportb(0x378,c);
}

}
}
}
}

printf("\nEnd rotation.....\n");
return 0;
}
}

int half_stepping(int direction,int steps,int speed)
{

int rotation;

printf("\n\nplease set number of rotation :");
scanf("%d",rotation);

steps = 12 * rotation;


printf("\nplease choose the direction for stepper motor");
printf("\nclockwise = 1 or counterclockwise = 0");
printf("\nwhat is your selection :");
scanf("%d",direction);


while((direction!=0)&&(direction!=1))
{
printf("please enter the right number :");
scanf("%d",direction);
}



if(direction==1)
{
int k=1;

printf("\n Start rotating.....clockwise direction");

for(int z=0;z<steps;z++)
{
{
for (int a=0;a<1;a++)
delay(speed);
outportb(0x378,a);
{
for (int c=0;c<3;c++)
delay(speed);
outportb(0x378,c);
{
for (int b=0;b<2;b++)
delay(speed);
outportb(0x378,;
{
for (int e=0;e<6;e++)
delay(speed);
outportb(0x378,e);
{
for (int d=0;d<4;d++)
delay(speed);
outportb(0x378,d);
{
for (int h=0;h<12;h++)
delay(speed);
outportb(0x378,h);
{
for (int f=0;f<8;f++)
delay(speed);
outportb(0x378,f);
{
for (int g=0;g<9;g++)
delay(speed);
outportb(0x378,g);
}
}
}
}
}
}
}
}
}

printf("\nEnd rotation.....\n");
return 0;
}

else
{
int k=1;

printf("\n Start rotating.....clockwise direction");

for(int z=0;z<steps;z++)
{
{
for (int g=0;g<9;g++)
delay(speed);
outportb(0x378,g);
{
for (int f=0;f<8;f++)
delay(speed);
outportb(0x378,f);
{
for (int h=0;h<12;h++)
delay(speed);
outportb(0x378,h);
{
for (int d=0;d<4;d++)
delay(speed);
outportb(0x378,d);
{
for (int e=0;e<8;e++)
delay(speed);
outportb(0x378,f);
{
for (int b=0;b<2;b++)
delay(speed);
outportb(0x378,;
{
for (int c=0;c<3;c++)
delay(speed);
outportb(0x378,c);
{
for (int a=0;a<1;a++)
delay(speed);
outportb(0x378,a);
}
}
}
}
}
}
}
}
}

printf("\nEnd rotation.....\n");
return 0;
}
}
 

violation of ANSI: there's no conio.h. AFAIK, this exists only on windoze/dos machines.
as for the program: eh, outportb() macro expands to nothing.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…