LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-20-2006, 12:33 PM   #1
myrmidon
Member
 
Registered: May 2005
Distribution: redhat 9 , fedora 5,6,7,DSL,Debian 3, mandrake 9.2 , knoppix 3.8, red hat 7.3
Posts: 38

Rep: Reputation: 15
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;

}
 
Old 02-20-2006, 01:16 PM   #2
burntfuse
Member
 
Registered: Sep 2005
Location: Laurel, MD, USA
Distribution: Slackware 10.1, FC5
Posts: 164

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
parallel port mehro Linux - Hardware 5 01-31-2006 06:43 AM
Where is the parallel port? kwyjibo99 Linux - Hardware 5 07-20-2005 05:47 PM
What's using my parallel port?! DiBosco Linux - Hardware 10 06-20-2004 10:18 AM
Parallel Port CD-RW dbrook42 Linux - Hardware 3 09-30-2003 07:54 PM
Parallel Port Crashed_Again Linux - Hardware 1 01-20-2003 08:52 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration