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.
 
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
}
 
Back
Top