Skip to main content
Skip table of contents

Configuring & Reading a Counter

T-series devices have various counters as part of the Digital I/O Extended Feature (DIO-EF) system.  In this example we will use the Kipling Register Matrix to enable and read an Interrupt Counter.  The Interrupt Counter simply keeps tracks of how many rising edges it has seen on the associated terminal.  The current count can be read at your convenience.

This example uses FIO0 (aka DIO0) which is easily accessible on the T7 and T8.  For the T4, use FIO4 (DIO4) instead.

1.  Go to the Register Matrix in Kipling and type "dio0" in the search box to narrow the list of registers.  Add the INDEX, ENABLE, and READ_A registers to the active list as shown.

2.  Change the search term to "dac1" and add DAC1_FREQUENCY_OUT_ENABLE to the active list.  Writing 1 to this register enables a 10 Hz square wave output on the DAC1 terminal (requires firmware 1.0234+).

3.  Write the following values:

DIO0_EF_ENABLE = 0  // Cannot change index if enabled.
DIO0_EF_INDEX = 8
DIO0_EF_ENABLE = 1
DAC1_FREQUENCY_OUT_ENABLE = 1

4.  The FIO0 line should now be counting rising edges and storing the current count in DIO0_EF_READ_A.  Connect a jumper from DAC1 to FIO0 and you should see DIO0_EF_READ_A incrementing 10 ticks per second.  Another test is to clamp a wire to GND, and tap the other end of that wire to the inside-back of the FIO0 screw-terminal.  For this latter test you will likely get many counts per tap as the counter notices the slight bouncing each time you do this.

5.  To save the configuration, so the counter will be configured at boot-up, go to the Power-Up Defaults tab, make sure the Current Device Settings option is selected, and click Configure Power-up Defaults.  This is suggested if using LJLogM, LJStreamM, or other simple polling programs, but not needed if your software will do the configuration.

Troubleshooting

The 10 Hz test signal enabled by writing DAC1_FREQUENCY_OUT_ENABLE = 1 requires firmware 1.0234 or higher.

Touching a conductor to the top of the screw head of an un-clamped screw terminal is rarely a valid connection.  The screw head is usually valid when the terminal is clamped, but the only guaranteed valid connection is to securely clamp a conductor inside the screw terminal.

Connecting your Signal to a Counter

The typical connection would be +signal to FIO0 and -signal to GND, but the exact connections can depend on the details of your signal.  Likely resources are the Driven Signals and Open-Collector Signals app notes.  The digital input in this example is looking for a rising edge, which means that the state of the digital input changes from low to high.  On T-series devices a low is less than 0.5 volts and a high is greater than 2.64 volts (see specs in appendix of device datasheet for details).  If your signal is not giving you counts use a DMM or oscilloscope to confirm you have valid voltages on FIO0 versus GND.

Measuring Frequency with a Counter

Frequency can be measured with a counter by looking at the change in counts over change in time, but this only works if you get enough counts over the desired time interval to provide the desired resolution.  If not, a better approach might be to use a timer to measure the period of individual pulses.

Reading the Count in LJLogM

Once the counter is enabled (above), you can read DIO0_EF_READ_A using any row in LJLogM.

Reading the Count in LJStreamM

Once the counter is enabled (above), you can read DIO0_EF_READ_A using any row in LJStreamM.  When not streaming, LJStreamUD is grabbing reads in command-response mode which is able to read the entire 32-bit value, but in stream mode DIO0_EF_READ_A only returns the lower 16-bits so if you want the upper 16-bits you need to also read STREAM_DATA_CAPTURE_16, which is mentioned on the LJLog/Stream Scaling Equations page.  Note also in the screenshot that we use the equation y=b + c*65536 and we have un-selected Disable Scaling.

Using a Counter in DAQFactory

To configure the counter you can use steps 1-5 above or write DIO0_EF_INDEX = 8 and DIO0_EF_ENABLE = 1 in DAQFactory.  See "Device Configuration" on the DAQFactory for LJM page.

To read the counter value you need to read DIO0_EF_READ_A.  See "Linking LabJack Inputs/Outputs to DAQFactory Channels" on the DAQFactory for LJM page.

Using a Counter in Your Program

To configure the counter you can use steps 1-5 above or write DIO0_EF_INDEX = 8 and DIO0_EF_ENABLE = 1 in your program.  You can do the latter with a couple calls to eWriteName or a single call to eWriteNames.

To read the counter value you need to read DIO0_EF_READ_A.  You can do this with a call to eReadName.  If using stream mode you also need to read STREAM_DATA_CAPTURE_16 if you want the upper 16-bits.

In the applicable LJM example code archive, look for an example called "Write Read Loop with Config" that can be used to configure and read the counter.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.