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

Thread: FreqMeasure Misleading Documentation

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    4

    FreqMeasure Misleading Documentation

    The FreqMeasure Library documentation on the Web site says:

    "FreqMeasure.read(); Read a measurement. An unsigned long (32 bits) containing the number of CPU clock cycles that elapsed during one cycle of the waveform."

    However, on Teensy 3.6 it acually uses the 60 Mhz bus clock.

  2. #2
    Quote Originally Posted by John Hasler View Post
    However, on Teensy 3.6 it acually uses the 60 Mhz bus clock.
    Paul has a tough job on his hands to get this kind of documentation exactly right across both Arduino and Teensy. The code below from FreqMeasure.cpp shows the different clocks that are used for each processor family. So, the documentation is correct for AVR, but for T3.x (KINETISK), the raw measurement is in BUS clock cycles. If you use the value returned by read(), you have to be aware of the clock details. If you use countToFrequency() or countToNanoseconds() functions, you do get the correct results.

    Code:
    float FreqMeasureClass::countToFrequency(uint32_t count)
    {
    #if defined(__AVR__)
    	return (float)F_CPU / (float)count;
    #elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISK)
    	return (float)F_BUS / (float)count;
    #elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISL)
    	return (float)(F_PLL/2) / (float)count;
    #elif defined(__arm__) && defined(TEENSYDUINO) && (defined(__IMXRT1052__) || defined(__IMXRT1062__))
    	return (float)F_BUS_ACTUAL / (float)count;
    #endif
    }

Posting Permissions

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