FTM Timing of up to eight simultaneous signals

Status
Not open for further replies.

TelephoneBill

Well-known member
The objective of this thread is raise awareness of the multiple signal timing capability of the Flexible Timer Module (FTM). I recently discovered that FTM0 can be configured to compare up to eight signals simultaneously with a resolution of around 8 nanoSeconds.

For anyone not familiar with the FTM timers there are three such devices generally available in the Teensy 3 boards (FTM0, FTM1 and FTM2). My recent experiments use a T3.6 board but the same principles apply to other boards.

An FTM timer is basically a 16 bit counter (0 to 65535) that can be driven by either an internal or an external clock signal. The counter value can be read at any moment by the rising or falling edge of an external signal using what is known as a “Channel”. One “flexible aspect” of these channels is that they can be configured to be associated with various external Teensy Pins, such that the rising/falling edge of an external signal can “instantly freeze” the count value into a variable. That variable can then be used in a computation at some later time. (By the way, these variables are pre-defined in the Teensyduino environment.)

The “freezing” of a “read value” of the 16 bit counter is done in hardware by the FTM module, so it is not subject to any software delays or variability in timing caused by interrupts. The standard internal clock frequency is 60 MHz which means the timing resolution of the counter is 16.7 nanoSeconds – but this may be overclocked (with caveats) to 120 MHz, giving a resolution of 8.3 nanoSeconds.

My experiments have shown that each of these eight channels operates independently, which means that the accuracy in a “read value” is not affected by the actions of other channels. This then allows the timing of up to eight external signals to be compared simultaneously with good consistent precision.

If you use a precision external signal on one channel, such as a 1 pulse per second from a frequency standard (perhaps a cheap GPS module), then you can make a series of counter read values of known interval accuracy. By then using one of the other channels to also make a series of readings, you can write some internal software to compare these readings against the 1 PPS – and thereby compute the frequency or timing of the second external signal. This could be computed over many seconds, and this would increase the resolution of the measurement even beyond 8 nanoSeconds. The benefit of this technique is that it is independent of the accuracy of the 120 MHz internal bus peripheral clock. Any variability of the 120 MHz due to, say - ambient temperature, is the same for both sets of channel readings.

Using Teensy 3.6 and the FTM0 timer, the eight simultaneous external channels can be configured as follows:

CH0 = Port PTC1 (ALT4) = External Pin 22
CH1 = Port PTC2 (ALT4) = External Pin 23
CH2 = Port PTC3 (ALT4) = External Pin 9
CH3 = Port PTC4 (ALT4) = External Pin 10
CH4 = Port PTD4 (ALT4) = External Pin 6
CH5 = Port PTD5 (ALT4) = External Pin 20
CH6 = Port PTD6 (ALT4) = External Pin 21
CH7 = Port PTD7 (ALT4) = External Pin 5

(For more details, see Table “Signal Multiplexing” in para 11.3.1, page 184 of the K66 Reference Manual).

I will include some sample coding shortly in another post to this thread.
 
Thanks,

Nice write-up!

FYI - CH2 has two other alternative pins 13(ALT7) and 25(ALT4)
 
Thanks for the pointer to FreqmeasureMulti. I had not appreciated this had been extended. A quick browse confirms this is exactly what I wanted to raise awareness of - even to using exactly same pins. I'm sure this library will be useful for many Teensy addicts.

Sometimes there are not enough Teenys pins available to bring out all the functions available in the Table “Signal Multiplexing” (para 11.3.1, page 184 of K66Ref Manual), and it was comforting to know that this was possible on all the 8 channels for FTM0. That really was the point I wanted to raise awareness of in this thread.

I have an interesting background project (in the planning stage) associated with this topic. I bought 4 cheap GPS modules recently. The 1 PPS output signals each have 20 nS jitter on them (from the internal 48 MHz clock) and they also suffer from timing perturbations (up to 100 nS) when they lock/lose a satellite. The project is to see if I can "create a resultant average" 1PPS from them, which is then more accurate than any one module alone. The strategy is to use 4 channels of FTM0 to derive the average as well as a bit of statistical manipulation from the readings. I then plan to drive a DAC to control an OCXO to present the "mythical average" 1PPS as a final output. A bit of a challenge, but should be fun...
 
Status
Not open for further replies.
Back
Top