Last active
August 29, 2015 14:13
-
-
Save johnp789/751a6c3a89a7370812d0 to your computer and use it in GitHub Desktop.
comedi_data_read with pci-das6402/16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I've made a small modification to the tut2.c demo to have it call | |
comedi_data_read() three times for each range available on a pci-das6402/16 on | |
channel 0 and then again on channel 1. For the test, I've configured for about | |
0.4V to be applied on differential channel 0, and I've jumpered channel 1 so | |
that it has 0V on it. | |
I'm seeing three problems: | |
1) The first reading in each range looks erroneous. Is this an instance where | |
comedi_data_read_hint() should be called with a short settling time before | |
calling comedi_data_read()? | |
2) The conversion to a physical value for ranges 4, 5, and 6 seems to be off by | |
a factor of two. | |
3) The readings in range 7 have raw values around 2591, when I would have | |
expected to see something like 42000. | |
This could be related to the trouble I'm having with comedi_calibrate on this | |
board. (See my earlier email.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
overall info: | |
version code: 0x00074c | |
driver name: cb_pcidas64 | |
board name: pci-das6402/16 | |
number of subdevices: 10 | |
subdevice 0: | |
type: 1 (analog input) | |
flags: 0x01519000 | |
number of channels: 64 | |
max data value: 65535 | |
ranges: | |
all chans: [-10,10] [-5,5] [-2.5,2.5] [-1.25,1.25] [0,10] [0,5] [0,2.5] [0,1.25] | |
command: | |
start: now|ext | |
scan_begin: follow|timer | |
convert: timer|ext | |
scan_end: count | |
stop: none|count|ext | |
command fast 1chan: | |
start: now 0 | |
scan_begin: follow 0 | |
convert: timer 5000 | |
scan_end: count 1 | |
stop: count 2 | |
subdevice 1: | |
type: 2 (analog output) | |
flags: 0x00135000 | |
number of channels: 2 | |
max data value: 65535 | |
ranges: | |
all chans: [-5,5] [-10,10] [0,5] [0,10] | |
command: | |
start: ext|int | |
scan_begin: timer|ext | |
convert: now | |
scan_end: count | |
stop: none | |
command fast 1chan: | |
start: int 0 | |
scan_begin: timer 10000 | |
convert: now 0 | |
scan_end: count 1 | |
stop: none 0 | |
subdevice 2: | |
type: 3 (digital input) | |
flags: 0x00010000 | |
number of channels: 4 | |
max data value: 1 | |
ranges: | |
all chans: [0,5] | |
command: | |
not supported | |
subdevice 3: | |
type: 4 (digital output) | |
flags: 0x00030000 | |
number of channels: 4 | |
max data value: 1 | |
ranges: | |
all chans: [0,5] | |
command: | |
not supported | |
subdevice 4: | |
type: 5 (digital I/O) | |
flags: 0x00030000 | |
number of channels: 24 | |
max data value: 1 | |
ranges: | |
all chans: [0,5] | |
command: | |
not supported | |
subdevice 5: | |
type: 0 (unused) | |
subdevice 6: | |
type: 9 (calibration) | |
flags: 0x00070000 | |
number of channels: 8 | |
max data value: 255 | |
ranges: | |
all chans: [0,1] | |
command: | |
not supported | |
subdevice 7: | |
type: 9 (calibration) | |
flags: 0x00070000 | |
number of channels: 2 | |
max data value: 255 | |
ranges: | |
all chans: [0,1] | |
command: | |
not supported | |
subdevice 8: | |
type: 8 (memory) | |
flags: 0x00050000 | |
number of channels: 128 | |
max data value: 65535 | |
ranges: | |
all chans: [0,1] | |
command: | |
not supported | |
subdevice 9: | |
type: 0 (unused) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- setting range to 0 --- | |
[0,65535] -> [-10,10] --- -0.287938 V (31824 in raw units) | |
[0,65535] -> [-10,10] --- 0.202487 V (33431 in raw units) | |
[0,65535] -> [-10,10] --- 0.202182 V (33430 in raw units) | |
[0,65535] -> [-10,10] --- 0.200656 V (33425 in raw units) | |
--- setting range to 1 --- | |
[0,65535] -> [-5,5] --- 0.19585 V (34051 in raw units) | |
[0,65535] -> [-5,5] --- 0.201038 V (34085 in raw units) | |
[0,65535] -> [-5,5] --- 0.202411 V (34094 in raw units) | |
[0,65535] -> [-5,5] --- 0.201801 V (34090 in raw units) | |
--- setting range to 2 --- | |
[0,65535] -> [-2.5,2.5] --- 0.1981 V (35364 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.201228 V (35405 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.200465 V (35395 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.201839 V (35413 in raw units) | |
--- setting range to 3 --- | |
[0,65535] -> [-1.25,1.25] --- 0.197776 V (37952 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 0.201019 V (38037 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 0.201095 V (38039 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 0.201438 V (38048 in raw units) | |
--- setting range to 4 --- | |
[0,65535] -> [0,10] --- 0.508278 V (3331 in raw units) | |
[0,65535] -> [0,10] --- 0.202792 V (1329 in raw units) | |
[0,65535] -> [0,10] --- 0.199893 V (1310 in raw units) | |
[0,65535] -> [0,10] --- 0.200961 V (1317 in raw units) | |
--- setting range to 5 --- | |
[0,65535] -> [0,5] --- 0.191119 V (2505 in raw units) | |
[0,65535] -> [0,5] --- 0.200504 V (2628 in raw units) | |
[0,65535] -> [0,5] --- 0.200732 V (2631 in raw units) | |
[0,65535] -> [0,5] --- 0.200732 V (2631 in raw units) | |
--- setting range to 6 --- | |
[0,65535] -> [0,2.5] --- 0.191424 V (5018 in raw units) | |
[0,65535] -> [0,2.5] --- 0.201152 V (5273 in raw units) | |
[0,65535] -> [0,2.5] --- 0.201076 V (5271 in raw units) | |
[0,65535] -> [0,2.5] --- 0.200427 V (5254 in raw units) | |
--- setting range to 7 --- | |
[0,65535] -> [0,1.25] --- 0.193465 V (10143 in raw units) | |
[0,65535] -> [0,1.25] --- 0.201305 V (10554 in raw units) | |
[0,65535] -> [0,1.25] --- 0.201038 V (10540 in raw units) | |
[0,65535] -> [0,1.25] --- 0.201247 V (10551 in raw units) | |
-+-+- setting channel to 1 -+-+- | |
--- setting range to 0 --- | |
[0,65535] -> [-10,10] --- -0.110628 V (32405 in raw units) | |
[0,65535] -> [-10,10] --- 0.00015259 V (32768 in raw units) | |
[0,65535] -> [-10,10] --- 0.00015259 V (32768 in raw units) | |
[0,65535] -> [-10,10] --- 0.00015259 V (32768 in raw units) | |
--- setting range to 1 --- | |
[0,65535] -> [-5,5] --- -0.00236515 V (32752 in raw units) | |
[0,65535] -> [-5,5] --- -7.62951e-05 V (32767 in raw units) | |
[0,65535] -> [-5,5] --- 7.62951e-05 V (32768 in raw units) | |
[0,65535] -> [-5,5] --- 0.000381476 V (32770 in raw units) | |
--- setting range to 2 --- | |
[0,65535] -> [-2.5,2.5] --- -0.000343328 V (32763 in raw units) | |
[0,65535] -> [-2.5,2.5] --- -0.000343328 V (32763 in raw units) | |
[0,65535] -> [-2.5,2.5] --- -0.000114443 V (32766 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.000190738 V (32770 in raw units) | |
--- setting range to 3 --- | |
[0,65535] -> [-1.25,1.25] --- 0.00246052 V (32832 in raw units) | |
[0,65535] -> [-1.25,1.25] --- -9.53689e-05 V (32765 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 1.90738e-05 V (32768 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 1.90738e-05 V (32768 in raw units) | |
--- setting range to 4 --- | |
[0,65535] -> [0,10] --- 0.215152 V (1410 in raw units) | |
[0,65535] -> [0,10] --- NaN [0,10] 0 in raw units | |
[0,65535] -> [0,10] --- NaN [0,10] 0 in raw units | |
[0,65535] -> [0,10] --- NaN [0,10] 0 in raw units | |
--- setting range to 5 --- | |
[0,65535] -> [0,5] --- NaN [0,5] 0 in raw units | |
[0,65535] -> [0,5] --- NaN [0,5] 0 in raw units | |
[0,65535] -> [0,5] --- NaN [0,5] 0 in raw units | |
[0,65535] -> [0,5] --- NaN [0,5] 0 in raw units | |
--- setting range to 6 --- | |
[0,65535] -> [0,2.5] --- 3.81476e-05 V (1 in raw units) | |
[0,65535] -> [0,2.5] --- NaN [0,2.5] 0 in raw units | |
[0,65535] -> [0,2.5] --- NaN [0,2.5] 0 in raw units | |
[0,65535] -> [0,2.5] --- NaN [0,2.5] 0 in raw units | |
--- setting range to 7 --- | |
[0,65535] -> [0,1.25] --- 0.00322347 V (169 in raw units) | |
[0,65535] -> [0,1.25] --- NaN [0,1.25] 0 in raw units | |
[0,65535] -> [0,1.25] --- NaN [0,1.25] 0 in raw units | |
[0,65535] -> [0,1.25] --- NaN [0,1.25] 0 in raw units |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- setting range to 0 --- | |
[0,65535] -> [-10,10] --- -0.0224308 V (32694 in raw units) | |
[0,65535] -> [-10,10] --- 0.411231 V (34115 in raw units) | |
[0,65535] -> [-10,10] --- 0.408179 V (34105 in raw units) | |
--- setting range to 1 --- | |
[0,65535] -> [-5,5] --- 0.400015 V (35389 in raw units) | |
[0,65535] -> [-5,5] --- 0.406577 V (35432 in raw units) | |
[0,65535] -> [-5,5] --- 0.407034 V (35435 in raw units) | |
--- setting range to 2 --- | |
[0,65535] -> [-2.5,2.5] --- 0.398528 V (37991 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.405241 V (38079 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.405165 V (38078 in raw units) | |
--- setting range to 3 --- | |
[0,65535] -> [-1.25,1.25] --- 0.395304 V (43130 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 0.404231 V (43364 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 0.404192 V (43363 in raw units) | |
--- setting range to 4 --- | |
[0,65535] -> [0,10] --- 1.09209 V (7157 in raw units) | |
[0,65535] -> [0,10] --- 0.799878 V (5242 in raw units) | |
[0,65535] -> [0,10] --- 0.800793 V (5248 in raw units) | |
--- setting range to 5 --- | |
[0,65535] -> [0,5] --- 0.767681 V (10062 in raw units) | |
[0,65535] -> [0,5] --- 0.802701 V (10521 in raw units) | |
[0,65535] -> [0,5] --- 0.802243 V (10515 in raw units) | |
--- setting range to 6 --- | |
[0,65535] -> [0,2.5] --- 0.768788 V (20153 in raw units) | |
[0,65535] -> [0,2.5] --- 0.804952 V (21101 in raw units) | |
[0,65535] -> [0,2.5] --- 0.804532 V (21090 in raw units) | |
--- setting range to 7 --- | |
[0,65535] -> [0,1.25] --- 0.0795949 V (4173 in raw units) | |
[0,65535] -> [0,1.25] --- 0.0494965 V (2595 in raw units) | |
[0,65535] -> [0,1.25] --- 0.0494202 V (2591 in raw units) | |
-+-+- setting channel to 1 -+-+- | |
--- setting range to 0 --- | |
[0,65535] -> [-10,10] --- -0.273899 V (31870 in raw units) | |
[0,65535] -> [-10,10] --- 0.00717174 V (32791 in raw units) | |
[0,65535] -> [-10,10] --- 0.0077821 V (32793 in raw units) | |
--- setting range to 1 --- | |
[0,65535] -> [-5,5] --- 0.00190738 V (32780 in raw units) | |
[0,65535] -> [-5,5] --- 0.00404364 V (32794 in raw units) | |
[0,65535] -> [-5,5] --- 0.00419623 V (32795 in raw units) | |
--- setting range to 2 --- | |
[0,65535] -> [-2.5,2.5] --- 0.00141146 V (32786 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.00209812 V (32795 in raw units) | |
[0,65535] -> [-2.5,2.5] --- 0.00179294 V (32791 in raw units) | |
--- setting range to 3 --- | |
[0,65535] -> [-1.25,1.25] --- 0.00288014 V (32843 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 0.00085832 V (32790 in raw units) | |
[0,65535] -> [-1.25,1.25] --- 0.000896468 V (32791 in raw units) | |
--- setting range to 4 --- | |
[0,65535] -> [0,10] --- 0.21149 V (1386 in raw units) | |
[0,65535] -> [0,10] --- Out of range [0,10] | |
[0,65535] -> [0,10] --- Out of range [0,10] | |
--- setting range to 5 --- | |
[0,65535] -> [0,5] --- Out of range [0,5] | |
[0,65535] -> [0,5] --- Out of range [0,5] | |
[0,65535] -> [0,5] --- Out of range [0,5] | |
--- setting range to 6 --- | |
[0,65535] -> [0,2.5] --- 0.00431067 V (113 in raw units) | |
[0,65535] -> [0,2.5] --- Out of range [0,2.5] | |
[0,65535] -> [0,2.5] --- Out of range [0,2.5] | |
--- setting range to 7 --- | |
[0,65535] -> [0,1.25] --- Out of range [0,1.25] | |
[0,65535] -> [0,1.25] --- Out of range [0,1.25] | |
[0,65535] -> [0,1.25] --- Out of range [0,1.25] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Tutorial example #2 | |
* Part of Comedilib | |
* | |
* Copyright (c) 1999,2000 David A. Schleef <[email protected]> | |
* Copyright (c) 2008 Frank Mori Hess <[email protected]> | |
* | |
* This file may be freely modified, distributed, and combined with | |
* other software, as long as proper attribution is given in the | |
* source code. | |
*/ | |
#include <stdio.h> /* for printf() */ | |
#include <stdlib.h> | |
#include <comedilib.h> | |
#include <ctype.h> | |
#include <math.h> | |
int subdev = 0; /* change this to your input subdevice */ | |
int chan = 0; /* change this to your channel */ | |
int range = 3; /* more on this later */ | |
int aref = AREF_DIFF; /* more on this later */ | |
const char filename[] = "/dev/comedi0"; | |
int do_read(comedi_t *device, int subdev, int chan, int range, int aref) | |
{ | |
lsampl_t data; | |
double physical_value; | |
comedi_range * range_info; | |
lsampl_t maxdata; | |
int retval = comedi_data_read(device, subdev, chan, range, aref, &data); | |
if(retval < 0) | |
{ | |
comedi_perror(filename); | |
exit(-1); | |
} | |
comedi_set_global_oor_behavior(COMEDI_OOR_NAN); | |
range_info = comedi_get_range(device, subdev, chan, range); | |
maxdata = comedi_get_maxdata(device, subdev, chan); | |
printf("[0,%d] -> [%g,%g] --- ", maxdata, | |
range_info->min, range_info->max); | |
physical_value = comedi_to_phys(data, range_info, maxdata); | |
if(isnan(physical_value)) { | |
printf("Out of range [%g,%g]\n", | |
range_info->min, range_info->max); | |
} else { | |
printf("%g", physical_value); | |
switch(range_info->unit) { | |
case UNIT_volt: printf(" V"); break; | |
case UNIT_mA: printf(" mA"); break; | |
case UNIT_none: break; | |
default: printf(" (unknown unit %d)", | |
range_info->unit); | |
} | |
printf(" (%lu in raw units)\n", (unsigned long)data); | |
} | |
return 0; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
comedi_t *device; | |
int retval; | |
device = comedi_open(filename); | |
if(device == NULL) | |
{ | |
comedi_perror(filename); | |
return -1; | |
} | |
for(range = 0; range < 8; range++) | |
{ | |
printf("--- setting range to %d ---\n", range); | |
retval = do_read(device, subdev, chan, range, aref); | |
retval = do_read(device, subdev, chan, range, aref); | |
retval = do_read(device, subdev, chan, range, aref); | |
} | |
chan = 1; | |
printf("-+-+- setting channel to %d -+-+-\n", chan); | |
for(range = 0; range < 8; range++) | |
{ | |
printf("--- setting range to %d ---\n", range); | |
retval = do_read(device, subdev, chan, range, aref); | |
retval = do_read(device, subdev, chan, range, aref); | |
retval = do_read(device, subdev, chan, range, aref); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment