FreqMeasureMulti does not work on Teensy 3.6

Status
Not open for further replies.
I am writing my code to measure two frequency values to estimate the velocity of two rotary encoders. I am trying to use the FreqMeasureMulti library to get two readings from the encoders, and the example file at
https://github.com/PaulStoffregen/F...ster/examples/Serial_Output/Serial_Output.ino does not work for me.

I tried with the FreqMeasure library on pin 3 and it worked. Below is my code, which worked:

Code:
#include <FreqMeasure.h>
unsigned long rpm1;
void setup() {
  Serial.begin(57600);
  FreqMeasure.begin();
}

double sum=0;
int count=0;

void loop() {
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      float frequency = FreqMeasure.countToFrequency(sum / count);

 rpm1 = (frequency*60)/96; // 96 are the line counts of the encoder http://www.quantumdev.com/finding-the-rpm-of-an-optical-encoder-using-an-oscilloscope/
 Serial.print("rpm=");
    Serial.print(rpm1);
       Serial.print(",freq=");
      Serial.println(frequency);
      
      sum = 0;
      count = 0;
    }
  }
}

Can you help me please to make it work on Teensy 3.6 with FreqMeasureMulti?
 
As the readme file of the library states, only Teensy LC, 3.1 and 3.2 are supported and tested.

A quick look onto the library's source code didn't reveal any obvious constraints to me. It should basically work on the Teensy 3.5/3.6, too. But unfortunately, you only write "the example file at https://github.com/PaulStoffregen/Fr...ial_Output.ino does not work for me." without giving more specific details.

There are people here who are for sure willing to investigate (and to fix) any issues, as long as code examples to reproduce the problem and a detailed description obtained result vs expected result are provided (Forum rules).

Edit: Since the FreqMeasureMulti class has several functions - available(), read(), readLevel(), countToFrequency(), countToNanoseconds(), it would be important to know which of these functions do not seem to work...
 
Last edited:
I tried only to read one frequency from pin 3 (for sure the sensor works fine) If I print freq3.available I get 0 as a value. read() gives constantly 4294967295.

Code:
 #include <FreqMeasureMulti.h>

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


void setup() {
  Serial.begin(57600);
  freq3.begin(3);
}

float sum3=0;
int count3=0;
unsigned long rpm1 ;

void loop() {
  Serial.println(freq3.available());
  if (freq3.available()) {
      // average several reading together
      sum3 = sum3 + freq3.read();
      count3 = count3 + 1;
      if (count3 > 30) {
        float frequency = freq3.countToFrequency(sum3 / count3);
  
        rpm1 = (frequency*60)/96; // 96 are the line counts of the encoder http://www.quantumdev.com/finding-the-rpm-of-an-optical-encoder-using-an-oscilloscope/
        Serial.print("rpm=");
        Serial.print(rpm1);
        Serial.print(",freq=");
        Serial.println(frequency);
        sum3 = 0;
        count3 = 0;
    }
  }
}
[\CODE]

If I use PaulStoffregen example and I just change the pins to 0,1,3, I get ("(no pulses)"); for all three signals from my serial monitor.

[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;
FreqMeasureMulti freq2;
FreqMeasureMulti freq3;

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

float sum1=0, sum2=0, sum3=0;
int count1=0, count2=0, count3=0;
elapsedMillis timeout;

void loop() {
  if (freq1.available()) {
    sum1 = sum1 + freq1.read();
    count1 = count1 + 1;
  }
  if (freq2.available()) {
    sum2 = sum2 + freq2.read();
    count2 = count2 + 1;
  }
  if (freq3.available()) {
    sum3 = sum3 + freq3.read();
    count3 = count3 + 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(",  ");
    if (count2 > 0) {
      Serial.print(freq2.countToFrequency(sum2 / count2));
    } else {
      Serial.print("(no pulses)");
    }
    Serial.print(",  ");
    if (count3 > 0) {
      Serial.print(freq3.countToFrequency(sum3 / count3));
    } else {
      Serial.print("(no pulses)");
    }
    Serial.println();
    sum1 = 0;
    sum2 = 0;
    sum3 = 0;
    count1 = 0;
    count2 = 0;
    count3 = 0;
    timeout = 0;
  }
}

I hope now it is more clear. Thank you for the effort.
 
Pin 3... That's the problem. As stated in the FreqMeasureMulti readme file, only the 8 FTM0 channel pins may be used for FreqMeasureMulti. Thus, as defined in the core file pins_teensy.c, only pins 5,6,9,10, 20,21,22, and 23 can be used.
Code:
#define FTM0_CH0_PIN 22
#define FTM0_CH1_PIN 23
#define FTM0_CH2_PIN  9
#define FTM0_CH3_PIN 10
#define FTM0_CH4_PIN  6
#define FTM0_CH5_PIN 20
#define FTM0_CH6_PIN 21
#define FTM0_CH7_PIN  5

Do you want me to lend you my reading glasses? :D :D :D
 
Status
Not open for further replies.
Back
Top