FreqMeasureMulti - Teensy 3.5 - Problems

Status
Not open for further replies.

WanaGo

Member
Hi there

I am having problems with FreqMeasureMulti.
At the moment I have just 1 frequency input, but there will be 2. Both are under 200Hz.

The problem is when I vary the frequency going in, reducing the frequency works fine, the number is quite rapid to respond. But when I increase the frequency, there is a significant delay and it often blinks a very low number and then carries on.
Always the same, decreasing frequency is smooth, increasing frequency something is going wrong, and I don't know what it could be.

The is coming off an RPS sensor for a motor, I have 28 pulses per revolution, and the max number of pulses will be about 200Hz.

I have tried the Serial_Output.ino example that comes with the library, and it does the same thing.
I have modified it a bit (minor) and this demonstrates the problem.
It shows a stream of numbers (just use 1 channel). Connect to pin 5, when you reduce the frequency it is smooth and seamless. When you increase it, the numbers pause for a bit (second or more), and then carry on, but often will show a number near 0.
This is a huge problem for me as I need a smooth up/down frequency stream.

Can anyone help, please?

Code:
#include <FreqMeasureMulti.h>

#define pin_SENSOR1_RPS 5
#define pin_SENSOR2_RPS 6

FreqMeasureMulti freq1;
FreqMeasureMulti freq2;

void setup()
{
  Serial.begin(115200);

  freq1.begin(pin_SENSOR1_RPS);
  freq2.begin(pin_SENSOR2_RPS);
}

float sum1 = 0, sum2 = 0;
int count1 = 0, count2 = 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;
  }

  // print results every 100ms
  if (timeout > 100) 
  {
    if (count1 > 0) 
    {
      Serial.println(freq1.countToFrequency(sum1 / count1));
    } 
    if (count2 > 0) 
    {
      Serial.println(freq2.countToFrequency(sum2 / count2));
    } 

    sum1 = 0;
    sum2 = 0;
    count1 = 0;
    count2 = 0;
  }
}

Teensy 3.5
PWM Frequency input I have going in is at 5V logic level.
 
I just can't figure out what is going on here.

Static frequency, its fine. Let the input sit and it reads it fine.
Lower the frequency, its fine. Reduce the frequency and the output is smooth and works correctly.
Raise the frequency, and it has problems. The output stops, then starts, but often has glitches to 0 or lower numbers. Even increasing the frequency by 1Hz, the output stream pauses, glitches, and then when you stop increasing, it runs smooth.

I am using this for a windmill RPM sensor, so the frequency is changing all the time, and I just can't control the system with the output as it is.

Surely I cannot be the only one who is seeing this.
I thought it was my code, but I just put in the example in my first post, and it does it exactly the same.

Is anyone able to assist, please?

Thanks
 
Maybe it's a power thing?? But you do need to add timeout = 0; after count2 = 0; to keep from overrunning the serial monitor and to properly manage your timeout. (I jumpered 5 and 6 to pin 23 and used tone(23,freq) to change pin 23 frequency every so many times through loop() and didn't see any pauses.)

Can you attach a photo of your wiring? do you have common ground from sensors to T3.5?
 
Last edited:
Sorry yes I had timeout = 0 at the end in my main program, not quite sure why it didn't appear in my example above. Weird.
Ill test this again tomorrow.
Still strange though isnt it, how it works fine lowering freq but not raising... ?

Teensy 3.5 on the bench, simple PWM generator, signal and GND to the Teensy. Teensy with a 5V 30A PSU, VIN to VUSB cut. Plenty of juice.
Scope output showing perfect square pulses.

In my project application, I have this code running in a TeensyThread. I thought that might have been the problem, so did the example above but had the same result.
Could me missing the timeout=0 have a similar effect as running this in a thread?
Is the thread effecting the FreqMeasureMulti?

Code:
void readingsThread(void)
{
  while(1)
  {
    if (freq1.available()) 
    {
      sum1 = sum1 + freq1.read();
      count1 = count1 + 1;
    }
    
    if (freq2.available()) 
    {
      sum2 = sum2 + freq2.read();
      count2 = count2 + 1;
    }

    if (timeout > 100) // Every 100ms
    {
      if (count1 > 0) 
      {
        RPM1Input = freq1.countToFrequency(sum1 / count1);
        Serial.println("RPM1: " + (String)RPM1Input);
      }
      
      if (count2 > 0) 
      {
        RPM2Input = freq2.countToFrequency(sum2 / count2);
        Serial.println("RPM2: " + (String)RPM2Input);
      } 
      
      sum1 = 0;
      sum2 = 0;
      count1 = 0;
      count2 = 0;
      timeout = 0;
    }
  }
}

Given no one else is having this problem it has to be something stupid I am doing.
Totally has me stumped.
The timeout=0 missing in the example won't have helped me verify the demo vs my code though.

Any issues with threading and the library though?

Thanks
 
Problem solved.
Wasnt the code, the library, Teensy 3.5 hardware or any of that.

Was my frequency generator. For some reason, the output goes HI for a second or so when changing the frequency up, but not when changing it down.
Stupid, it never used to do this. Didn't do this when I scoped it initially, but now it's doing it all the time.

Anyway, I simulated the PWM with another embedded device and all is OK now.

Sorry to waste peoples time reading this.

Thanks
 
My function generator does that too, even though it's one of the more expensive Siglent ones. Not for 1 second, but long enough to require waiting a moment.
 
Status
Not open for further replies.
Back
Top