Home Programmering Step motor kontroller - C programmet
Step motor kontroller - C programmet PDF Skriv ut E-post
Skrevet av Jens Christoffersen   
fredag 18. september 2009 20:30
Artikkelindeks
Step motor kontroller
Komponenter
C programmet
Verdien som sendes
Video
Alle sider

 

C programmet som styrer dette.

Denne listingen gjør at 2 unipolar stepmotorer snurrer noen runder den ene veien, for så å snurre like mange ganger den andre veien. Det kan sikkert med fordel gjøres på en annen måte, men denne har jeg valgt.

 

Kompileres med gcc -O 2stepmotor.c -o 2stepmotor

Kjøres med kommandoen sudo ./2stepmotor

 

 

/****************************************************
* Program som styrer to steppermotorer synkronisert *
* Laget av Jens Christoffersen                      *
* 2009                                              *
*****************************************************/
//includes
#include
#include
#include
#include
#include

//definitions
#define base 0x3bc
#define sleeping1 7000    // by changeing this, you change the speed og the motor.

//variables
int x;


main(int argc, char **argv)
{
// get access to the parallel port
if (ioperm(base,1,1))
fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);

// send low, to all pins
outb(0, base);

// start infinit loop
while (1)
{

// start for - loop
for (x=0;x<48;x++)
{
// start sending high nad low to pins start with all pins to low
outb(0, base);
// send high to pin 2 and 4
outb(5, base);
printf ("Pin \t2 and 4 high and \t3 and 5 low.\n");
usleep(sleeping1);

// send low to all pins
outb(0, base);
printf ("Pin \t2 and 4 low and \t3 and 5 low.\n");
usleep(sleeping1);

// send hig to pin 3 and 5
outb(10, base);
printf ("Pin \t2 and 4 low and \t3 and 5 high .\n");
usleep(sleeping1);

// send low to all pins
outb(0, base);   
//send high til pind 2, 3, 4 and 5
outb(15, base);
printf ("Pin \t2 and 4 high and \t3 and 5 high.\n");
usleep(sleeping1);
} // end for loop

// start new for loop
for (x=0;x<48;x++)
{
// do everything again, just the other way around.
outb(0, base);   
outb(15, base);
printf ("Pin \t2 and 4 high and \t3 and 5 high.\n");
usleep(sleeping1);

outb(0, base);
outb(10, base);
printf ("Pin \t2 and 4 low and \t3 and 5 high .\n");
usleep(sleeping1);

outb(0, base);
printf ("Pin \t2 and 4 low and \t3 and 5 low.\n");
usleep(sleeping1);

outb(0, base);
outb(5, base);
printf ("Pin \t2 and 4 high and \t3 and 5 low.\n");
usleep(sleeping1);

} // end for loop


} // end infinite loop

// send low to all pins
outb(0, base);
}

 

 



Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:):(:0:shock::confused:8):lol::x:P:oops::cry:
:evil::twisted::roll::wink::!::?::idea::arrow:
Sist oppdatert tirsdag 04. mai 2010 10:49
 
Kopirett © 2010 nerdegutta.org. Alle rettigheter reservert.
Joomla! er fri programvare utgitt under GNU/GPL License.