Overview
T4 Capable DIO: DIO4, DIO5 (aka FIO4, FIO5)
T7 Capable DIO: DIO0, DIO1 (aka FIO0, FIO1)
T8 Capable DIO: DIO0, DIO1, DIO2, DIO3, DIO4, DIO5, DIO8, DIO11, DIO13 (aka FIO0, FIO1, FIO2, FIO3, FIO4, FIO5, EIO0, EIO3, EIO5)
Requires Clock Source: Yes
Index: 6
Streamable: No
Line-to-line mode can be used to measure the time between edge transition points on two supported DIO.
T4/T7 - The measurement occurs between the lower DIO number edge and the upper DIO edge. For example, the time between a falling edge on DIO0 and the next falling edge on DIO1 when using a T7.
T8 - The measurement occurs between the combination of edges selected. Either DIO can trigger the measurement.
Operation
Clock#Frequency = CoreFrequency / DIO_EF_CLOCK#_DIVISOR
Time(s) = DIO#_EF_READ_A / Clock#Frequency
Resolution(s) = 1 / Clock#Frequency
Max Time(s) = DIO_EF_CLOCK#_ROLL_VALUE / Clock#Frequency
See the DIO-EF Clock Source section for more information about your device core frequency and DIO_EF clock source settings.
Roll value for this feature would typically be left at the default of 0, which is the max value (2^32 for the 32-bit Clock0), but you might be using a lower roll value for another feature such as PWM Out.
A couple typical scenarios with roll value = 0 and using the 32-bit clock (Clock0):
-
Divisor = 1, Resolution = 12.5 nanoseconds, MaxPeriod = 53.7 seconds
-
Divisor = 256, Resolution = 3.2 microseconds, MaxPeriod = 229 minutes
Line-to-Line In operates in a one-shot mode. Once the specified combination of edges is observed, the data is saved and measuring stops. Another measurement can be started by resetting or performing the configuration procedure again. If no measurement has occurred yet, attempting to read any measurement registers will return 0.
Configure
Configuring Line-to-Line In requires configuring two digital I/O lines (see capable DIO here) as Line-to-Line In feature index 6. The first DIO configured should be the one expecting the first edge. Any extended features on either DIO should be disabled before beginning configuration.
DIO#_EF_ENABLE: 0 = Disable, 1 = Enable
DIO#_EF_INDEX: 6
DIO#_EF_CLOCK_SOURCE (formerly DIO#_EF_OPTIONS): Default = 0. Specify which clock source to use. 0 for Clock0, 1 for Clock1, or 2 for Clock2.
DIO#_EF_CONFIG_A: 0 = falling edge. 1 = rising edge.
DIO#_EF_CONFIG_B: Not used.
DIO#_EF_CONFIG_C: Not used.
DIO#_EF_CONFIG_D: Not used.
Update
No update operations can be performed on Line-to-Line In.
Read
Results are read from the following registers.
DIO#_EF_READ_A: Returns the one-shot measured time in clock source ticks. If the specified combination of edges has not yet been observed this value will be zero. Both configured DIO#s return the same value.
DIO#_EF_READ_A_F: Returns the time in seconds. If the specified combination of edges has not yet been observed this value will be zero.
DIO#_EF_READ_B: Returns 1 for the DIO# which detected the first edge, otherwise it returns 0.
Important note: Before reading DIO#_EF_READ_B, you must read DIO#_EF_READ_A or DIO#_EF_READ_A_F on either DIO to read a valid result. If this prerequisite read is not performed, DIO#_EF_READ_B will always return 0.
Reset
DIO#_EF_READ_A_AND_RESET: Performs the same operation as DIO#_EF_READ_A, then clears the result and starts another measurement. Also clears the READ_A values on the paired DIO#.
Example
This shows how to setup Line-to-Line for detecting a falling edge on DIO0 and DIO1 with the maximum measurement resolution using clock source 0.
First, disable and configure the clock source:
DIO_EF_CLOCK0_ENABLE = 0 // Disable the clock source
DIO_EF_CLOCK0_DIVISOR = 1 // Set the divsor
DIO_EF_CLOCK0_ROLL_VALUE = 0 // Set the roll value
On the T4 and T7 this clock configuration results in:
Resolution = 1 / 80 MHz = 12.5 ns
MaxPeriod = 232/ 80 MHz = 53.7 seconds
On the T8 this clock configuration results in:
Resolution = 1 / 100 MHz = 10 ns
MaxPeriod = 232/ 100 MHz = 42.9 seconds
Now disable and configure the DIO-EF on DIO0 and DIO1 as line-to-line (use DIO4 and DIO5 on the T4):
DIO0_EF_ENABLE = 0 // Disable DIO-EF
DIO1_EF_ENABLE = 0 // Disable DIO-EF
DIO0_EF_INDEX = 6 // Index for line-to-line feature.
DIO0_EF_OPTIONS = 0 // Select the clock source.
DIO0_EF_CONFIG_A = 0 // Detect falling edge.
DIO1_EF_INDEX = 6 // Index for line-to-line feature.
DIO1_EF_OPTIONS = 0 // Select the clock source.
DIO1_EF_CONFIG_A = 0 // Detect falling edge.
And finally, enable both DIO-EF and then the clock source to ensure synced results:
DIO0_EF_ENABLE = 1 // Turn on the DIO-EF
DIO1_EF_ENABLE = 1 // Turn on the DIO-EF
DIO_EF_CLOCK0_ENABLE = 1 // Enable the clock source
At this point the device is watching DIO0 for a falling edge. Once that happens it watches for a falling edge on DIO1. Finally after that, it stores the ticks or time between those 2 edges, which you can read from the READ registers described above.
To get a measurement, keep reading either DIO0_EF_READ_A or DIO0_EF_READ_A_F until a non-zero value is reported, indicating a measurement occurred.
ticks_between_edges = 0
while (ticks_between_edges == 0)
ticks_between_edges = DIO0_EF_READ_A // Keep reading until measurement
if DIO0_EF_READ_B == 1
// DIO0 saw the edge first
else
// DIO1 saw the edge first
To do another measurement, repeat this example, or read from DIO0_EF_READ_A_AND_RESET or DIO0_EF_READ_A_F_AND_RESET.
Rate Limits
Line-to-line can achieve high resolution while requiring very little processor time. The time between the edges can be as little as 50 ns. Once a measurement has been completed the system will not measure again until reconfigured or reset. Unless you are reading at a high rate, line-to-line will have little impact on other systems.
If running at a high rate, it is recommended to follow the Example on how to correctly setup the DIO_EF and clock source to ensure both DIO_EFs start on the same clock cycle.