FreqCount - Microsecond Gate Interval

ggiuli

New member
Hi Everybody,
I am working on a project that needs to count the total number of photons emitted in a very short time interval.
This is done counting the pulses (one photon = one pulse) coming from a photodiode.

Up to this point I have been using a Teensy 3.2 and the FreqCount library to measure the total counts in a 1 ms period (the lowest gate interval that the library allows). I would now need to go in the microseconds gate interval range. Is it possible to modify the FreqCount source code to do so on a T3.2 or is the hardware the main limitation here?

Here is the code that I am currently using to read over 1 ms:
Code:
FreqCount.begin(1);
while(!FreqCount.available());
FreqCount.end();
count = FreqCount.read();

Thanks a lot!

P.S: I also have a T4.0 that I could use if this makes things easier.
 
Hi Everybody,
I am working on a project that needs to count the total number of photons emitted in a very short time interval. This is done counting the pulses (one photon = one pulse) coming from a photodiode.

Up to this point I have been using a Teensy 3.2 and the FreqCount library to measure the total counts in a 1 ms period (the lowest gate interval that the library allows). I would now need to go in the microseconds gate interval range. Is it possible to modify the FreqCount source code to do so on a T3.2 or is the hardware the main limitation here?

P.S: I also have a T4.0 that I could use if this makes things easier.

You should try with your T4.0, since FreqCount takes a gate interval in microseconds for T4.x. See the FreqCount library examples Serial_Output (T3) and Serial_Output_T4 in TeensyDuino.
 
Here is an "improved" example sketch for FreqCount that calls out the msec versus usec difference, and also shows the pin assignments

Code:
/* FreqCount - Example with serial output
 * http://www.pjrc.com/teensy/td_libs_FreqCount.html
 *
 * This example code is in the public domain.
 *
 * Teensy     FreqCount input pin    PWM output pin
 * 4.x/MM     9                      8
 * 3.x        13                     8
 * LC         13                     9
 * 2.0        11                     ?
 * 
 * Jumper OUTPUT_PIN to INPUT_PIN
 */
#include <FreqCount.h>

#if defined (__IMXRT1062__) // T4.x
#define PWM_OUTPUT_PIN 8
#elif defined (KINETISK)    // T3.x
#define PWM_OUTPUT_PIN 8
#elif defined (KINETISL)    // LC
#define PWM_OUTPUT_PIN 9
#else
// define pin for T2.0
#endif

void setup() {
  Serial.begin(57600); 
  delay(2000);
  
  analogWriteFrequency(PWM_OUTPUT_PIN, 5000);  // 5 kHz test signal
  analogWrite(PWM_OUTPUT_PIN, 128);
  
#if defined (__IMXRT1062__)
  FreqCount.begin(1000000);  // for T4.x/MM, count time in microseconds
#else
  FreqCount.begin(1000);     // for T3.x/LC/T2.x, count time in milliseconds
#endif
}

void loop() {
  if (FreqCount.available()) {
    unsigned long count = FreqCount.read();
    Serial.println(count);
  }
}
 
The documentation for both FreqCount and FreqMeasure are hopelessly out of date, and the actual performance of both is different due to both the use of microseconds plus the high clock speed. Running on T4 uses the quadtimer, so timer resolution is actually 150 MHz, so much higher than previously available.
 
Back
Top