[ myrmidon @ 20.02.2006. 18:42 ] @
Pozdrav svima, evo jedan mali problem sa paralelnim portom i step motorom. Ovaj kod vrti jedan step motor bez problema ali opterecuje CPU 99.99% zbog beskonacne petlje, ako ubacim usleep(1); opterecenje procesora padne na 0.1% ali motor se vrti jaaako sporo. Da li je moguce "uspavati" process da ne jede CPU ali da motor vrti normalnom brzinom ? 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; } |