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

Thread: FreqMeasure

  1. #1
    Junior Member
    Join Date
    Mar 2016
    Posts
    4

    FreqMeasure

    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.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,938
    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

  3. #3
    Junior Member
    Join Date
    Aug 2015
    Posts
    18
    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.

  4. #4
    Junior Member
    Join Date
    Mar 2016
    Posts
    4
    thank's for your answers. I will try all the options !

  5. #5
    Junior Member
    Join Date
    Aug 2015
    Posts
    18
    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.

  6. #6
    Junior Member
    Join Date
    Mar 2016
    Posts
    4
    Click image for larger version. 

Name:	freqmeasure errreur.jpg 
Views:	234 
Size:	80.2 KB 
ID:	6992
    Can you see the image.

  7. #7
    Junior Member
    Join Date
    Aug 2015
    Posts
    18
    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/Fr...ive/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.

  8. #8
    Hi all,
    I know it is an old post but it is the most recent that I can find related to my question and I have opened so many new posts asking questions lately so I didn't want to start yet another one.
    So I want to measure the frequency of a 50 Hz sine-wave (I have already mentioned details in that post:https://forum.pjrc.com/threads/35379...t=freq+measure).
    Because I use FTM0 module for an other function I can't use FreqMeasureMulti.
    So I want to go back to the old FreqMeasure.
    I have teensy 3.2 with Arduino 1.6.6 and teensy loader 1.26.
    inside the folder \Arduino\hardware\teensy\avr\libraries I have the FreqMeasure library and the FreqMeasureMulti library but I can't include the FreqMeasure in my sketch.
    Is there a way to use FreqMeasure?

    Thank you for your time.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,734
    FreqMeasure uses FTM1, not FTM0.

  10. #10
    Yes, That's why I want to use it instead of FreqMeasureMulti (which I think uses FTM0).
    Anyway I somehow made it work. I deleted the FreqMeasureMulti library and reinstalled FreqMeasure because for some reason the arduino didn't let me use the FreqMeasure when both libraries existed.
    Since I don't need the *Multi for my project, it is ok to delete it for the moment.
    Thanks for your time Paul.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,734
    Quote Originally Posted by JohnKon View Post
    ... 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.

  12. #12
    I don't know how to demonstrate the conflict but I will try to explain.
    I had both the frequencymeasuremulti and the freqmeasure libraries in the arduino library folder \Arduino\hardware\teensy\avr\libraries.
    In the arduino software I could see both libraries however when I tried to include the freqmeasure library from Sketch -> include library, it wouldn't include the freqmeasure but the freqmeasuremulti. Also when I was trying to load the freqmeasure examples the corresponding frqmeasuremulti examples were loaded. Lastly when I was trying to manually include the freqmeasure library the inclusion didn't change color to orange.
    I am running arduino 1.6.6
    I read all the files for both libraries several times but I didn't find any reference in one library to the other so I deleted them both and installed the freqmeasure. Now it works find but I haven't installed the freqmeasuremulti
    Last edited by JohnKon; 07-24-2016 at 12:21 AM.

  13. #13

    Question

    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:
    Click image for larger version. 

Name:	Captura de pantalla de 2017-01-04 03:53:11.jpg 
Views:	158 
Size:	120.2 KB 
ID:	9289
    (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):
    Click image for larger version. 

Name:	Captura de pantalla de 2017-01-04 03:58:18.jpg 
Views:	117 
Size:	119.6 KB 
ID:	9290

    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 by marcos daniel; 01-04-2017 at 07:11 AM.

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,734
    Quote Originally Posted by marcos daniel View Post
    so I added a comparator (lm393) and a using a trim pot, I got the blue analog values:
    Click image for larger version. 

Name:	Captura de pantalla de 2017-01-04 03:53:11.jpg 
Views:	158 
Size:	120.2 KB 
ID:	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?

  15. #15
    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)
    Click image for larger version. 

Name:	Paul.png 
Views:	322 
Size:	271.5 KB 
ID:	9317
    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

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

Posting Permissions

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