« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Configuring & Reading Frequency

T-series devices have various timers 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 a timer in the Frequency In mode.  This feature will measure the period/frequency of a digital input signal by counting the number of clock source ticks between two edges: rising-to-rising (index=3) or falling-to-falling (index=4).  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 "clock0" in the search box to narrow the list of registers.  Add the clock0 enable register to the active list.  Change the search term to "dio0" and add the index, enable, read-a-f, and read-b-f registers to the active list.

 

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

 

3. Write the following values:

DIO_EF_CLOCK0_ENABLE = 1        // Enable clock0.  Default frequency is 80 MHz.
DIO0_EF_ENABLE = 0              // Cannot change index if enabled
DIO0_EF_INDEX = 3
DIO0_EF_ENABLE = 1
DAC1_FREQUENCY_OUT_ENABLE = 1

Index 3 times between rising edges while index 4 times between falling edges.

 

4. The FIO0 line should now be measuring the time between rising edges.  The period in seconds is returned by DIO0_EF_READ_A_F and the frequency in Hz is returned by DIO0_EF_READ_B_F.  Connect a jumper from DAC1 to FIO0 and DIO0_EF_READ_A_F should read about 0.1 and DIO0_EF_READ_B_F should read about 10.  Note that the register DIO0_EF_READ_B_F is a capture register, and thus it is only updated whenever the DIO0_EF_READ_A register is read.

**Kipling 3.1.10 has an issue where dio-ef read registers may not initially update. To work around this, change to a different tab (e.g. 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, 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

T7: Firmware 1.0234 or higher is required for the 10 Hz test signal enabled by writing DAC1_FREQUENCY_OUT_ENABLE = 1.

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, 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.

 

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 feature is enabled (above), you can read DIO0_EF_READ_A which returns the period in clock ticks (in stream mode only the integer values DIO0_EF_READ_A and B can be read).  To get the period in seconds, divide by the clock frequency.

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.

In the following screenshot we read the lower 16-bits in row b and the upper 16-bits in row c, so the applicable equations are:

y = b + c*65536                   // total ticks
y=(b + c*65536) / 80000000        // period in seconds
y = 80000000 / (b + c*65536)      // frequency in Hz

 

Reading a Frequency in DAQFactory

To configure the feature you can use steps 1-5 above or write DIO_EF_CLOCK0_ENABLE = 1, 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.  Invert that value to get Hz, or you can also 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 the feature you can use steps 1-5 above or write DIO_EF_CLOCK0_ENABLE = 1, DIO0_EF_INDEX = 3, and DIO0_EF_ENABLE = 1 in your program.  You can do this with a few calls to eWriteName or a single call to eWriteNames.

To read the period value read DIO0_EF_READ_A_F.  You can do this with a call to eReadName.  Invert that value to get Hz, or you can also read DIO0_EF_READ_B_F.  Note that the register DIO0_EF_READ_B_F is a capture register, and thus it is only updated whenever the DIO0_EF_READ_A register is read.  If using stream mode you also need to read STREAM_DATA_CAPTURE_16 if you want the upper 16-bits.

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