Command setup for a counter subdevice setup to read an encoder.

65 views
Skip to first unread message

pa...@reell.com

unread,
Nov 28, 2011, 6:48:21 PM11/28/11
to Comedi: Linux Control and Measurement Device Interface
I'd like to setup a command to read the value from a counter
subdevice. The system has an encoder and an analog input and I need
to record position and the value of the analog input at the same
interval. I can setup the encoder with the gptc_encoder from the
demo directory and read the current value with inp. I've been able
to get commands working for the analog input subdevice.

I'm running under Ubuntu 10.04 with RTAI and comedi off the RTXI live
CD, the card I'm using is a NI PCI-6221. We have used this card for
similar systems that were programed in c++ under windows with the
DAQmx drivers, with that setup both the encoder and the analog
channels were setup to use the same sample clock also.

Ian Abbott

unread,
Nov 29, 2011, 5:26:28 AM11/29/11
to comed...@googlegroups.com

You should be able to set up commands on the subdevice-specific file for
the counter subdevice, e.g. /dev/comedi0_subd11 for the first counter
subdevice, but I don't think you can set up a command to read both the
counter and the analog input in the same interval because each comedi
command can only access a single subdevice.

--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

pa...@reell.com

unread,
Nov 29, 2011, 5:43:36 PM11/29/11
to Comedi: Linux Control and Measurement Device Interface
I've tried to get a command to run on subdevice 11, and I haven't
managed to build a command that will pass the function
comedi_command_test.

As far as synchronizing the timer it looks like
comedi_get_clock_source and comedi_set_clock_source would be the
commands I would need to use to get the equivalent of what the windows
program does. I can't find any documentation about the clock source
functions.

Here's the channel setup code from the windows DAQmx program:

// Load Cell
DAQmxErrChk(DAQmxCreateTask("",&LoadCellTaskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(LoadCellTaskHandle,"Dev1/
ai0","",DAQmx_Val_RSE,-1.5,1.5,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(LoadCellTaskHandle,"",globals-
>Fixture.SampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,int(globals-
>Fixture.SampleRate)));

DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(LoadCellTaskHandle,DAQmx_Val_Acquired_Into_Buffer,CALLBACKFREQ,
0,EveryNCallback,NULL));

// Get trigger to slave encoder read to
DAQmxErrChk (GetTerminalNameWithDevPrefix(LoadCellTaskHandle,"ai/
SampleClock",trigName));
// Hardware (NI-DAQ) Encoder
DAQmxErrChk (DAQmxCreateTask("",&EncoderTaskHandle));
DAQmxErrChk (DAQmxCreateCIAngEncoderChan(EncoderTaskHandle,"Dev1/
ctr0","",DAQmx_Val_X4,0,0.0,DAQmx_Val_AHighBHigh,DAQmx_Val_Degrees,int(globals-
>Fixture.SampleRate)));

// Start data read function
DAQmxStartTask(EncoderTaskHandle);
DAQmxStartTask(LoadCellTaskHandle);

> -=( Ian Abbott @ MEV Ltd.    E-mail: <abbo...@mev.co.uk>        )=-

Reply all
Reply to author
Forward
0 new messages