13.2.5 Frequency In [T-Series Datasheet]
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: 3 (positive edges) or 4 (negative edges)
Streamable: Yes—integer READ registers only.
Frequency In will measure the period or 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).
Operation
The number of ticks can be read from DIO#_EF_READ_A.
Clock#Frequency = CoreFrequency / DIO_EF_CLOCK#_DIVISOR
Period (s) = DIO#_EF_READ_A / Clock#Frequency
Frequency (Hz) = Clock#Frequency / DIO#_EF_READ_A
Resolution(s) = 1 / Clock#Frequency
Max Period(s) = DIO_EF_CLOCK#_ROLL_VALUE / Clock#Frequency
Frequency In works best with periodic signals. Due to a hardware constraint, the first edge is often missed. That can cause confusing results when the signal is not periodic. For measuring non-perioidic singles we recommend L2L.
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 forced to use a lower roll value due to another needed feature such as PWM Out.
A couple of 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
Only Clock0 is 32-bit. Clock1 and Clock2 are both 16-bit. Usage of Clock1 or Clock2 would decrease the maximum roll value to 216.
If you are also using the PWM Out feature, note that the PWM output frequency cannot be measured using the frequency in feature when using the same DIO_EF clock.
Consider using the Interrupt Frequency Input feature for measurement instead.
By default, Frequency In operates in one-shot mode where it will measure the frequency once after being enabled and a new measurement only once after each read of a READ_A register. The other option is continuous mode, where the frequency is constantly measured (every edge is processed) and READ registers return the most recent result. Running in continuous mode puts a greater load on the processor.
If you do another read before a new edge has occurred, you will get the same value as before. Some applications will want to use the read-and-reset option so that a value is only returned once and extra reads will return 0. (See Reset below.)
Configure
DIO#_EF_ENABLE: 0 = Disable, 1 = Enable
DIO#_EF_INDEX: 3 or 4
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: Default = 0. Bit 1: 0 = one-shot, 1 = continuous. All other bits reserved.
DIO#_EF_CONFIG_B: Not used.
DIO#_EF_CONFIG_C: Not used.
DIO#_EF_CONFIG_D: Not used.
One-Shot
When one-shot mode is enabled, the DIO_EF will complete a measurement then go idle. No more measurements will be made until the DIO_EF has been read or reset.
Continuous
When continuous mode is enabled, the DIO_EF will repeatedly make measurements. If a new reading is completed before the old one has been read the old one will be discarded.
CONFIG_A Value Map
To configure the DIO_EF measurement mode, refer to the table below for the mapping between the bit field value and the corresponding integer value which should be written to DIO#_EF_CONFIG_A.
Measurement Mode | Bit Field | Int Value |
---|---|---|
One-Shot | 0b00 | 0 |
Continuous | 0b10 | 2 |
Update
No update operations can be performed on Frequency In.
Read
Results are read from the following registers.
DIO#_EF_READ_A: Returns the period in ticks. If a full period has not yet been observed this value will be zero.
DIO#_EF_READ_B: Returns the same value as READ_A.
DIO#_EF_READ_A_F: Returns the period in seconds. If a full period has not yet been observed this value will be zero.
DIO#_EF_READ_B_F: Returns the frequency in Hz. If a full period has not yet been observed this value will be zero.
Note that all "READ_B" registers are capture registers. All "READ_B" registers are only updated when any "READ_A" register is read. Thus it would be unusual to read any B registers without first reading at least one A register.
Stream Read
All operations discussed in this section are supported in command-response mode. In stream mode, you can read from the integer READ registers (A, B, A_AND_RESET), but as mentioned in the Stream Section those reads only return the lower 16 bits so you need to also use STREAM_DATA_CAPTURE_16 in the scan list to get the upper 16 bits.
Reset
DIO#_EF_READ_A_AND_RESET: Returns the same data as DIO#_EF_READ_A and then clears the result so that zero is returned by subsequent reads until another full period is measured (2 new edges).
Note that even in continuous mode, with reads happening faster than the signal frequency using a _RESET read will result in measurements of every other cycle not every cycle.
Example
Most applications can use default clock settings, so to configure frequency input on DIO0 you can simply write the following register sequence:
DIO_EF_CLOCK0_ENABLE = 1
DIO0_EF_ENABLE = 0
DIO0_EF_INDEX = 3
DIO0_EF_ENABLE = 1
Now you can read the period in seconds from a 4th register DIO0_EF_READ_A_F.
Roll Value Considerations
Sometimes, other DIO-EF might interact with this feature. For example, roll value would usually be set to 0 to provide the maximum measurable period, but assume that we have to use 10000 because it is set to that for PWM output on another channel:
T4/T7:
DIO_EF_CLOCK0_DIVISOR = 8 // Divisor used for PWM. 80 MHz / 8 = 10 MHz clock
DIO_EF_CLOCK0_ROLL_VALUE = 10000 // Roll value used for PWM
T8:
DIO_EF_CLOCK0_DIVISOR = 16 // Divisor used for PWM. 100 MHz / 16 = 6.25 MHz clock
DIO_EF_CLOCK0_ROLL_VALUE = 10000 // Roll value used for PWM
This clock configuration results in:
Resolution = 1 / 6.25 MHz = 0.16 us
MaxPeriod = 10000 / 6.25 MHz = 1.6 ms
For a more detailed walkthrough, see Configuring & Reading Frequency.
Rate Limits
The maximum measurable frequency varies based on the one-shot setting, concurrent stream rate, and other DIO-EFs set to an input mode.
One-shot or Continuous
When one-shot is enabled, the T-series devices will take a single measurement, then wait for a READ_A register to be read before taking another measurement. This means that with one-shot, only a small fraction of the total periods of a signal are measured. One-shot allows for higher maximum measurable frequency than continuous does.
Stream
The stream process is the highest priority process on T-series devices. When stream needs the processor, all other operations are put on hold. That hold occurs more frequently at higher stream speeds. When a DIO-EF process has to wait, the max frequency that can be measured is reduced.
Multiple DIO-EFs
DIO-EFs on other different lines also require processor time. The amount of processor time required depends on the signal being processed and the DIO-EF's settings. The maximum frequencies in the below table give the total max frequency for all running DIO-EFs—divide the max frequencies below by the number of enabled DIO-EFs to get the max frequency for each individual DIO-EF.
Refer to the following table for maximum measurable frequencies in various combinations of stream and one-shot.
Index | One-shot or Continuous | Stream Rate | Max Frequency |
---|---|---|---|
3 or 4 | Continuous | Stream not running | 200 kHz |
3 or 4 | One-shot | Stream not running | 750 kHz |
3 or 4 | Continuous | 10 kHz | 75 kHz |
3 or 4 | One-shot | 10 kHz | 750 kHz |
3 or 4 | Continuous | 100 kHz | 20 kHz |
3 or 4 | One-shot | 100 kHz | 250 kHz |
5 | Continuous | Stream not running | 200 kHz |
5 | One-shot | Stream not running | 750 kHz |
5 | Continuous | 10 kHz | 75 kHz |
5 | One-shot | 10 kHz | 750 kHz |
5 | Continuous | 100 kHz | 20 kHz |
5 | One-shot | 100 kHz | 250 kHz |