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

Thread: FreqMeasureMulti with teensy 3.6

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    2

    FreqMeasureMulti with teensy 3.6

    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 by YL77; 10-02-2018 at 08:09 PM.

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,642
    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 by manitou; 10-02-2018 at 10:48 PM.

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,066
    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.

  4. #4
    Junior Member
    Join Date
    Oct 2018
    Posts
    2
    OK. I'll try FreqCount.
    Thank you for your help!

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,679
    Here's a video I made last year for FreqCount. Hopefully this can give you a good idea of what to expect.


Posting Permissions

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