Teensy 4 - FreqCount.begin() - timer units?

MartinJR

Member
I've noticed that the documentation for FreqCount uses milliseconds for .begin() but example "serial_output_T4" uses microseconds.

Code:
FreqCount.begin(1000000);  //Time in microseconds

Which is correct?

Second, does FreqCount block interupts on the serial ports or is it just PWM function that is affected?

Thanks.
 
Yes it looks like when it was converted to T4.x it changed. From the header file
Code:
	#if(!defined(__IMXRT1062__))
		static void begin(uint16_t msec);
	#else
		static void begin(uint32_t usec);
	#endif
Probably the documentation page: https://www.pjrc.com/teensy/td_libs_FreqCount.html

Should be updated.

Edit: Also maybe there should be a couple new versions of begin
like beginMS(uint16_t ms) and beginUS(uint32_t us);

That is not platform specific... Calls off to existing one.
 
Thanks for that; I almost got caught out by the change!

Here's a FreqCount example program with conditional defines for T3/LC and T4/MM

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);
  }
}
 
Back
Top