FreqMeasureMulti with teensy 3.6

Status
Not open for further replies.

YL77

Member
Hi,

I probably have a trivial problem which I can't really understand. I'm trying to run the example code with teensy 3.6 but it seems like the freq isn't available. I would like to measure the F_BUS. The main porpose is to track time in sub-microsecond scale. It prints no pulses all the time (except the second print). I tried different pins (5,6,23) and it is the same. What did I miss?

Thanks in advance




Code:
/* FreqMeasureMulti - Example with serial output
 * http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
 *
 * This example code is in the public domain.
 */
#include <FreqMeasureMulti.h>

// Measure 3 frequencies at the same time! :-)
FreqMeasureMulti freq1;


void setup() {
  Serial.begin(57600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  delay(10);
  Serial.println("FreqMeasureMulti Begin");
  delay(10);
  freq1.begin(6);
  
}

float sum1=0;
int count1=0;
elapsedMillis timeout;

void loop() {
  if (freq1.available()) {
    sum1 = sum1 + freq1.read();
    count1 = count1 + 1;
  }
  
  // print results every half second
  if (timeout > 500) {
    if (count1 > 0) {
      Serial.print(freq1.countToFrequency(sum1 / count1));
    } else {
      Serial.print("(no pulses)");
    }
    Serial.print(",  ");
    
    Serial.println();
    sum1 = 0;
   
    count1 = 0;
   
    timeout = 0;
  }
}
 
Last edited:
What signal do you have hooked to pin 6?

I added to tone(23,1024); to the end of setup() in your sketch, and jumpered pin 23 to pin 6, and your sketch worked for me
Code:
FreqMeasureMulti Begin
(no pulses),  
1022.76,  
1024.01,  
1024.01,  
1024.00,  
1024.00,  
1024.01, 
...

Due to ISR overhead, the highest frequency you can accurately measure is about 500khz. if you want to measure higher frequencies, use FreqCount lib.
 
Last edited:
Reading the documentation and studying the source code would have told you that the FreqMeasure and FreqMeasureMulti libraries measure the period duration of a signal, counting the F_BUS pulses during that time. The displayed frequency is then calculated as f = F_BUS /pulse_count_per_period. The documentation states that this is precise enough for signals <= 5kHz. Interrupt latencies make the physical limit at around 500kHz, but with reduced precision. F_BUS is between 36MHz and 60MHz, depending on F_CPU and the bus clock divider setting, and will thus never be measurable with that library.
The FreqCount library could basically do that, really counting input pulses during a fixed gate time. But since the latter is always obtained by integer division of F_BUS, you can’t measure eventual deviations.
 
Status
Not open for further replies.
Back
Top