Skip to main content
Skip table of contents

13.2.6 Pulse Width 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: 5

Streamable: Yes—integer READ registers only.

Pulse Width In will measure the high time and low time of a digital input signal, by counting the number of clock source ticks while the signal is high and low.  This could also be referred to as duty-cycle input or PWM input.

Operation

The number of high ticks can be read from DIO#_EF_READ_A and the number of low ticks can be read from DIO#_EF_READ_B.

Clock#Frequency = CoreFrequency / DIO_EF_CLOCK#_DIVISOR
HighTime(s) = DIO#_EF_READ_A / Clock#Frequency
LowTime(s) = DIO#_EF_READ_B / Clock#Frequency
Resolution(s) = 1 / Clock#Frequency
Max High or Low 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 (232 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, MaxTime = 53.7 seconds

  • Divisor = 256, Resolution = 3.2 microseconds, MaxTime = 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.

Once this feature is enabled, a new measurement happens on every applicable edge and both result registers are updated on every rising edge.  If you do another read before a new rising edge has occurred, you will get the same values as before.  Many applications will want to use the read-and-reset option so that a value is only read once and extra reads will return 0. (See Reset below.)

Configure

DIO#_EF_ENABLE: 0 = Disable, 1 = Enable
DIO#_EF_INDEX: 5
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 Pulse Width In.

Read

Results are read from the following registers.

DIO#_EF_READ_A: Returns the measured high time in clock source ticks and saves the low time so that it can be read later. If a full period has not yet been observed this value will be zero.
DIO#_EF_READ_B: Returns the measured low time in clock source ticks.  This is a capture register ... it is only updated when one of the READ_A registers is read.
DIO#_EF_READ_A_F: Returns the measured high time in seconds and saves the low time so that it can be read later. If a full period has not yet been observed this value will be zero.
DIO#_EF_READ_B_F: Returns the measured low time in seconds.  This is a capture register ... it is only updated when one of the READ_A registers is read.

Only reading one of the "READ_A" registers will trigger a new measurement. All "READ_B" registers are capture registers, and they are only updated when any "READ_A" register is read.

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: Performs the same read as READ_A, but then also clears the register so that zero is returned until another full period is measured.

DIO#_EF_READ_A_F_AND_RESET: Performs the same read as READ_A_F, but then also clears the register so that zero is returned until another full period is measured.

Example

T4/T7

First, configure the clock source.  Roll value should usually be set to 0 for PWM-in to provide the maximum measurable period. Assume for this example that we have to use 10000 for the roll value because a PWM output on another channel uses the same clock source (clock 0).

DIO_EF_CLOCK0_DIVISOR = 8 // Divisor used for PWM. 80 MHz / 8 = 10 MHz clock

DIO_EF_CLOCK0_ROLL_VALUE = 10000 // Roll value required for PWM output on another channel

This clock configuration results in:

Resolution = 1 / 10 MHz = 0.1 us

MaxPeriod = 10000 / 10 MHz = 1 ms

With these settings, the PWM-in feature could not measure a signal with a period greater than 1 ms.

Configure the DIO_EF on DIO0 (FIO0) as pulse width input*:

DIO0_EF_ENABLE = 0
DIO0_EF_INDEX = 5    // Pulse width input feature.
DIO0_EF_OPTIONS = 0  // Set to use clock source zero.
DIO0_EF_CONFIG_A = 2 // Use Continuous measurement mode
DIO0_EF_ENABLE = 1   // Enable the DIO_EF

After a full period (rising edge, falling edge, rising edge) has occurred, the values are stored in the result registers. This repeats at each rising edge. READ_A and READ_A_F both return the high time and save the low time that can be read from READ_B and READ_B_F. This ensures that both readings are from the same waveform cycle.

*The T4 does not support this feature on DIO0, so you might use DIO4 (FIO4) on the T4 instead. For example, configure DIO4_EF_ENABLE.

T8

First, configure the clock source.  Roll value should usually be set to 0 for PWM-in to provide the maximum measurable period. Assume for this example that we have to use 10000 for the roll value because a PWM output on another channel uses the same clock source (clock 0).

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

With these settings, the PWM-in feature could not measure a signal with a period greater than 1.6 ms.

Now configure the DIO_EF on DIO0 as pulse width input:

DIO0_EF_ENABLE = 0
DIO0_EF_INDEX = 5    // Pulse width input feature.
DIO0_EF_OPTIONS = 0  // Set to use clock source zero.
DIO0_EF_CONFIG_A = 2 // Use Continuous measurement mode
DIO0_EF_ENABLE = 1   // Enable the DIO_EF

After a full period (rising edge, falling edge, rising edge) has occurred, the values are stored in the result registers. This repeats at each rising edge. READ_A and READ_A_F both return the high time and save the low time that can be read from READ_B and READ_B_F. This ensures that both readings are from the same waveform cycle.

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

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.