From 16142b8d9ce822df4fdabd58f95d2bf8cb4d8b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Piel?= Date: Wed, 27 May 2015 18:42:01 +0200 Subject: [PATCH] doc: add information about using the National Instrument GPCT The counter interface might eventually be changed to a more generic one. However, for now it's good to have something documented on how things work. --- doc/other.xml | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/doc/other.xml b/doc/other.xml index 3654f28..3a5479f 100644 --- a/doc/other.xml +++ b/doc/other.xml @@ -2010,6 +2010,117 @@ should get latched? +
+ +National instruments General Purpose Counters/Timers (GPCT) + + +Counters/timers and pulse generators are fairly different in terms of +functionality, but they correspond to similar devices seen either as input +or output. When generalising, these devices are both referred to as +"counters". The NI boards provide a couple of such counters, under the name of +GPCT. +A counter is made of the following basic elements: + + + Input source + the signal measured or the clock of the pulse generation. + + + Gate + controls when the counting (or sampling) occurs. + + + Register + holds the current count. + + + Out + for the output counters (pulse generators), the output signal. + + + + +There are many different ways to count, time or generate pulses. All the modes +rely on the counter and some particular configuration. For example, in a typical +buffered counting mode, the source is the (digital) signal that is measured, the +counter is increased at every rising edge of the signal, the gate is the +(digital) signal indicating when to save the counter to memory. It is preferable +you get first familiarized with these various modes by reading your NI board +documentation before reading the following description on the mapping to the +comedi interface. + + + +Each counter of the board is represented in comedi as a subdevice of type +COMEDI_SUBD_COUNTER. Each subdevice has a device file +associated (eg, /dev/comedi0_subd11) in order to read or +write buffered data from or to the counter. +Note that the comedi subdevice has three "channels". In most case, only channel +0 is to be used. Reading or writing on channel 0 corresponds to reading/writing +the counter value. The GPCT also has two registers named A and B, they can be +accessed respectively via channels 1 and 2. + + + +To configure the behaviour of the counter with comedi, the +function comedi_set_counter_mode is used. +The possible mode values are to be found in the ni_gpct_mode_bits +enum constants. For instance, by default the counter is cumulative, even in +buffered counting. To reinitialise it after each sampling (ie, after an edge on +the gate signal), one can add the NI_GPCT_LOADING_ON_GATE_BIT +to the mode. In that case, the counter will be reset to the value of the A +register after each sampling. + + + +To configure the signal to be used as the "source", one uses the +comedi_set_clock_source with one constant from the +ni_gpct_clock_source_bits enum. When the period of the signal is +fixed and known, it should be specified as the last parameter of the method, otherwise +0 should be passed. Note that in comedi this is called "clock" +because in timer and pulse generator, this signal is used as the clock. + + + +To configure the signal to be used as the "gate", one uses the +comedi_set_gate_source with one constant from the +ni_gpct_gate_select enum. When the gate signal is not be used, +NI_GPCT_DISABLED_GATE_SELECT should be specified. Some +NI boards have two gates, but the behaviour associated with the second gate is +usually unknown so it is recommended to disable it. Note that this is called +"gate" because in some modes, this signal is used to block/unblock the counter. + + + +The function comedi_reset will stop and reset a counter. +After being configured, to start a counter, it should be "armed", which can be +done either with the comedi_arm function (for simple counting +mode), or with the start_src member of the command +(for buffered counting). + + + +One side thing to mention is the signal routing of the NI card, which is done +via the PFIs (Programmable Function Inputs). +NI's naming is confusing because they use the same name for the +terminal (ie, physical input/output pins) and for the signal +(ie, the logical information that controls/indicates a specific event). + +The routing allows to configure which signal goes to a PFI terminal. +This is done via comedi_set_routing, with subdevice being +the special DIO comedi subdevice (eg, 7 on M-series), the PFI terminal +number as channel, the signal that should be routed to it encoded as source with +one of the constants from the ni_pfi_routing enum. +The direction of the pin must also be correctly configured (ie, whether it is +used as input or output). This is done via comedi_dio_config +with the same subdevice and channel, and either COMEDI_INPUT +or COMEDI_OUTPUT. + + +
+ +
National instruments RTSI trigger bus