FreqMeasure

Status
Not open for further replies.

Benjamin

New member
Hello, I am a French student. I try to measure the speed of an object. I use te following program :

#include <FreqMeasure.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
Serial.begin(57600);
lcd.begin(16, 2);
lcd.print("Freq:");
lcd.setCursor(10,0);
lcd.print("Speed:");
FreqMeasure.begin();
}


double sum=0;
int count=0;


void loop() {
if (FreqMeasure.available()) {
// average 30 readings together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
float frequency = FreqMeasure.countToFrequency(sum / count);
float spd = frequency / 19.49;
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(frequency);
lcd.print("Hz");
//lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(spd);
lcd.print("km/h");
sum = 0;
count = 0;
}
}
}

But I havea problem, the does not wokit seems that lack a file from the Library. Someone could explain me how to solve this problem.
 
Working through some basics, apologies if this is to basic
Is Arduino installed correctly -> can compile blink for Uno
Is Teesyduino installed -> do you have teensy options on the boards menu
Do you have the right device -> tools -> board - > some sort of teensy
Does the LCD library hello world example work -> file -> examples -> liquid crystal -> hello world
Does the frequency measure serial library example library work?

On my system here the code compiles without error (but not actually loaded to a device) without error
 
If it looks like there is a file missing, you could always try to install the library manually by downloading it from GitHub and simply copying it to the "libraries" folder or by using "Add .ZIP Library" in the Arduino IDE menu.
 
In addition, if you still cant figure it out, posting the error log might give us a better understanding. If you go into the Arduino IDE settings and turn on "verbose output during compilation" and copy that log into a reply then that should provide the full picture.
 
freqmeasure errreur.jpg
Can you see the image.
 
Ok cool, thank you for posting that. It looks like it is using a legacy version of the library which might not have the method "countToFrequency()." To solve this please download the zip from Paul's Github: https://github.com/PaulStoffregen/FreqMeasure/archive/master.zip

Once it is downloaded, you will want to go to C:\Users\HOCQUINGMEM\Documents\Arduino\libraries\ and delete "FrequencyMeasure...."

Then go back into Arduino and go to "Sketch->Include Library->Add Zip Library" and select the zip that you just downloaded.

Let me know if this helps.
 
... for some reason the arduino didn't let me use the FreqMeasure when both libraries existed.

Could you post a program which shows the conflict? It's possible there's something I've overlooked, but I don't know what. I really need to a see a program which causes the conflict if I'm going to find a way to permanently solve it for everyone in future versions.
 
Hello!
I'm also having some trouble with freqMeasure...
What I want to do is to control the speed of a DC motor by PWM.
As first step, I attached a little magnet to the axis of the motor, and using a linear hall effect sensor (AH3503), I get the yellow signal from serial port. I was not sure that signal would be appropiate for the measurement, so I added a comparator (lm393) and a using a trim pot, I got the blue analog values:
Captura de pantalla de 2017-01-04 03:53:11.jpg
(Microseconds are converted to seconds)
The frequency is roughly about 80Hz.

But when I try to use de library (without moving anything, just the comparator's ouptut from pin A6 to D3), I get variable and higher values (average around 350Hz):
Captura de pantalla de 2017-01-04 03:58:18.jpg

The code used to get the blue and yellow plots is the following:


void setup() {
Serial.begin(9600);
pinMode(5,OUTPUT);
analogWriteResolution(12); // these settings
analogWriteFrequency(5,732.4218); // are arbitrary
analogWrite(5,400); // just for testing
}

void loop() {

for (int i=0; i<1000; i++) {
Serial.print(micros());
Serial.print(" ");
Serial.println(analogRead(6));
}
delay(15000);
}

and the code to measure frequency is the example with a slight modification, just to let the motor spin in the same condition of the preceeding test.


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

void setup() {
Serial.begin(57600);
FreqMeasure.begin();
//begining of modification for the test
pinMode(5,OUTPUT);
analogWriteResolution(12);
analogWriteFrequency(5,732.4218);
analogWrite(5,400);
//end of modification
}

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);
Serial.println(frequency);
sum = 0;
count = 0;
}
}
}
 
Last edited:
so I added a comparator (lm393) and a using a trim pot, I got the blue analog values:
View attachment 9289
(Microseconds are converted to seconds)
The frequency is roughly about 80Hz.

I notice some small issues when the waveform it high. Perhaps those are actually much larger problems, but not visible with the limited sample rate or bandwidth of whatever instrument you're using?

Voltage comparator circuits can be prone to false triggering without hysteresis. A good power supply decoupling capacitor is usually also needed.

Maybe post the circuit you built and a photo of how it's constructed?
 
Hello Paul, thanks for your reply!

I did not use any instrument, those values plotted are the ones Teensy (3.1) sends through Serial Port (I just copied them and pasted on a spreadsheet).
I made a drawing of my circuit (excluding the part of the motor, and sorry because of using ms-paint, I'm not electronic at all)
Paul.png
To obtain the yellow waveform, the only diference in the circuit is that the hall sensor is directly connected to analog imput 6 instead of comparator's in.
I also noticed those issues (and not only when the signal is high, look at the other plots...)
Where should I put the capacitor, and which capacity shoud it have?
I have another comparator (LM339, which is quadruple), a couple of months ago I had done some preliminary tests with the same scheme, and I hadn't have any problem, but in fact I didn't plot the signal that time, I just conected and tested the frequency was being measured. I'll test it again to see if that is the problem.
Kind regards,
Marcos
 
The LM3xx comparators need a pull up resistor of max. 3.3k at their output to work correctly. The internal pull ups of the digital inputs and your 19k resistor have a too high resistance which leads to "unclean" signal ramps.
 
Status
Not open for further replies.
Back
Top