Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    17

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

    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.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    11,170
    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.

  3. #3
    Junior Member
    Join Date
    May 2021
    Posts
    17
    Quote Originally Posted by KurtE View Post
    Yes it looks like when it was converted to T4.x it changed.
    Thanks for that; I almost got caught out by the change!

  4. #4
    Quote Originally Posted by MartinJR View Post
    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);
      }
    }

  5. #5
    Junior Member
    Join Date
    May 2021
    Posts
    17
    Quote Originally Posted by joepasquariello View Post
    Here's a FreqCount example program with conditional defines for T3/LC and T4/MM
    Thanks for that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •