- From: Ong Wee Liat <g0202550_at_nus.edu.sg>
- Date: Sun, 1 Aug 2004 16:53:34 +0800
Hi All,
I have coded a little program to output a periodic digital pulses to run in LXRT. As LXRT has rt_make_soft_real_time() and rt_make_hard_real_time(), i have tried to compare the "reliability" by checking the frequency of the digital pulses through an oscilloscope.
However to my surprise, under the soft realtime option, the output on my oscilloscope is stable up to 10kHz, whereas under the hard realtime option, the output starts to produce "unstable" waveform at a low freqency of 500Hz!!!
I suspect that my code has not fully utilised the hard realtime option but i do not know what is wrong. Can anyone help me to take a look? I am using rtai-24.1.11, linux-2.4.20-rthal5g, comedi-0.7.65 and comedilib-0.7.21. I am using a NI DAQ6024E card. I loaded rt_lxrt_old.o, rtai.o and rt_sched_up.o for the lxrt.
Thanks and my code is attached below.
wee
***************************************
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <sys/mman.h> // for mlockall function
#include <rtai_lxrt_user.h>
#include <rtai_lxrt.h>
#include <comedilib.h>
/*Variables for comedi*/
char *filename="/dev/comedi0";
int value=0;
int subdevice=2;//for dio
int channel=0;
int aref=AREF_GROUND;
int range=0;
static int end;
static void endme(int dummy) { end=1; } //press ctrl + c to terminate loop
#define TICK_PERIOD 1000000 //in ns, now is 1ms
//hard_real_time => ??
//soft_real_time => 10kHz (~ stable)
int main(void)
{
comedi_t *device;
RT_TASK *task;
int priority = 0;
int stack_size=0;
int msg_size = 0;
int i=0;
int signalOp = 0;
int counter = 0;
float sin_value=0.0;
RTIME sintime[10000];
long long time;
RTIME tick_period;
struct sched_param mysched;
/*Open comedi device*/
device=comedi_open(filename);
if(!device){
comedi_perror(filename);
exit(0);
}
printf("configuring pin %d for output...\n",channel);
comedi_dio_config(device,subdevice,channel,COMEDI_OUTPUT);
mysched.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
if(sched_setscheduler(0, SCHED_FIFO, &mysched) == -1)
{
puts("Error in setting the scheduler");
perror("errno");
exit(1);
}
signal(SIGINT, endme); // press ctrl + c to get into endme function
mlockall(MCL_CURRENT | MCL_FUTURE);
/*Creating the realtime task*/
task = rt_task_init(rt_get_name(0)/*nam2num("NAME")*/, priority, stack_size, msg_size);
rt_set_oneshot_mode();
tick_period = start_rt_timer(nano2count(TICK_PERIOD));
rt_make_soft_real_time(); //rt_make_hard_real_time();
rt_task_make_periodic(task, rt_get_time() + tick_period, tick_period);
/*realtime user function starts here*/
signalOp = 0;
while(counter< 500000 && !end)
{
if(signalOp == 0)
{
signalOp = 1;
/*output low to channel0 of DIO port*/
comedi_dio_write(device,subdevice,channel,0);
}
else if(signalOp == 1)
{
signalOp = 0;
/*output high to channel0 of DIO port*/
comedi_dio_write(device,subdevice,channel,1);
}
counter++;
rt_task_wait_period();
}
rt_make_soft_real_time();
stop_rt_timer();
rt_busy_sleep(10000000);
rt_task_delete(task);
return 0;
}
Attachments
- application/ms-tnef attachment: winmail.dat
Received on 2004-08-01Z07:53:34