Distorted signal from PXI 6031E.

Dear all,

I'm using NI PXI 6031E DAQ board. I fed pure sine wave from
function generator to this board in analog single end input. I get
digitized signal that looks nice when plotted.

But when I change to differential input, the signal looks little
distorted, drifts up and down, and once in a while there is an
occasional significant distortion. Has anyone seen
similar behavior?

I included part of my code below. Can someone look and see
if there is any suspicious method that I'm not aware of?

I used :
subdevice = 0
channel =1
range = 1
aref = 2

Thanks. Regards,
J. Ju
---------------------------------------------------------------------------------------


#include <stdio.h>
#include <string.h>
#include <comedilib.h>

#define BUF_LEN 256
#define N_CHANS 32

comedi_t *dev;
comedi_cmd c, *cmd = &c;
lsampl_t maxdata;
lsampl_t rawdata[BUF_LEN];
float times[BUF_LEN];
char buf[BUF_LEN];
unsigned int chanlist[N_CHANS];

int subdevice, channel, range, aref;
int n_scan = 128;
int n_chan = 2;

int prepare_cmd(comedi_t*, int, comedi_cmd*);
int initialize_comedi(char*, int, int, int, int, int);
int get_signal_comedi(int, float*, float*);

char *cmdtest_messages[]={
"success",
"invalid source",
"source conflict",
"invalid argument",
"argument conflict",
"invalid chanlist",
};

int initialize_comedi(char* device_file, int max_sample, int subdevice1,
int channel1, int range1, int aref1)
{
struct timeval t1, t2, start, end;
unsigned int chanlist[16];
double value;
int err, ret, ret1, i, m;
int total = 0;
subdevice = subdevice1;
channel = channel1;
range = range1;
aref = aref1;

dev = comedi_open(device_file);
if (dev == NULL) {
comedi_perror(device_file);
exit(1);
}

for (i = 0; i < n_chan; i++)
chanlist[i] = CR_PACK(channel + i, range, aref);

prepare_cmd(dev, subdevice, cmd);

fprintf(stderr,"command before testing:\n");
dump_cmd(stderr, cmd);

ret = comedi_command_test(dev, cmd);
if (ret < 0) {
comedi_perror("comedi_command_test");
printf("comedi_command_test 1 \n");
exit(1);
}
fprintf(stderr, "first test returned %d (%s)\n", ret,
cmdtest_messages[ret]);
dump_cmd(stderr, cmd);

maxdata = comedi_get_maxdata(dev, subdevice, channel);

ret = comedi_command_test(dev, cmd);
if (ret < 0) {
comedi_perror("comedi_command_test");
printf("comedi_command_test 2 \n");
exit(1);
}
fprintf(stderr,"second test returned %d (%s)\n", ret,
cmdtest_messages[ret]);
if (ret != 0) {
dump_cmd(stderr, cmd);
fprintf(stderr, "Error preparing command\n");
exit(1);
}

ret = comedi_command(dev, cmd);
if (ret < 0) {
comedi_perror("comedi_command");
exit(1);
}

while(1) {
ret = comedi_fileno(dev);
ret = read(comedi_fileno(dev), buf, BUF_LEN);
if (ret < 0) {
perror("read");
break;
} else if (ret == 0) {
break;
} else {
total += ret;
for(i = 0; i < ret / 2; i++) {
rawdata[i] = ((sampl_t *)buf)[i];
}
}
}
return 0;
}

int prepare_cmd(comedi_t *dev, int subdevice, comedi_cmd *cmd)
{
memset(cmd, 0, sizeof(*cmd));
cmd->subdev = subdevice;
cmd->flags = 0;
cmd->start_src = TRIG_NOW;
cmd->start_arg = 0;
cmd->scan_begin_src = TRIG_TIMER;
cmd->scan_begin_arg = 10000;
cmd->scan_end_src = TRIG_COUNT;
cmd->scan_end_arg = channel;
cmd->stop_src = TRIG_COUNT;
cmd->stop_arg = n_scan;
cmd->chanlist = chanlist;
cmd->chanlist_len = channel;
return 0;
}

Received on 2005-01-28Z07:45:37