Teensy 4.1 pulse counter - down to 20 ns !

khupys

New member
Hello?

I remember there was discussion for using Teensy 4.x as a fast pulse counter some years ago.
Pictured below is the pulse counter I built using FreqCount function, and all I need is counting 1 us wide pulses, I kept reducing the pulse width until Teensy became erratic. I confirmed that It can count quite reliably down to the pulse width of 20 ns. I suppose the Rigol pulse generator having rise/fall time of 3 ns, going further down would not give you reliable measurements.

The setup is relatively amateurish as I did not pay much attention to the termination, shielding, and impedance matching, etc.
That is why I had to apply 7.5 V pulse when the initial design was for 5 V pulse reduced to 3.3 V. I will fix it later :)

In any case, simple Teensy pulse counter works well down to 20 ns. This may not be surprising to some as the 600 Mhz clock of Teensy means 1.67 ns time resolution. But considering 10 - 20 ns counter board from NI, for example, costs 100s - 1000s of $, this is very nice.

Enjoy it.

Yongsup Park


Teensy-20ns.jpg
 
Last edited:
Nice!

Any chance you might share the code here or on github. I'm pretty sure other people will find it interesting, maybe even make their own pulse measurement.
 
Nice!

Any chance you might share the code here or on github. I'm pretty sure other people will find it interesting, maybe even make their own pulse measurement.

Hi !
I'v done it mostly by vibe coding with Gemini 3 CLI.

The code snippet relevant to the pulse counting is shown below. It is just a simple utilization of FreqCount function, no fancy logic.


Code:
  // Ensure the gate is set to the requested dwell in MICROSECONDS (Teensy 4.1 FreqCount uses usec)
  unsigned long startGate = millis();
  FreqCount.begin(dwell * 1000UL);

  while (!FreqCount.available()) {
    myusb.Task();
  }

  long counts = FreqCount.read();
  FreqCount.end();

  unsigned long endGate = millis();
  Serial.printf("Point: %.2fV, Dwell: %dms, Actual: %lums, Counts: %ld\n", v1, dwell, endGate - startGate, counts);

As I posted earlier in this forum the goal of this ongoing project is building a lab equipment control app that runs entirely on web browser with no dedicated computer for data acquisition. We have a single T4.1 that acts as a web server, USB device controller, and the pulse counter. The browser connects to T4.1 and downloads the React/TypeScript code from T4.1 and run it, after which the React app talks to T4.1 for pulse counting and USB device control.

Hope this helps.

Yongsup Park
 
Last edited:
Back
Top