Go Down

Topic: Arduino Mega 2560 frequency measure not working for me (Read 238 times) previous topic - next topic

tplum

I have been measuring frequency (via FreqMeasure lib) with Uno with no problems.  I upgraded to Mega 2560 and cannot get the freq measure to work.  I know my input signal (set with "tone" in the code below) is working as I have it hooked to an oscilloscope in real time when trying the FreqMeasure code.

References I have been using:
- My homework:  https://www.pjrc.com/teensy/td_libs_FreqMeasure.html#otherarduino
- FreqMeas Lib:  https://github.com/PaulStoffregen/FreqMeasure


My basic program:

//trying to read oscillating signal through pins 47, 48, or 49 - none work for me.

Code: [Select]
#include <FreqMeasure.h>
void setup() {
  tone(7, 1000);    // set up oscillating signal on Digital I/O 7.  Connect this pin to inputs 47 or 48 or 49
  Serial.begin(9600);
  FreqMeasure.begin();
}
void loop() {
    float freq = FreqMeasure.countToFrequency(FreqMeasure.read());
    Serial.println(freq);   // Always reads 0
    delay(1000);
}


Given the lack of success, I have been trying to read off of pins 47, 48, and 49.  From my homework, I thought 49 was the correct one... but no luck.  In addition, I have tried using either CAPTURE_USE_TIMER4 or CAPTURE_USE_TIMER5 in my \libraries\FreqMeasure-1.2.0\util\FreqMeasureCapture.h file, shown here:

Code: [Select]

// Arduino Mega
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
//#define CAPTURE_USE_TIMER4       // ICP4 is pin 49
#define CAPTURE_USE_TIMER5    // ICP5 is pin 48




I also tried the FreqCount (https://github.com/PaulStoffregen/FreqCount) option, but get an error when calling it from my program via the #include <FreqCount.h> statement.

I am stuck... any suggestions?

Thank you!

tplum

Ah, I appologize... the code above works, but it cannot measure a 1kHz signal. It is working for slower signals.  Interesting on the Uno, I can measure much faster signals with this code. 

Delta_G

If you want responses, ask one of the mods to move this to an appropriate section.  You picked a section that CLEARLY says

Quote
For problems with Arduino itself, NOT your project
So you are being ignored for the most part.  It might help to go read the documentation on the library you are using if you haven't.  There might be many clues in there.  When I looked, it mentioned something very specific about the 1kHz line. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up