Interrupt Frequency In will measure the frequency of a signal on the associated DIO line.

This interrupt-based digital I/O extended feature (DIO-EF) is not purely implemented in hardware, but rather firmware must service each edge. See the discussion of edge rate limits at the bottom of this page.

To measure the frequency, the T-series device will measure the duration of one or more periods. There are several option available to control the way the LabJack does this. The number of periods to be averaged, the edge direction to trigger on, and whether to measure continuously or in one-shot mode can all be specified.

The maximum measurable time is 107 s. The number of periods to be averaged multiplied by the maximum expected period must be less than 107 s or the result will overflow:

107 > (NumToAverage * MaxPeriod)

By default, Interrupt Frequency In operates in one-shot mode where it will measure the frequency once after being enabled and a new measurement only once after each read. The other option is continuous mode, where the frequency is constantly measured (every edge is processed) and READ registers return the most recent result. Running in continuous mode puts a greater load on the processor.

Update

No update operations can be performed with Interrupt Frequency In.

Read

Results are read from the following registers.

DIO#_EF_READ_A: Returns the average period per cycle in ticks (core clock ticks / 2).DIO#_EF_READ_B: Returns the total core clock tick count.DIO#_EF_READ_A_F: Returns the average period per cycle in seconds. Takes into account the number of periods to be averaged and the core clock speed.DIO#_EF_READ_B_F: Returns the average frequency in Hz. Takes into account the number of periods to be averaged and the core clock speed.

Note that all "READ_B" registers are capture registers. All "READ_B" registers are only updated when any "READ_A" register is read. Thus it would be unusual to read any B registers without first reading at least one A register.

Stream Read

All operations discussed in this section are supported in command-response mode. In stream mode, you can read from the integer READ registers (A, B, A_AND_RESET), but as mentioned in the Stream Section those reads only return the lower 16 bits so you need to also use STREAM_DATA_CAPTURE_16 in the scan list to get the upper 16 bits.

Reset

DIO#_EF_READ_A_AND_RESET: Returns the same data as DIO#_EF_READ_A and then clears the result so that zero is returned by subsequent reads until another full period is measured (2 new edges). DIO#_EF_READ_A_AND_RESET_F: Returns the same data as DIO#_EF_READ_A_F and then clears the result so that zero is returned by subsequent reads until another full period is measured (2 new edges).

Note that even in continuous mode, with reads happening faster than the signal frequency using a _RESET read will result in measurements of every other cycle not every cycle.

Example

To configure Interrupt Frequency In on DIO6 you can simply write to 2 registers:

DIO6_EF_ENABLE = 0DIO6_EF_INDEX = 11DIO6_EF_ENABLE = 1

Now you can read the period in seconds from a 4th register DIO6_EF_READ_A_F.

Edge Rate Limits

This
interrupt-based digital I/O extended feature (DIO-EF) is not purely
implemented in hardware, but rather firmware must service each edge.
This makes it substantially slower than other DIO-EF that are purely
hardware-based. To avoid missed edges, the aggregate limit for edges
seen by all interrupt-based DIO-EF is 70k edges/second. If stream mode is active, the limit is reduced to 20k edges/second. Excessive processor loading (e.g. a busy Lua script) can also reduce these limits.

The more
proper way to
think of the edge limit, and understand error that could be introduced
when using multiple interrupt-based DIO-EF, is to consider that the
interrupt that
processes an edge can take up to 14 μs to complete. When a particular
channel sees an applicable edge, an IF (interrupt flag) is set for that
channel that tells the processor it needs to run an ISR (interrupt
service routine) for that channel. Once an ISR is started, it runs to
completion and no other ISR can run until it is done (except that stream
interrupts are higher priority and will preempt other interrupts).
When an ISR completes, it clears the IF for that channel. So it is okay
to have edges on multiple channels at the same time, as long as there
is not another edge on any of those channels before enough time to
process all the initial edges.

Say that channel A & B have an
edge occur at the same time and an ISR starts to process the edge on
channel A. If channel A has another edge during the first 14 μs, that
edge will be lost. If channel B has another edge during the first 14
μs, the initial edge will be lost. If channel B has another edge during
the second 14 μs (during the ISR for channel B), the new edge will be
lost.