- From: Calin A. Culianu <calin_at_ajvar.org>
- Date: Wed, 2 Oct 2002 11:27:53 -0400 (EDT)
Yeah, the sleep wouldn't do it. This is because while you are sleeping in
between channel 0 and channel 1, the board's multiplexer itself is still
hooked into channel 0. Then when you wake up and issue the read command,
what happens it the board is instantly switched to channel 1, then its
registers for that channel are immediately read, thus not allowing enough
time for multiplexer settling. You need to get the cvs version of
comedilib and look at the header file comedilib.h for the function
comedi_data_read_delayed() (I think that's what its called). That
function is just a frontend to lower-level comedi functionality -- it does
roughly the following:
1) Issue a INSN_READ with a 0-length data array
2) Issue an INSN_WAIT with the time parameter as specified by your
nano_sec parameter.
3) Issue a read INSN_READ with a length 1 data array, then return the
result back to your application.
So, if you don't want the CVS version of comedilib, then just emulate the
behavior of comedi_data_read_delayed() by implementing it yourself using
the lower-level INSN interface.
Hope this helps!!
-Calin
On Wed, 2 Oct 2002, Michael Wagner wrote:
> Calin,
>
> Thanks for the suggestion. I did put a "sleep" in between the two reads,
> but that didn't seem to help. I'll try the delayed approach.
>
> Do you have a better API document than the one provided with the comedi
> 0.7.64 or comedilib 0.7.18 tarballs? I find those documents very sparse
> on explanation.
>
> Thanks!
>
> -Mike
>
> Calin A. Culianu wrote:
>
> >Hmm.. I know sometimes you can get unexpected interactions between
> >channels when you read 1 channel right after the other one. This is
> >because the boards internally have a multiplexer that pipes in to the ADC,
> >and the multiplexer itself needs a little time to settle. You may have to
> >issue a comedi_data_read_delayed() when reading from your second channel..
> >
> >-Calin
> >
> >On Thu, 26 Sep 2002, Michael Wagner wrote:
> >
> >
> >
> >>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
> >>
> >>
> >>
> >>_______________________________________________
> >>comedi mailing list
> >>comedi_at_comedi.org
> >>https://cvs.comedi.org/cgi-bin/mailman/listinfo/comedi
> >>
> >>
> >>
> >
> >
> >
> >
> >
>
>
Received on 2002-10-02Z14:27:53