Controlling a stepper motor with c language in RTLInux

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View

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.....

in non-real-time the motor works 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


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

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


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

==========================non-real-time-linux c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/io.h>

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


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

        outb(0x01, base);
    outb(0x03, base);
    outb(0x02, base);
    outb(0x06, base);
    outb(0x04, base);
    outb(0x0c, base);
    outb(0x08, base);
    outb(0x09, base);


=============================rtlinux program========================
#include <linux/module.h>
#include <linux/kernel.h>
#include <rtl_time.h>
#include <rtl_sched.h>
#include <asm/io.h>
#include <time.h>
#include "common.h"

int period10%00000000;
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){
        one = ~one;

        two = ~two;

        three = ~three;

        four = ~four;

        five = ~five;

        six = ~six;

        seven = ~seven;

        eight = ~eight;



    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;

    pthread_delete_np (thread);


Re: Controlling a stepper motor with c language in RTLInux

Quoted text here. Click to load it

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

Site Timeline