« Close

Datasheets and User Guides

App Notes

Software & Driver

 

13.1.6 Pulse Width In

Overview

 

T4 Capable DIO: DIO4, DIO5 (aka FIO4, FIO5)

 

T7 Capable DIO: DIO0, DIO1 (aka FIO0, FIO1)

Requires Clock Source: Yes

Index: 5

Streamable: Yes—integer READ registers only.

Operation

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.  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    //typically 80M/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

CoreFrequency is always 80 MHz at this time, but in the future some low-power operational modes might result in different core frequencies.  The valid values for DIO_EF_CLOCK#_DIVISOR are 1, 2, 4, 8, 16, 32, 64, or 256, and a value of 0 (default) equates to a divisor of 1.  For more details about Clock#Frequency and DIO_EF_CLOCK#_DIVISOR, see the DIO-EF Clock Source section.

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, MaxTime = 53.7 seconds
  • Divisor = 256, Resolution = 3.2 microseconds, MaxTime = 229 minutes

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_OPTIONS: Bits 0-2 specify which clock source to use ... 000 for Clock0, 001 for Clock1, and 010 for Clock2. All other bits reserved and should be set to 0.
DIO#_EF_CONFIG_A: Bit 1: 1=continuous, 0=OneShot. All other bits reserved.
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 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 DIO#_EF_READ_A or DIO#_EF_READ_A_F triggers a new measurement.

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

First, configure the clock source.  Roll value would usually be set to 0 to provide the maximum measurable period, but assume for this example that we have to use 10000 because of PWM output on another channel:

DIO_EF_CLOCK0_DIVISOR = 8    // Clock0Frequency = 80M/8 = 10 MHz
DIO_EF_CLOCK0_ROLL_VALUE = 10000
DIO_EF_CLOCK0_ENABLE = 1

This clock configuration results in:

Resolution = 1 / 10M = 0.1 us

and

MaxPeriod = 10000 / 10M = 1 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_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.

6 comments

It looks like reading in stream mode from DIO#_EF_READ_A_AND_RESET isn't resetting the register. Is this because stream mode isn't reading all 32 bits of the register in one hit?

We have been working on DIO_EF recently, so perhaps a bug got introduced or perhaps the behavior is correct but not as expected. To be clear, while reading DIO#_EF_READ_A_AND_RESET from stream mode the value returned does not get set to zero, but rather stays at one number until another reading has been completed?

... also, does it make a difference whether you use continuous or oneshot (DIO#_EF_CONFIG_A)?

Correct, it repeatedly returns the last measurement that was taken. A direct read to the DIO#_EF_READ_A_AND_RESET register using the eReadNames command (I'm using the Python wrappers) has the expected effect.

I've been using continuous mode, but I'll give one-shot a try as well.

Firmware 1.0161 will reset the DIO_EF value properly.

"also, does it make a difference whether you use continuous or oneshot (DIO#_EF_CONFIG_A)?"

One-Shot will only measure a signal once then stop reading until the result has been read. After being read, a new measurement will be started. The advantage is that processor loading can be significantly reduced. Useful in command-response or if your signal is faster than your stream rate. The downside is that, at best, one-shot will measure every other period.

 

It appears in one-shot mode the register is being reset on a read, whereas in continuous mode it doesn't.