1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5
>Acquisition and configuration functions</TITLE
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
12
HREF="index.html"><LINK
14
TITLE="Writing Comedi programs"
15
HREF="x403.html"><LINK
17
TITLE="Writing a Comedi driver"
18
HREF="x1283.html"></HEAD
29
SUMMARY="Header navigation table"
42
>Control and Measurement Device Interface</I
82
NAME="ACQUISITIONFUNCTIONS"
83
>4. Acquisition and configuration functions</A
86
>This Section gives an overview of all <ACRONYM
89
> functions with which
90
application programmers can implement their data acquisition. (With
94
> we mean all possible kinds of interfacing
95
with the cards: input, output, configuration, streaming, etc.)
99
> explains the function calls in full
106
NAME="SINGLEACQUISITION"
107
>4.1. Functions for single acquisition</A
110
>The simplest form of using <ACRONYM
113
> is to get one single sample to or
114
from an interface card. This sections explains how to do such simple
120
HREF="x621.html#SINGLEANALOG"
129
>4.1.1. Single digital acquisition</A
132
>Many boards supported by <ACRONYM
135
> have digital input and output
136
channels; i.e., channels that can only produce a <VAR
144
Some boards allow the <SPAN
151
of each channel to be specified independently in software.</P
156
> groups digital channels into a
163
>, which is a group of digital channels
164
that have the same characteristics. For example, digital output lines
165
will be grouped into a digital
166
output subdevice, bidirectional digital lines will be grouped
167
into a digital I/O subdevice. Thus, there can be multiple
168
digital subdevices on a particular board.</P
170
>Individual bits on a digital I/O device can be read and written using
173
CLASS="PROGRAMLISTING"
177
>(device,subdevice,channel,unsigned int *bit);
181
>(device,subdevice,channel,unsigned int bit);</PRE
188
HREF="x3563.html#REF-TYPE-COMEDI-T"
191
to a successfully opened <ACRONYM
202
> parameters are positive
203
integers that indicate which subdevice and channel is used in the
204
acquisition. The integer <VAR
208
contains the value of the acquired bit.</P
210
>The direction of bidirectional lines can be configured using
213
CLASS="PROGRAMLISTING"
216
>comedi_dio_config</A
217
>(device,subdevice,channel,unsigned int dir);</PRE
231
Many digital I/O subdevices group channels into blocks for
232
configuring direction. Changing one channel in a block changes
235
>Multiple channels can be read and written simultaneously using the
238
CLASS="PROGRAMLISTING"
241
>comedi_dio_bitfield</A
242
>(device,subdevice,unsigned int write_mask,unsigned int *bits);</PRE
244
Each channel is assigned to a bit in the
253
bitfield. If a bit in
258
corresponding bit in <VAR
262
be written to the corresponding digital output line.
263
Each digital line is then read and placed into
272
to digital output lines is undefined and device-specific. Channel
276
> is the least significant bit in the bitfield;
280
> is the most significant bit. Channels
284
> cannot be accessed using this method.</P
286
>The digital acquisition functions seem to be very simple, but, behind
287
the implementation screens of the <ACRONYM
290
> kernel module, they are
291
executed as special cases of the general
293
HREF="x621.html#INSTRUCTIONS"
303
>4.1.2. Single analog acquisition</A
309
> channels can produce data values that are
316
> from continuous analog signals.
317
These samples are integers with a significant content in
318
the range of, typically, <VAR
335
CLASS="PROGRAMLISTING"
340
HREF="x3563.html#REF-TYPE-COMEDI-T"
342
> * device, unsigned int subdevice, unsigned int channel,
343
unsigned int range, unsigned int aref, <A
344
HREF="x3563.html#REF-TYPE-LSAMPL-T"
348
function reads one such data value from a <ACRONYM
351
> channel, and puts it in
352
the user-specified <VAR
357
CLASS="PROGRAMLISTING"
360
>comedi_data_write</A
362
HREF="x3563.html#REF-TYPE-COMEDI-T"
364
> * device, unsigned int subdevice, unsigned int channel,
365
unsigned int range, unsigned int aref, <A
366
HREF="x3563.html#REF-TYPE-LSAMPL-T"
370
works in the opposite direction. Data values returned by this function
371
are unsigned integers less than, or equal to, the maximum sample value
372
of the channel, which can be determined using the function
374
CLASS="PROGRAMLISTING"
376
HREF="x3563.html#REF-TYPE-LSAMPL-T"
380
>comedi_get_maxdata</A
382
HREF="x3563.html#REF-TYPE-COMEDI-T"
384
> * device, unsigned int subdevice, unsigned int channel);</PRE
386
Conversion of data values to physical units can be performed by the
389
CLASS="PROGRAMLISTING"
394
HREF="x3563.html#REF-TYPE-LSAMPL-T"
396
> data, comedi_range * range, <A
397
HREF="x3563.html#REF-TYPE-LSAMPL-T"
401
There are two data structures in these commands that are not fully
409
HREF="x3563.html#REF-TYPE-COMEDI-T"
411
>: this data structure
412
contains all information that a user program has to know about an
422
> device. The programmer doesn't have
423
to fill in this data structure manually: it gets filled in by opening
429
HREF="x3563.html#REF-TYPE-LSAMPL-T"
434
>"data structure"</SPAN
435
> represents one single sample. On most
436
architectures, it's nothing more than a 32 bits value. Internally,
440
> does some conversion from raw sample data to
444
> integers. This is called <SPAN
453
>Each single acquisition by, for example,
458
>comedi_data_read()</A
461
requires quite some overhead, because all the arguments of the
462
function call are checked. If multiple acquisitions must be done on
463
the same channel, this overhead can be avoided by using a function
464
that can read more than one sample:
466
CLASS="PROGRAMLISTING"
469
>comedi_data_read_n</A
471
HREF="x3563.html#REF-TYPE-COMEDI-T"
473
> *it, unsigned int subdev, unsigned int chan, unsigned int range,
474
unsigned int aref, <A
475
HREF="x3563.html#REF-TYPE-LSAMPL-T"
477
> *data, unsigned int n)</PRE
479
The number of samples, <VAR
483
limited by the <ACRONYM
486
> implementation (to a maximum of 100 samples),
487
because the call is blocking.</P
489
>The start of the data acquisition can also be delayed by a specified
490
number of nano-seconds:
492
CLASS="PROGRAMLISTING"
495
>comedi_data_read_delayed</A
497
HREF="x3563.html#REF-TYPE-COMEDI-T"
499
> *it, unsigned int subdev, unsigned int chan, unsigned int range,
500
unsigned int aref, <A
501
HREF="x3563.html#REF-TYPE-LSAMPL-T"
503
> *data, unsigned int nano_sec)</PRE
505
All these read and write acquisition functions are implemented on top
507
HREF="x621.html#INSTRUCTIONS"
519
>4.2. Instructions for multiple acquisitions</A
528
> is one of the most generic,
529
overloaden and flexible functions in the <ACRONYM
533
execute a multiple of identical acquisitions on the same channel, but
536
HREF="x621.html#INSTRUCTIONSCONFIGURATION"
541
NAME="ANCHOR.INSTRUCTION.LIST"
550
> is a list of instructions,
551
possibly on different channels. Both instructions and instructions
552
lists are executed <SPAN
565
> the calling process.
566
This is one of the limitations of instructions; the other one is that
567
they cannot code an acquisition involving timers or external events.
568
These limits are eliminated by the
570
HREF="x621.html#COMMANDSSTREAMING"
579
NAME="COMEDIINSNSTRUCTURE"
580
>4.2.1. The instruction data structure</A
583
>All the information needed to execute an instruction is stored in the
585
HREF="x3563.html#REF-TYPE-COMEDI-INSN"
590
CLASS="PROGRAMLISTING"
592
NAME="INSN-DATA-STRUCTURE"
596
NAME="INSN-DATA-STRUCTURE-INSN"
598
>unsigned int insn; // integer encoding the type of acquisition
599
// (or configuration)
600
unsigned int n; // number of samples
602
HREF="x3563.html#REF-TYPE-LSAMPL-T"
605
NAME="INSN-DATA-STRUCTURE-DATA"
607
>*data; // pointer to data buffer
608
unsigned int subdev; // subdevice
610
NAME="INSN-DATA-STRUCTURE-CHANSPEC"
613
HREF="x3563.html#REF-MACRO-CR-PACK"
615
>; // encoded channel specification
616
unsigned int unused[3];
619
Because of the large flexibility of the instruction function, many
620
types of instruction do not need to fill in all fields, or attach
621
different meanings to the same field. But the current implementation
627
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
630
least one byte long.</P
633
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
637
HREF="x621.html#INSN-DATA-STRUCTURE"
638
>instruction data structure</A
640
determines the type of acquisition executed in the corresponding
647
>INSN_READ: the instruction executes a read on an analog channel.</P
651
>INSN_WRITE: the instruction executes a write on an analog channel. </P
655
>INSN_BITS: indicates that the instruction must
656
read or write values on multiple digital I/O channels.</P
660
>INSN_GTOD: the instruction performs a <SPAN
662
>"Get Time Of Day"</SPAN
668
>INSN_WAIT: the instruction blocks for a specified number of
679
NAME="INSTRUCTIONEXECUTION"
680
>4.2.2. Instruction execution</A
683
>Once an instruction data structure has been filled in, the
684
corresponding instruction is executed as follows:
686
CLASS="PROGRAMLISTING"
691
HREF="x3563.html#REF-TYPE-COMEDI-T"
694
HREF="x3563.html#REF-TYPE-COMEDI-INSN"
696
> * instruction);</PRE
701
> instructions are shortcuts that relieve the programmer
702
from explicitly filling in the data structure and calling the
711
CLASS="PROGRAMLISTING"
714
>comedi_do_insnlist</A
716
HREF="x3563.html#REF-TYPE-COMEDI-T"
719
HREF="x3563.html#REF-TYPE-COMEDI-INSNLIST"
723
instruction allows to perform a list of instructions in one function
724
call. The number of instructions in the list is limited in the
725
implementation, because instructions are executed
732
>, i.e., the call blocks until the
733
whole instruction (list) has finished.</P
741
NAME="INSTRUCTIONSCONFIGURATION"
742
>4.3. Instructions for configuration</A
746
HREF="x621.html#INSTRUCTIONS"
748
> explains how instructions are used to do
755
> on channels. This section explains
756
how they are used to <SPAN
763
There are various sorts of configurations, and the
764
specific information for each different configuration possibility is
765
to be specified via the
767
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
771
HREF="x621.html#INSN-DATA-STRUCTURE"
772
>instruction data structure</A
774
(So, the pointer to a
776
HREF="x3563.html#REF-TYPE-LSAMPL-T"
779
is misused as a pointer to an array with board-specific information.)</P
781
>Using INSN_CONFIG as the
783
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
787
HREF="x621.html#INSN-DATA-STRUCTURE"
788
>instruction data structure</A
790
indicates that the instruction will
795
>not perform acquisition</I
798
channel, but will <SPAN
805
For example, the configuration of digital I/O channels is done as
808
HREF="x3563.html#REF-MACRO-CR-PACK"
812
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
815
data structure, contains the channel to be configured. And
817
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
820
either COMEDI_INPUT or COMEDI_OUTPUT, depending on the desired
821
direction of the digital I/O lines.
822
On typical devices, multiple channels are grouped together in blocks
823
for determining their direction. And configuring one channel in a
824
block configures the entire block.</P
826
>Another example of an INSN_CONFIG instruction is the configuration of
828
HREF="x621.html#TRIGOTHER-EVENT"
837
NAME="INTTRIGCONFIGURATION"
838
>4.4. Instruction for internal triggering</A
841
>This special instruction has
847
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
851
HREF="x621.html#INSN-DATA-STRUCTURE"
852
>instruction data structure</A
854
Its execution causes an
856
HREF="x621.html#TRIG-INT-START-SRC"
857
>internal triggering event</A
859
event can, for example, cause the device driver to start a conversion,
860
or to stop an ongoing acquisition. The exact meaning of the triggering
861
depends on the card and its particular driver.</P
865
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
868
INSN_INTTRIG instruction is reserved for future use, and should be set
879
NAME="COMMANDSSTREAMING"
880
>4.5. Commands for streaming acquisition</A
883
>The most powerful <ACRONYM
886
> acquisition primitive is the
893
>. It's powerful because, with one single
894
command, the programmer launches:
900
>a possibly infinite <SPAN
904
>sequence of acquisitions</I
910
>accompanied with various <SPAN
917
(DMA, interrupts, driver-specific callback functions), </P
925
>any number of channels</I
937
> of channels in each scan
938
(possibly even with repeated channels per scan), </P
942
>and with various scan <SPAN
946
>triggering sources</I
949
external (i.e., hardware pulses) as well as internal (i.e., pulses
950
generated on the DAQ card itself, or generated by a
952
HREF="x621.html#INTTRIGCONFIGURATION"
953
>software trigger instruction</A
958
This command functionality exists in the <ACRONYM
961
> API, because various
962
data acquisition devices have the capability to perform this kind of
963
complex acquisition, driven by either on-board or
964
off-board timers and triggers.</P
966
>A command specifies a particular data
968
HREF="index.html#FIG-ACQ-SEQ"
969
>acquisition sequence</A
971
consists of a number of <SPAN
978
comprised of a number of <SPAN
985
usually corresponds to a single A/D or D/A conversion. So, for
986
example, a scan could consist of sampling channels 1, 2 and 3 of a
987
particular device, and this scan should be repeated 1000 times, at
988
intervals of 1 millisecond apart.</P
990
>The command function is complementary to the
992
HREF="x621.html#INSTRUCTIONSCONFIGURATION"
993
>configuration instruction</A
995
function: each channel in the command's
997
HREF="x621.html#COMMAND-DATA-STRUCT-CHANLIST"
1000
should first be configured by an appropriate instruction.</P
1006
NAME="EXECUTINGCOMMAND"
1007
>4.5.1. Executing a command</A
1010
>A commands is executed by the following <ACRONYM
1015
CLASS="PROGRAMLISTING"
1020
HREF="x3563.html#REF-TYPE-COMEDI-T"
1023
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1027
The following sections explain the meaning of the
1029
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1032
Filling in this structure can be quite complicated, and
1033
requires good knowledge about the exact functionalities of the DAQ
1034
card. So, before launching a command, the application programmer is
1035
adviced to check whether this complex command data structure can be
1036
successfully parsed. So, the typical sequence for executing a command is
1037
to first send the command through
1040
>comedi_command_test()</A
1042
once or twice. The test will check that the command is valid for the
1043
particular device, and often makes some adjustments to the command
1044
arguments, which can then be read back by the user to see the actual
1050
> program can find out on-line what the command capabilities
1051
of a specific device are, by means of the
1054
>comedi_get_cmd_src_mask()</A
1063
NAME="COMEDICMDSTRUCTURE"
1064
>4.5.2. The command data structure</A
1067
>The command executes according to the information about the requested
1068
acquisition, which is stored in the
1070
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1074
NAME="COMMAND-DATA-STRUCT"
1078
CLASS="PROGRAMLISTING"
1079
>typedef struct comedi_cmd_struct comedi_cmd;
1081
struct comedi_cmd_struct{
1082
unsigned int subdev; // which subdevice to sample
1084
NAME="COMMAND-DATA-STRUCT-FLAGS"
1086
>flags; // encode some configuration possibilities
1087
// of the command execution; e.g.,
1088
// whether a callback routine is to be
1089
// called at the end of the command
1092
NAME="COMMAND-DATA-STRUCT-START-SRC"
1094
>start_src; // event to make the acquisition start
1096
NAME="COMMAND-DATA-STRUCT-START-ARG"
1098
>start_arg; // parameters that influence this start
1101
NAME="COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
1103
>scan_begin_src; // event to make a particular scan start
1105
NAME="COMMAND-DATA-STRUCT-SCAN-BEGIN-ARG"
1107
>scan_begin_arg; // parameters that influence this start`
1110
NAME="COMMAND-DATA-STRUCT-CONVERT-SRC"
1112
>convert_src; // event to make a particular conversion start
1114
NAME="COMMAND-DATA-STRUCT-CONVERT-ARG"
1116
>convert_arg; // parameters that influence this start
1119
NAME="COMMAND-DATA-STRUCT-SCAN-END-SRC"
1121
>scan_end_src; // event to make a particular scan terminate
1123
NAME="COMMAND-DATA-STRUCT-SCAN-END-ARG"
1125
>scan_end_arg; // parameters that influence this termination
1128
NAME="COMMAND-DATA-STRUCT-STOP-SRC"
1130
>stop_src; // what make the acquisition terminate
1132
NAME="COMMAND-DATA-STRUCT-STOP-ARG"
1134
>stop_arg; // parameters that influence this termination
1137
NAME="COMMAND-DATA-STRUCT-CHANLIST"
1139
>*chanlist; // pointer to list of channels to be sampled
1141
NAME="COMMAND-DATA-STRUCT-CHANLIST-LEN"
1143
>chanlist_len; // number of channels to be sampled
1146
NAME="COMMAND-DATA-STRUCT-DATA"
1148
>data; // address of buffer
1150
NAME="COMMAND-DATA-STRUCT-DATA-LEN"
1152
>data_len; // number of samples to acquire
1155
The start and end of the whole command acquisition sequence, and the
1156
start and end of each scan and of each conversion, is triggered by a
1165
HREF="x621.html#COMEDICMDSOURCES"
1174
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1177
the index of the subdevice the command is intended for. The
1180
>comedi_find_subdevice_by_type()</A
1182
function can be useful in discovering the index of your desired subdevice.</P
1185
HREF="x621.html#COMMAND-DATA-STRUCT-CHANLIST"
1190
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1193
structure should point to an array whose number of elements is
1196
HREF="x621.html#COMMAND-DATA-STRUCT-CHANLIST-LEN"
1199
(this will generally be the same as the
1201
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-END-ARG"
1206
HREF="x621.html#COMMAND-DATA-STRUCT-CHANLIST"
1209
specifies the sequence of channels and gains (and analog references)
1210
that should be stepped through for each scan. The elements of the
1212
HREF="x621.html#COMMAND-DATA-STRUCT-CHANLIST"
1215
initialized by <SPAN
1218
> the channel, range and reference
1219
information together with the
1223
HREF="x3563.html#REF-MACRO-CR-PACK"
1230
HREF="x621.html#COMMAND-DATA-STRUCT-DATA"
1234
HREF="x621.html#COMMAND-DATA-STRUCT-DATA-LEN"
1237
members can be safely ignored when issueing commands from a user-space
1238
program. They only have meaning when a command is sent from a
1249
> interface, in which case they specify
1250
the buffer where the driver should write/read its data to/from.</P
1252
>The final member of the
1254
HREF="x621.html#COMMAND-DATA-STRUCT"
1258
HREF="x621.html#COMMAND-DATA-STRUCT-FLAGS"
1261
i.e., bits in a word that can be bitwise-or'd together. The meaning of
1262
these bits are explained in a
1264
HREF="x621.html#SOURCE.FLAGS.ANCHOR"
1273
NAME="COMEDICMDSOURCES"
1274
>4.5.3. The command trigger events
1276
NAME="SOURCE.TRIGGER.ANCHOR"
1281
>A command is a very versatile acquisition instruction, in the sense
1282
that it offers lots of possibilities to let different hardware and
1283
software sources determine when acquisitions are started, performed,
1284
and stopped. More specifically, the command
1286
HREF="x621.html#COMMAND-DATA-STRUCT"
1295
> types of events: start the
1297
HREF="index.html#ACQUISITIONTERMINOLOGY"
1301
HREF="index.html#SCAN"
1305
HREF="index.html#CONVERSION"
1307
>, stop a scan, and stop
1308
the acquisition. Each event can be given its own
1314
HREF="x621.html#SOURCE.TRIGGER.ANCHOR"
1324
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1327
structure). And each event source can have a corresponding
1333
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1336
structure) whose meaning depends on the type of source trigger.
1337
For example, to specify an external digital line <SPAN
1341
source (in general, <SPAN
1348
sources), you would use
1353
HREF="x621.html#TRIG-EXT"
1361
>The following paragraphs discuss in somewhat more detail the trigger
1366
corresponding arguments (<VAR
1371
>The start of an acquisition is controlled by the
1373
HREF="x621.html#COMMAND-DATA-STRUCT-START-SRC"
1376
The available options are:
1383
NAME="TRIG-NOW-START-SRC"
1388
HREF="x621.html#COMMAND-DATA-STRUCT-START-SRC"
1393
HREF="x621.html#COMMAND-DATA-STRUCT-START-ARG"
1396
nanoseconds after the
1398
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1401
is called. Currently, only
1403
HREF="x621.html#COMMAND-DATA-STRUCT-START-ARG"
1411
NAME="TRIG-FOLLOW-START-SRC"
1414
TRIG_FOLLOW: (For an output device.) The
1416
HREF="x621.html#COMMAND-DATA-STRUCT-START-SRC"
1419
event occurs when data is written to the buffer.</P
1424
NAME="TRIG-EXT-START-SRC"
1427
TRIG_EXT: the start event occurs when an external trigger signal
1428
occurs; e.g., a rising edge of a digital line.
1430
HREF="x621.html#COMMAND-DATA-STRUCT-START-ARG"
1433
chooses the particular digital line.</P
1438
NAME="TRIG-INT-START-SRC"
1441
TRIG_INT: the start event occurs on a <ACRONYM
1444
> internal signal, which
1445
is typically caused by an
1447
HREF="x621.html#INSN-INTTRIG"
1448
>INSN_INTTRIG instruction</A
1453
The start of the beginning of each
1455
HREF="index.html#SCAN"
1457
> is controlled by the
1459
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
1462
The available options are:
1469
NAME="TRIG-TIMER-START-SCAN"
1474
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
1477
events occur periodically. The time between
1479
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
1484
HREF="x621.html#COMMAND-DATA-STRUCT-CONVERT-ARG"
1492
NAME="TRIG-FOLLOW-START-SCAN"
1497
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
1500
event occurs immediately after a
1502
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-END-SRC"
1510
NAME="TRIG-EXT-START-SCAN"
1515
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
1518
event occurs when an external trigger signal
1519
occurs; e.g., a rising edge of a digital line.
1521
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-ARG"
1524
chooses the particular digital line.</P
1530
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-ARG"
1533
used here may not be supported exactly by the device, but it
1534
will be adjusted to the nearest supported value by
1537
>comedi_command_test()</A
1540
>The timing between each sample in a
1542
HREF="index.html#SCAN"
1544
> is controlled by the
1546
HREF="x621.html#COMMAND-DATA-STRUCT-CONVERT-SRC"
1556
NAME="CONVERT-TRIG-TIMER"
1563
TRIG_TIMER: the conversion events occur periodically. The time
1564
between convert events is
1566
HREF="x621.html#COMMAND-DATA-STRUCT-CONVERT-ARG"
1574
NAME="CONVERT-TRIG-EXT"
1581
TRIG_EXT: the conversion events occur when an external trigger signal
1582
occurs, e.g., a rising edge of a digital line.
1584
HREF="x621.html#COMMAND-DATA-STRUCT-CONVERT-ARG"
1587
chooses the particular digital line.</P
1592
NAME="CONVERT-TRIG-NOW"
1599
TRIG_NOW: All conversion events in a
1601
HREF="index.html#SCAN"
1603
> occur simultaneously.</P
1613
> of each scan is almost always specified
1616
HREF="x621.html#TRIG-COUNT"
1618
>, with the argument being
1619
the same as the number of channels in the
1621
HREF="x621.html#COMMAND-DATA-STRUCT-CHANLIST"
1624
could probably find a device that allows something else, but it would
1629
HREF="index.html#ACQUISITIONTERMINOLOGY"
1634
HREF="x621.html#COMMAND-DATA-STRUCT-STOP-SRC"
1638
HREF="x621.html#COMMAND-DATA-STRUCT-STOP-ARG"
1647
NAME="ACQUISITION-END-TRIG-COUNT"
1654
TRIG_COUNT: stop the acquisition after
1656
HREF="x621.html#COMMAND-DATA-STRUCT-STOP-ARG"
1664
NAME="ACQUISITION-END-TRIG-NONE"
1671
TRIG_NONE: perform continuous acquisition, until stopped using
1677
>Its argument is reserved and should be set to 0.
1682
means that unspecified things could happen if it is set to something
1687
There are a couple of less usual or not yet implemented events:
1698
cause an event to occur at a particular time.</P
1700
>(This event source is reserved for future use.)</P
1705
NAME="TRIGOTHER-EVENT"
1708
TRIG_OTHER: driver specific event trigger.</P
1710
>This event can be useful as any of the trigger sources. Its exact
1711
meaning is driver specific, because it implements a feature that
1712
otherwise does not fit into the generic <ACRONYM
1715
> command interface.
1716
Configuration of TRIG_OTHER features are done by
1718
HREF="x621.html#INSTRUCTIONSCONFIGURATION"
1723
>The argument is reserved and should be set to 0.</P
1727
Not all event sources are applicable to all events. Supported
1728
trigger sources for specific events depend significantly on your
1729
particular device, and even more on the current state of its device
1733
>comedi_get_cmd_src_mask()</A
1735
function is useful for determining what trigger sources a subdevice
1743
NAME="COMEDICMDFLAGS"
1744
>4.5.4. The command flags
1746
NAME="SOURCE.FLAGS.ANCHOR"
1753
HREF="x621.html#COMMAND-DATA-STRUCT-FLAGS"
1757
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1758
>command data structure</A
1760
is used to specify some <SPAN
1763
> of the acquisitions in
1765
The meaning of the field is as follows:
1775
TRIG_RT: ask the driver to use a
1782
> interrupt handler.
1783
This will reduce latency in handling interrupts from your data
1785
hardware. It can be useful if you are sampling at high frequency, or
1786
if your hardware has a small onboard data buffer. You must have a
1787
real-time kernel (<A
1788
HREF="http://www.rtai.org"
1793
HREF="http://fsmlabs.com/community/"
1797
and must compile <ACRONYM
1800
> with real-time support, or this flag will do
1806
NAME="TRIG-WAKE-EOS"
1815
>"End of Scan"</SPAN
1817
drivers will change their behaviour when this flag is set, trying to
1818
transfer data at the end of every scan (instead of, for example,
1819
passing data in chunks whenever the board's hardware data buffer is
1820
half full). This flag may degrade a driver's performance at high
1821
frequencies, because the end of a scan is, in general, a much more
1822
frequent event than the filling up of the data buffer.</P
1827
NAME="TRIG-ROUND-NEAREST"
1831
round to nearest supported timing period, the default.
1832
This flag (as well as the following three), indicates how timing
1833
arguments should be rounded if the hardware cannot achieve the exact
1834
timing requested.</P
1839
NAME="TRIG-ROUND-DOWN"
1842
TRIG_ROUND_DOWN: round period down.</P
1847
NAME="TRIG-ROUND-UP"
1850
TRIG_ROUND_UP: round period up.</P
1855
NAME="TRIG-ROUND-UP-NEXT"
1859
this one doesn't do anything, and I don't know what it was intended
1868
TRIG_DITHER: enable dithering? Dithering is a software technique to
1869
smooth the influence of discretization <SPAN
1877
NAME="TRIG-DEGLITCH"
1880
TRIG_DEGLITCH: enable deglitching? Another <SPAN
1884
smoothing technique.</P
1893
write to bidirectional devices. Could be useful, in principle, if
1894
someone wrote a driver that supported commands for a digital I/O
1895
device that could do either input or output.</P
1903
TRIG_BOGUS: do the motions?</P
1911
TRIG_CONFIG: perform configuration, not triggering. This is a legacy
1914
HREF="x3563.html#REF-TYPE-COMEDI-CMD"
1915
>comedi_trig_struct</A
1917
data structure, and has no function at present.</P
1928
>4.5.5. Anti-aliasing</A
1931
>If you wish to aquire accurate waveforms, it is vital that you use an
1932
anti-alias filter. An anti-alias filter is a low-pass filter used to
1933
remove all frequencies higher than the Nyquist frequency (half your sampling rate)
1934
from your analog input signal
1935
before you convert it to digital. If you fail to filter your input signal,
1936
any high frequency components in the original analog signal will create
1937
artifacts in your recorded digital waveform that cannot be corrected.</P
1939
>For example, suppose you are sampling an analog input channel at a rate of
1940
1000 Hz. If you were to apply a 900 Hz sine wave to the input, you
1941
would find that your
1942
sampling rate is not high enough to faithfully record the 900 Hz input,
1943
since it is above your Nyquist frequency of 500 Hz. Instead, what you
1944
will see in your recorded digital waveform is a 100 Hz sine wave! If you
1945
don't use an anti-alias filter, it is impossible to tell whether the 100
1946
Hz sine wave you see in your digital signal was really produced by a
1947
100 Hz input signal, or a 900 Hz signal aliased to 100 Hz, or a 1100 Hz
1950
>In practice, the cutoff frequency for the anti-alias filter is usually
1951
set 10% to 20% below the Nyquist frequency due to fact that real filters
1952
do not have infinitely sharp cutoffs.</P
1960
NAME="SLOWLYVARYING"
1961
>4.6. Slowly-varying inputs</A
1964
>Sometimes, your input channels change slowly enough that
1965
you are able to average many successive input values to get a
1966
more accurate measurement of the actual value. In general,
1967
the more samples you average, the better your estimate
1968
gets, roughly by a factor of sqrt(number_of_samples).
1969
Obviously, there are limitations to this:</P
1975
>you are ultimately limited by <SPAN
1977
>"Spurious Free Dynamic
1979
>. This SFDR is one of the popular measures to quantify how
1980
much noise a signal carries. If you take a Fourier transform of your
1981
signal, you will see several <SPAN
1984
> in the transform: one
1985
or more of the fundamental harmonics of the measured signal, and lots
1993
noise. The SFDR is then the difference between the amplitude of the
1994
fundamental harmonic and of the largest spur (at frequencies below
1995
half of the Nyquist frequency of the DAQ sampler!).</P
1999
>you need to have <SPAN
2005
> noise on the input channel,
2006
otherwise you will be averaging the same number <VAR
2010
times. (Of course, this only holds if the noise is large enough to
2011
cause at least a one-bit discretization.)</P
2015
>the more noise you have, the greater your SFDR, but it
2016
takes many more samples to compensate for the increased
2021
>if you feel the need to average samples for, for example, two seconds,
2022
your signal will need to be <SPAN
2029
i.e., not varying more than your target uncertainty for the entire two
2034
>As you might have guessed, the <ACRONYM
2037
> library has functions
2038
to help you in your quest to accurately measure slowly varying
2041
CLASS="PROGRAMLISTING"
2046
HREF="x3563.html#REF-TYPE-COMEDI-SV-T"
2049
HREF="x3563.html#REF-TYPE-COMEDI-T"
2051
> * device, unsigned int subdevice, unsigned int channel);</PRE
2053
This function initializes the
2055
HREF="x3563.html#REF-TYPE-COMEDI-SV-T"
2057
> data structure, used
2058
to do the averaging acquisition:
2060
CLASS="PROGRAMLISTING"
2061
>struct comedi_sv_struct{
2063
HREF="x3563.html#REF-TYPE-COMEDI-T"
2066
unsigned int subdevice;
2073
/* number of measurements to average (for analog inputs) */
2079
The actual acquisition is done with:
2081
CLASS="PROGRAMLISTING"
2084
>comedi_sv_measure</A
2086
HREF="x3563.html#REF-TYPE-COMEDI-SV-T"
2088
> * sv, double * data);</PRE
2090
The number of samples over which the
2093
>comedi_sv_measure()</CODE
2094
> averages is limited by the
2095
implementation (currently the limit is 100 samples). </P
2097
>One typical use for this function is the measurement of thermocouple
2102
> self-calibration utility also uses these functions.
2103
On some hardware, it is possible to tell it to measure an
2104
internal stable voltage reference, which is typically going
2105
to be very slowly varying; on the kilosecond time scale
2106
or more. So, it is reasonable to measure millions of samples,
2107
to get a very accurate measurement of the A/D converter output
2108
value that corresponds to the voltage reference. Sometimes,
2109
however, this is overkill, since there is no need to
2110
perform a part-per-million calibration to a standard that
2111
is only accurate to a part-per-thousand.</P
2118
NAME="EXPERIMENTALFUNCTIONALITY"
2119
>4.7. Experimental functionality</A
2122
>The following subsections document functionality that has not yet
2123
matured. Most of this functionality has even not been implemented yet
2124
in any single device driver. This information is included here, in
2125
order to stimulate discussion about their API, and to encourage
2126
pioneering implementations.</P
2132
NAME="DIGITALINPUTCOMBINING"
2133
>4.7.1. Digital input combining machines</A
2140
>Status: experimental (i.e., no driver implements
2145
>When one or several digital inputs are used to modify an output
2146
value, either an accumulator or a single digital line or bit,
2147
a bitfield structure is typically used in the <ACRONYM
2151
The digital inputs have two properties, <SPAN
2158
> inputs. Edge transitions on sensitive
2159
inputs cause changes in the output signal, whereas modifier inputs
2160
change the effect of edge transitions on sensitive inputs. Note that
2161
inputs can be both modifier inputs and sensitive inputs.</P
2163
>For simplification purposes, it is assumed that multiple digital
2164
inputs do not change simultaneously.</P
2166
>The combined state of the modifier inputs determine a modifier
2167
state. For each combination of modifier state and sensitive
2168
input, there is a set of bits that determine the effect on the
2169
output value due to positive or negative transitions of the
2170
sensitive input. For each transition direction, there are two
2171
bits defined as follows:
2179
>00: transition is ignored.</TD
2183
>01: accumulator is incremented, or output is set.</TD
2187
>10: accumulator is decremented, or output is cleared.</TD
2198
For example, a simple digital follower is specified by the bit
2199
pattern 01 10, because it sets the output on positive transitions
2200
of the input, and clears the output on negative transitions. A
2201
digital inverter is similarily 10 01. These systems have only
2202
one sensitive input.</P
2204
>As another example, a simple up counter, which increments on
2205
positive transitions of one input, is specified by 01 00. This
2206
system has only one sensitive input.</P
2208
>When multiple digital inputs are used, the inputs are divided
2209
into two types, inputs which cause changes in the accumulator, and
2210
those that only modify the meaning of transitions on other inputs.
2211
Modifier inputs do not require bitfields, but there needs to be
2212
a bitfield of length 4*(2^(N-1)) for each edge sensitive input,
2213
where N is the total number of inputs. Since N is usually 2 or
2214
3, with only one edge sensitive input, the scaling issues are
2222
NAME="ANALOGCONVERSION"
2223
>4.7.2. Analog filtering configuration</A
2230
>(Status: design (i.e., no driver implements
2236
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
2240
HREF="x621.html#INSN-DATA-STRUCTURE"
2241
>instruction data structure</A
2243
has not been assigned yet.</P
2246
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
2250
HREF="x621.html#INSN-DATA-STRUCTURE"
2255
>Some devices have the capability to add white noise (dithering) to
2256
analog input measurement. This additional noise can then be averaged
2257
out, to get a more accurate measurement of the input signal. It
2258
should not be assumed that channels can be separately configured.
2259
A simple design can use 1 bit to turn this feature on/off.</P
2261
>Some devices have the capability of changing the glitch characteristics
2262
of analog output subsytems. The default (off) case should be where
2263
the average settling time is lowest. A simple design can use 1 bit
2264
to turn this feature on/off.</P
2266
>Some devices have a configurable analog filters as part of the analog
2267
input stage. A simple design can use 1 bit to enable/disable the
2268
filter. Default is disabled, i.e., the filter being bypassed, or if
2269
the choice is between two filters, the filter with the largest
2277
NAME="WAVEFORMGENERATION"
2278
>4.7.3. Analog Output Waveform Generation</A
2285
>(Status: design (i.e., no driver implements
2291
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
2295
HREF="x621.html#INSN-DATA-STRUCTURE"
2296
>instruction data structure</A
2298
has not been assigned yet.</P
2301
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
2305
HREF="x621.html#INSN-DATA-STRUCTURE"
2310
>Some devices have the ability to cyclicly loop through samples kept in
2311
an on-board analog output FIFO. This config should allow the user to
2312
enable/disable this mode.</P
2314
>This config should allow the user to configure the number of samples
2315
to loop through. It may be necessary to configure the channels used.</P
2322
NAME="EXTENDEDTRIGGERING"
2323
>4.7.4. Extended Triggering</A
2330
>(Status: alpha.)</B
2335
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
2339
HREF="x621.html#INSN-DATA-STRUCTURE"
2340
>instruction data structure</A
2342
has not been assigned yet.</P
2345
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
2349
HREF="x621.html#INSN-DATA-STRUCTURE"
2354
>This section covers common information for all extended
2355
triggering configuration, and doesn't describe a particular
2356
type of extended trigger.</P
2358
>Extended triggering is used to configure triggering engines that
2359
do not fit into commands. In a typical programming sequence, the
2360
application will use
2362
HREF="x621.html#INSTRUCTIONSCONFIGURATION"
2363
>configuration instructions</A
2365
to configure an extended trigger, and a
2367
HREF="x621.html#COMMANDSSTREAMING"
2372
HREF="x621.html#TRIG-OTHER"
2374
> as one of the trigger
2377
>Extended trigger configuration should be designed in such a way
2378
that the user can probe for valid parameters, similar to how
2379
command testing works. An extended trigger configuration instruction
2380
should not configure the hardware directly, rather, the configuration
2381
should be saved until the subsequent command is issued. This
2382
allows more flexibility for future interface changes.</P
2384
>It has not been decided whether the configuration stage should return a
2385
token that is then used as the trigger argument in the command.
2386
Using tokens is one method to satisfy the problem that extended
2387
trigger configurations may have subtle compatiblity issues with
2388
other trigger sources/arguments that can only be determined at
2389
command test time. Passing all stages of a command test should
2390
only be allowed with a properly configured extended trigger.</P
2392
>Extended triggers must use
2394
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
2397
upper 16 bits are reserved and used only for flags that are common to
2398
all extended triggers. The lower 16 bits may be defined by the
2399
particular type of extended trigger.</P
2401
>Various types of extended triggers must use
2403
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
2406
event the extended trigger will be assigned to in the command
2407
structure. The possible values are an OR'd mask of the following:</P
2418
>COMEDI_EV_SCAN_BEGIN
2443
NAME="ANALOGTRIGGERING"
2444
>4.7.5. Analog Triggering</A
2451
>(Status: alpha. The <CODE
2453
>ni_mio_common.c</CODE
2455
implements this feature.)</B
2460
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
2464
HREF="x621.html#INSN-DATA-STRUCTURE"
2465
>instruction data structure</A
2467
has not been assigned yet.</P
2470
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
2474
HREF="x621.html#INSN-DATA-STRUCTURE"
2480
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
2484
HREF="x621.html#INSN-DATA-STRUCTURE"
2487
> is used as follows:
2495
>data[1]: trigger and combining machine configuration.
2500
>data[2]: analog triggering signal chanspec.
2505
>data[3]: primary analog level.
2510
>data[4]: secondary analog level.
2519
>Analog triggering is described by a digital combining machine that
2520
has two sensitive digital inputs. The sensitive digital inputs are
2521
generated by configurable analog comparators. The analog comparators
2522
generate a digital 1 when the analog triggering signal is greater
2523
than the comparator level. The digital inputs are not modifier
2524
inputs. Note, however, there is an effective modifier due to the
2525
restriction that the primary analog comparator level must be less
2526
than the secondary analog comparator level.</P
2528
>If only one analog comparator signal is used, the combining machine
2529
for the secondary input should be set to ignored, and the secondary
2530
analog level should be set to 0.</P
2532
>The interpretation of the chanspec and voltage levels is device
2533
dependent, but should correspond to similar values of the analog
2534
input subdevice, if possible.</P
2536
>Notes: Reading range information is not addressed. This makes it
2537
difficult to convert comparator voltages to data values.</P
2539
>Possible extensions: A parameter that specifies the necessary time
2540
that the set condition has to be true before the trigger is generated.
2541
A parameter that specifies the necessary time that the reset condition
2542
has to be true before the state machine is reset.</P
2549
NAME="BITFIELDMATCHING"
2550
>4.7.6. Bitfield Pattern Matching Extended Trigger</A
2557
>(Status: design. No driver implements this feature yet.)</B
2562
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
2566
HREF="x621.html#INSN-DATA-STRUCTURE"
2567
>instruction data structure</A
2569
has not been assigned yet.</P
2572
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
2576
HREF="x621.html#INSN-DATA-STRUCTURE"
2582
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
2586
HREF="x621.html#INSN-DATA-STRUCTURE"
2589
> is used as follows:</P
2597
>data[1]: trigger flags.
2615
>The pattern matching trigger issues a trigger when all of a specifed
2616
set of input lines match a specified pattern. If the device allows,
2617
the input lines should correspond to the input lines of a digital input
2618
subdevice, however, this will necessarily be device dependent. Each
2619
possible digital line that can be matched is assigned a bit in the
2620
mask and pattern. A bit set in the mask indicates that the
2621
input line must match the corresponding bit in the pattern.
2622
A bit cleared in the mask indicates that the input line is ignored.</P
2624
>Notes: This only allows 32 bits in the pattern/mask, which may be
2625
too few. Devices may support selecting different sets of lines from
2626
which to match a pattern.</P
2628
>Discovery: The number of bits can be discovered by setting the mask
2629
to all 1's. The driver must modify this value and return -EAGAIN.</P
2637
>4.7.7. Counter configuration</A
2644
>(Status: design. No driver implements this feature yet.)</B
2649
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
2653
HREF="x621.html#INSN-DATA-STRUCTURE"
2654
>instruction data structure</A
2656
has not been assigned yet.</P
2659
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
2663
HREF="x621.html#INSN-DATA-STRUCTURE"
2666
> is used to specify which counter to use. (I.e., the
2667
counter is a <ACRONYM
2673
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
2677
HREF="x621.html#INSN-DATA-STRUCTURE"
2680
> is used as follows:</P
2688
>data[1]: trigger configuration.
2693
>data[2]: primary input chanspec.
2698
>data[3]: primary combining machine configuration.
2703
>data[4]: secondary input chanspec.
2708
>data[5]: secondary combining machine configuration.
2713
>data[6]: latch configuration.
2721
>Note that this configuration is only useful if the counting has to be
2728
>. Many cards offer configurable
2729
counters in hardware; e.g., general purpose timer cards can be
2730
configured to act as pulse generators, frequency counters, timers,
2733
>Counters can be operated either in synchronous mode (using
2735
HREF="x621.html#COMEDIINSNSTRUCTURE"
2738
or asynchronous mode (using
2740
HREF="x621.html#COMMANDSSTREAMING"
2742
>), similar to analog
2744
The input signal for both modes is the accumulator.
2745
Commands on counter subdevices are almost always specified using
2747
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
2751
HREF="x621.html#TRIGOTHER-EVENT"
2754
counter configuration also serving as the extended configuration for
2755
the scan begin source.</P
2757
>Counters are made up of an accumulator and a combining machine that
2758
determines when the accumulator should be incremented or decremented
2759
based on the values of the input signals. The combining machine
2760
optionally determines when the accumulator should be latched and
2761
put into a buffer. This feature is used in asynchronous mode.</P
2763
>Note: How to access multiple pieces of data acquired at each event?</P
2771
>4.7.8. One source plus auxiliary counter configuration</A
2778
>(Status: design. No driver implements this feature yet.)</B
2783
HREF="x621.html#INSN-DATA-STRUCTURE-INSN"
2787
HREF="x621.html#INSN-DATA-STRUCTURE"
2788
>instruction data structure</A
2790
has not been assigned yet.</P
2793
HREF="x621.html#INSN-DATA-STRUCTURE-CHANSPEC"
2797
HREF="x621.html#INSN-DATA-STRUCTURE"
2803
HREF="x621.html#INSN-DATA-STRUCTURE-DATA"
2807
HREF="x621.html#INSN-DATA-STRUCTURE"
2810
> is used as follows:</P
2819
>data[1]: is flags, including the flags for the command triggering
2820
configuration. If a command is not subsequently issued on the
2821
subdevice, the command triggering portion of the flags are ignored.
2826
>data[2]: determines the mode of operation. The mode of operation
2827
is actually a bitfield that encodes what to do for various
2828
transitions of the source signals.</TD
2832
>data[3], data[4]: determine the primary source for the counter,
2835
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-SRC"
2839
HREF="x621.html#COMMAND-DATA-STRUCT-SCAN-BEGIN-ARG"
2844
HREF="x621.html#COMMAND-DATA-STRUCT"
2845
>command data structure</A
2854
>Notes: How to specify which events cause a latch and push, and what
2855
should get latched?</P
2864
SUMMARY="Footer navigation table"
b'\\ No newline at end of file'