LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Stepper motor and parallel port (https://www.linuxquestions.org/questions/programming-9/stepper-motor-and-parallel-port-417630/)

myrmidon 02-20-2006 12:33 PM

Stepper motor and parallel port
 
Hi to all!

I'm writing some code for controlling the stepper motor via lpt:


Now the problem is: when i comment the usleep line the stepper motor run extra fine BUT the CPU usage boost up to 99.99%.

If i remove the comment from usleep line the stepper motor runs veery slow but the CPU usage drops to 0.0%.


Can i pause my process for a veery small amount of time to not to boost the CPU usage up to 99% and to remain the motors speed normal ??




Code :




#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>


#define BASEPORT 0x378 /*lpt0*/


int *spin_wheel(int *current_step, int *start_step)
{

outb(*current_step,BASEPORT);



if (*current_step==*(start_step+3))
current_step=start_step;
else
current_step++;

return current_step;

}



int main()
{
// Duo phase
int steps[]={3,6,12,9};

int *current,*pocetni;

current=steps;
pocetni=steps;

/* open port */
if (ioperm(BASEPORT,3,1))
{
perror("ioperm");

exit(1);
}


outb(0,BASEPORT);


while(1)
{

current=spin_wheel(current,pocetni)

/*

usleep(1);

*/


}


return 0;

}

burntfuse 02-20-2006 01:16 PM

As a last resort, you could try an empty for loop that counts up to some large number (experiment with values), although it's a sort of messy hack, and it will act completely different if used on other machines.


All times are GMT -5. The time now is 09:45 AM.