Controlling a stepper motor with c language in RTLInux

hello there, i am new to this group.....i am working on a simple project " Controlling a stepper motor in real time linux". actually i am a student of undergrad....fact is with the help of google....i am able to run the motor from both non-real time linux and rtlinux.....

Problem: ======= in non-real-time the motor works fine....it gives full 360 degree rotation with 5 - 7 degree each pulse......with rtlinux for eight step it gives same result like non-real-time but after step eight means end of while loop the motor rotate back at least 20 degree....i dont no what to do....can any one help me understand what is happening here.....

note: ===

if i use only one pthread_wait_np(); after step eight.....and disable other.....it gives 27-30 degree rotation per pulse and never rotate back and finish 360 degree.....

i tried my best to present my problem....

Thanks.

stepper motor driver ckt i am using ULN2003 , both programs ( linux and rtlinux) are following:

==========================non-real-time-linux c program================== #include #include #include #include #include

#define base 0x378 /* printer port base address */

main() {

if (ioperm(base,1,1)) fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit (1);

while(1){ outb(0x01, base); sleep(1); outb(0x03, base); sleep(1); outb(0x02, base); sleep(1); outb(0x06, base); sleep(1); outb(0x04, base); sleep(1); outb(0x0c, base); sleep(1); outb(0x08, base); sleep(1); outb(0x09, base); sleep(1); }

} =================================End==============================

=============================rtlinux program======================== #include #include #include #include #include #include #include "common.h"

int period=1000000000; int periodic_mode=0;

int one=0x01; int two=0x03; int three=0x02; int four=0x06; int five=0x4; int six=0x0c; int seven=0x08; int eight=0x09;

pthread_t thread;

void * bit_toggle(void *t) { pthread_make_periodic_np(thread, gethrtime(), period);

while (1){ outb(one,LPT); one = ~one; pthread_wait_np();

outb(two,LPT); two = ~two; pthread_wait_np();

outb(three,LPT); three = ~three; pthread_wait_np();

outb(four,LPT); four = ~four; pthread_wait_np();

outb(five,LPT); five = ~five; pthread_wait_np();

outb(six,LPT); six = ~six; pthread_wait_np();

outb(seven,LPT); seven = ~seven; pthread_wait_np();

outb(eight,LPT); eight = ~eight; pthread_wait_np();

} }

init_module(void) { pthread_attr_t attr; struct sched_param sched_param;

pthread_attr_init (&attr); sched_param.sched_priority = 1; pthread_attr_setschedparam (&attr, &sched_param); pthread_create (&thread, &attr, bit_toggle, (void *)0);

return 0; }

void cleanup_module(void) { pthread_delete_np (thread); }

================================End=============================

Reply to
evan
Loading thread data ...

..

..

..

Why do you invert the value of 'one' (and 'two', 'three' etc) after using it? You do not appear to do a similar operation in your non-rtlinux program.

Reply to
srl100

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.