Problem reading multiple analog input channels

Hi,

I am trying to read two analog inputs back to back, using code like
this:

  maxData[0] = comedi_get_maxdata(adc, SUBDEV_AD, channel[0]);
  rangeType[0] = comedi_get_range(adc, SUBDEV_AD, channel[0], 0);
  maxData[1]= comedi_get_maxdata(adc, SUBDEV_AD, channel[1]);
  rangeType[1] = comedi_get_range(adc, SUBDEV_AD, channel[1], 0);
  while(1) {
    comedi_data_read(adc, SUBDEV_AD, channel[0], range, AREF_DIFF,
&data);
    volts = comedi_to_phys(data, rangeType[0], maxData[0]);
    printf("AD on first channel says %f volts\n", volts);
    comedi_data_read(adc, SUBDEV_AD, channel[1], range, AREF_DIFF,
&data);
    volts = comedi_to_phys(data, rangeType[1], maxData[1]);
    printf("AD on second channel says %f volts\n", volts);
    // sleep for about 0.1 seconds
  }

Unfortunately this doesn't work! When I read both channels like this,
one channel gives expected results and the other gives values that
(a) don't change like they should (say I have them connected to a
variable voltage source...I increase the voltage and the result doesn't
show it) and (b) don't start in the correct range (for instance, I might
expect the signal to start at 0 V, but instead starts off around 3 V).

Now, if I remove ONE of the comedi_data_read/comedi_to_phys/printf
blocks, the other block works fine. In other words, it's not that one
channel is bad. If I read ONLY that channel, it works fine. The channel
that works seems to be the first one read, *but I'm not absolutely sure
about that.*

Any ideas???? Thanks!

The info on my system:

Red Hat Linux 7.1
Kernel 2.4.2-2
comedi 0.7.64
comedilib 0.7.18
NI-DAQ PCI card (not sure exactly what type)

comedilib/demo/info gives me:
overall info:
  version code: 0x00073c
  driver name: ni_pcimio
  board name: pci-mio-16xe-50
  number of subdevices: 7
subdevice 0:
  type: 1 (analog input)
  number of channels: 16
  max data value: 65535
  ranges:
    all chans: [-10,10] [-5,5] [-1,1] [-0.1,0.1] [0,10] [0,5] [0,1]
[0,0.1]
  command:
    start: now|int
    scan_begin: timer|ext
    convert: timer|ext
    scan_end: count
    stop: none|count
  command fast 1chan:
    not supported
subdevice 1:
  type: 2 (analog output)
  number of channels: 2
  max data value: 4095
  ranges:
    all chans: [-10,10]
  command:
    start: now
    scan_begin: timer
    convert: now
    scan_end: count
    stop: none|count
  command fast 1chan:
can't do timed?!?
    not supported
subdevice 2:
  type: 5 (digital I/O)
  number of channels: 8
  max data value: 1
  ranges:
    all chans: [0,5]
  command:
    not supported
subdevice 3:
  type: 0 (unused)
subdevice 4:
  type: 6 (counter)
  number of channels: 2
  max data value: 1
  ranges:
    all chans: [0,1]
  command:
    not supported
subdevice 5:
  type: 9 (calibration)
  number of channels: 9
  max data value: (channel specific)
    chan0: 255
    chan1: 255
    chan2: 255
    chan3: 255
    chan4: 255
    chan5: 255
    chan6: 255
    chan7: 255
    chan8: 4095
  ranges:
    all chans: [0,1]
  command:
    not supported
subdevice 6:
  type: 8 (memory)
  number of channels: 512
  max data value: 255
  ranges:
    all chans: [0,1]
  command:
    not supported

Received on 2002-09-26Z19:16:47