- Line-to-Line Measurement (Mode 14) [U3 Datasheet] | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver - Line-to-Line Measurement (Mode 14) [U3 Datasheet]


This timer mode requires firmware 1.30 or later.



The Line-to-Line timer mode uses two timers to measure the time between specified edges on two different lines. For instance, you can measure the time between a rising edge on Timer0 and a falling edge on Timer1. When the LabJack sees the specified edge on Timer0 it starts counting until it sees the specified edge on Timer1. High resolution up to 20.8ns can be achieved with this mode.  



To configure a LabJack for Line-to-Line mode set an even timer and the next (odd) timer to mode 14. The timer values determine the edge that the timer will respond to, 1 being rising, 0 being falling. So, if Timer0's value is 0 and Timer1's is 1 then the LabJack will measure the time between a falling edge on Timer0 to a rising edge on Timer1.



Once configured the timer will return zero until both specified edges have been detected. The time difference in TimerClock periods is then returned by both timers until they are reset.  Both timers will return the same reading, so it is only necessary to read one or the other. To convert to time, divide the value returned by the timer clock. This mode returns 16-bit values, so care should be taken to be sure that the specified condition does not exceed the maximum time. The maximum time can be calculated by (2^16-1)/TimerClock.



Once a measurement has been acquired the even timer needs to be reset before the LabJack will measure again. Values specified when resetting have no effect. Once reset the even timer will return zero until a new measurement has been completed. Resetting the odd timer is optional, if not reset it will continue to return the last measurement until a new one has been completed.






This mode 14 is ideal for using ultrasonic range finding devices. These devices respond to a falling edge on their control line by emitting an ultrasonic pulse. The output line goes high until the echo of the pulse is received after the sound strike an object. The time the output line is high represents twice the distance to the object that caused the echo. Tying the output line to both the even and odd timers in mode 14 allows precise measurement of this interval if you prgram the even timer to trigger on a rising edge and the odd timer to trigger on a falling edge. Use another digital output to create the control pulse. With the Add/Go/Get protocol, you can create those very short pulses precisely – Jon S

Hello Labjack Support,

I am currently trying to work with the Line to Line Measurement (Mode 14) and having some troubles understanding some of the results. 

Here is a copy of the one of the modified examples I am using in MATLAB:

% ------------------------------------------------------

% Line to Line Period Example: Two timers are set to Mode 14 and are used

% to measure the difference between the two rising edges

% ------------------------------------------------------


clc %clear the MATLAB command window

clear global %Clears MATLAB global variables


ljud_LoadDriver; % Loads LabJack UD Function Library

ljud_Constants; % Loads LabJack UD constant file

Time0 = 0;

Time1 = 0;

[Error ljHandle] = ljud_OpenLabJack(LJ_dtU6,LJ_ctUSB,'1',1); % Returns ljHandle for open LabJack



% Reset Labjack

Error = ljud_ePut(ljHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);



% Set the timer/counter pin offset to 0, which will put the first

% timer/counter on FIO0

Error = ljud_AddRequest(ljHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 0, 0, 0);



% 48 MHz Clock

Error = ljud_AddRequest(ljHandle,LJ_ioPUT_CONFIG,LJ_chTIMER_CLOCK_BASE,LJ_tc48MHZ_DIV,0,0);



% Frequency = 1 MHz

Error = ljud_AddRequest(ljHandle,LJ_ioPUT_CONFIG,LJ_chTIMER_CLOCK_DIVISOR,48,0,0);



% Enable 2 Timers

Error = ljud_AddRequest(ljHandle,LJ_ioPUT_CONFIG,LJ_chNUMBER_TIMERS_ENABLED,2,0,0);


% Timer Mode 14: Line to Line Measurement

Error = ljud_AddRequest(ljHandle,LJ_ioPUT_TIMER_MODE,0,14,1,0);



Error = ljud_AddRequest(ljHandle,LJ_ioPUT_TIMER_MODE,1,14,1,0);



% Execute above requests

Error = ljud_GoOne(ljHandle);



% Get all results just to check for errors

Error = ljud_GetFirstResult(ljHandle,0,0,0,0,0);

Error_Message (Error)


% Run while loop until Error 1006 is returned to ensure that the device has

% fully configured its channels before continuing.

while (Error ~= 1006) % 1006 Equates to LJE_NO_MORE_DATA_AVAILABLE

    Error = ljud_GetNextResult(ljHandle,0,0,0,0,0);

    if ((Error ~= 0) && (Error ~= 1006))

        Error_Message (Error)





%Get Timer Reading

%Timer 1 Reading

[Error Time0] = ljud_eGet(ljHandle,LJ_ioGET_TIMER,0,Time0,0); 




%Timer 2 Reading

[Error Time1] = ljud_eGet(ljHandle,LJ_ioGET_TIMER,1,Time1,0); 




if Time0 == Time1

    display('Success!') % Display Counter value

    fprintf('Edge Difference is:%fs\n',Time0/1e6);



%Reset the timer

Error = ljud_ePut(ljHandle, LJ_ioPUT_TIMER_VALUE, 0,0,0);



The purpose of that program is just to output the time difference if the timer have matching values (meaning a pulse width has been measured).

I have done tests using two different types of 5V pulse trains, fixed width and variable width, and the results are a bit off compared  to what I have read from your information. <\p>


First tests were done with a 1kHz 5V fixed dely pulse train. At the first device startup, I get:

Time0 = 49993 (the numbers are just for an example)

Time1 = 49993

which is producing a correct result.<\p>


However, when I poll again (nothing about the pulse train has been changed), I get:

Time0 = 0

Time1 = 49993

I understand that Time0 goes to 0 because I reset it and Time1 stays the same because I did not reset it, but shouldn't the Timers measure again and return ~49993 on both Time0 and Time1?<\p>


Now, for tests on a variable pulse train. I turned on the pulse trains and took readings twice, my results were:

Test 1

Time0 = 41810

Time1 = 43076

Test 2

Time0 = 30940

Time1 = 32200

Then, when I unplug the turn off the pulse train, I get the following result:

Time0 = 57630

Time1 = 57630

The numbers match!


So do you have any idea as to why this behaviour is occuring. I had thought based on what I read that the numbers should always match as long as both triggers have been met. I have just started working with this device in MATLAB so I may have set it up wrong. Any help is appreciated.

Many thanks,




I just tested the L-2-L mode on the U3. I was able to accurately measure the time between rising edges of two signals. After stopping the signals and resetting Tmr0, Tmr0 read 0 and Tmr1 read the old value. When I turned the signals back on I again get an accurate reading on both timers.

Tested with U3 firmware 1.46.

If you continue to have issues, please send an email to [email protected] so that we can look into your specific case.

So, If understood this feature correctly then Line-to-Line measurement can measures the delta time between an edge on one FIOx line and an edge on another FIOy line by counting the number of clock source ticks between the two FIO edges.

Thanks and Regards, R.

Yes, your description sounds correct.