« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Configuring & Reading Frequency

T-series devices have various configurable clock sources as part of the Digital I/O Extended Feature (DIO-EF) system. In this example we will use the Kipling Register Matrix to configure and read the period/frequency of a digital input signal by counting the number of clock source ticks between two edges. For this example we use clock 0 with default settings.

This example uses FIO0 (aka DIO0) which is handy on the T7. 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, read-a-f, and read-b-f registers to the active list as shown.

 

2. Change the search term to "clock0" and add DIO_EF_CLOCK0_ENABLE to the active list. Writing a 1 to this register enables the first clock source at 80MHz (default frequency). Only enable the clock source after configuring the other EF settings (index).

 

3. Write the following values:

DIO0_EF_ENABLE = 0 //Cannot change index if enabled
DIO0_EF_INDEX = 3
DIO_EF_CLOCK0_ENABLE = 1
DIO0_EF_ENABLE = 1

For this example index 3 is used. This configures which edge pair should be read; Rising-to-rising (index=3) or Falling-to-falling (index=4).

 

4. At this point the LabJack is watching the IO lines for the specified edge. After the first two edges have been observed the time between them is stored, and this repeats for each subsequent edge. Now you can read the period in seconds from a 4th register DIO0_EF_READ_A_F, and the frequency from a 5th register DIO0_EF_READ_B_F. The register DIO0_EF_READ_B_F is a capture register, so this means that it is only updated with a call to read on one of the DIO0_EF_READ_A registers. If you only want the frequency either invert the period to get frequency or read DIO0_EF_READ_A_F first before reading the capture register.

To test functionality, type "dac1_freq" in the search bar and add DAC1_FREQUENCY_OUT_ENABLE to the active register list. Enable DAC1_FREQUENCY_OUT_ENABLE by writing 1 to it—this outputs a 10Hz signal on the DAC1 line on the device. Wire a jumper from DAC1 to FIO0. In the read-a-f register you should see 0.1, or something close, as the period for a 10Hz signal is 0.1s.

**Kipling 3.1.9 has a bug where read-a-f and other DIO EF READ registers may not update. To work around this, change the tab (e.g. change to Analog Outputs), then change back to the Register Matrix tab.**

 

5. To save the configuration, so the frequency measurement will be configured at boot-up, go to the Power-Up Defaults tab and click "Configure Power-up Defaults". Make sure that "Current Device Settings" option is selected. This is suggested if using LJLogM or 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 Frequency Input

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 pair, which means that the state of the digital input changes from low to high twice. 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.

 

Reading a Frequency in LJLogM

Once the frequency counter is enabled (above), you can read DIO0_EF_READ_A_F and DIO0_EF_READ_B_F using any row in LJLogM.

 

Reading a Frequency in LJStreamM

Once the frequency counter is enabled (above), you can read DIO0_EF_READ_A using any row in LJStreamM. In stream mode only DIO0_EF_READ_A and B can be read. DIO0_EF_READ_A returns the period in ticks. To get the period in seconds divide by the clock frequency. In LJStreamM the scaling is:
y=a/80000000
The default clock frequency is 80MHz. To get the frequency from period ticks invert the previous equation:
y=80000000/a
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.

 

Reading a Frequency in DAQFactory

To configure and read frequency you can use steps 1-5 above or write DIO0_EF_INDEX = 3 and DIO0_EF_ENABLE = 1 in DAQFactory. See "Device Configuration" on the DAQFactory for LJM page.
To read the period value you need to read DIO0_EF_READ_A_F. For frequency read DIO0_EF_READ_B_F. See "Linking LabJack Inputs/Outputs to DAQFactory Channels" on the DAQFactory for LJM page.

 

Reading a Frequency in Your Program

To configure and read frequency you need to write DIO0_EF_INDEX = 3 and DIO0_EF_ENABLE = 1. You can do this with a couple calls to eWriteName or a single call to eWriteNames.
To read the period value read DIO0_EF_READ_A_F. For frequency read DIO0_EF_READ_B_F. You can do this with a call to eReadName or a call to eWriteNames if you want both period and frequency. To re-iterate from above, the register DIO0_EF_READ_B_F is a capture register, so this means that it is only updated with a read call on of the DIO0_EF_READ_A registers. If you only want the frequency either invert the period to get frequency or read DIO0_EF_READ_A_F first before reading the capture register.
If using stream mode you also need to read STREAM_DATA_CAPTURE_16 if you want the upper 16-bits.