Measure short pulses with Teensy 3.2

Status
Not open for further replies.

kalle_wirsch

New member
Hi,

I am new to Teensy. I want to measure short pulses (about 2 microseconds). So I can not use the micros() function.
I need a resolution of about 500 ns. On an Arduino (ATmega 328) I would use the Timer1.
How do I do that with the Teensy 3.2? Are there any examples of which timers are available and how they are used?

kalle_wirsch
 
Last edited:
Teensy 3.2 has similar timers, called FTM. They work much like AVR's 16 bit timers, but with *many* more features.

You'll need the reference manual.

https://www.pjrc.com/teensy/datasheets.html

The FTM timer chapter starts on page 769. It's huge, but only the first part matters. The timer has a ton of features of dual-PWM for controlling motors which you can ignore. Focus on just the input capture stuff.

The FreqMeasure library is probably a good place to start.

For only very short pulses, you could probably delete quite a lot of that code which also interrupts on timer overflow and keeps a 16 bit count of the number of overflows, which gets combined with the 16 bit capture. For short times, the 16 bit capture should be plenty.

FreqMeasure configures the capture to happen only on the rising edge. Then it subtracts successive captures, to give the time between edges. The main program computes the frequency from this period measurement. You'll want to capture on both edges. There are 2 basic ways. First, you can reconfigure the edge on each interrupt. As long as the interrupt does this before the next edge happens, you'll capture everything. The other way involves connecting the signal to 2 different channels of the FTM timer and configure one to capture on the rising edge, the other on the falling edge.

The FTM timers clock at F_BUS, which is 48 MHz by default. So when this is working, you can expect ~21ns resolution in the measurement.
 
Status
Not open for further replies.
Back
Top