Frequency Counter

Hi everybody: I'm new to Arduino and programming, but reasonably good in electronics. I' m interested in the frequency counter of MARNAW, so I downloaded the two source code Zip files in both , the sketchbook and into Arduino-0017,/hardware/libreries ( to be on the safe side). The I just copied the original Marnaw's Example Program into my sketchbook . But it didn't work: as soon as I try to compile it, I get the following message: “ Error: 'Void' does not name a type” on line 2. :o I'm think I'm doing something wrong, but what? Can someone help me?

Thank you

Downloaded from where?

Can you post you sketch now?

I Downloaded the libraries from:

http://interface.khm.de/index.php/labor/experimente/arduino-frequency-counter-library/

And this is the sketch I just downloaded from Marnaw as it is:

#include <FreqCounter.h>

void setup() {
Serial.begin(57600); // connect to the serial port
Serial.println(“Frequency Counter”);
}

long int frq;
Void loop() {

FreqCounter::f_comp= 8; // Set compensation to 12
FreqCounter::start(100); // Start counting with gatetime of 100ms
while (FreqCounter::f_ready == 0) // wait until counter ready

frq=FreqCounter::f_freq; // read result
Serial.println(frq); // print result
delay(20);
}

Anything wrong ?
Thank you

Yes, there is something wrong. Void and void are not the same type. Change the return type for loop to void (with a lower case v).

Hey! You are magic! At least it compiles.
But still no results: only the first “Frequency Counter” printout and nothing else.

I connected a 4.5V square wave at pin 5 (protected by a 1.5KOhm).

I modified the sketch adding some check point (A,B,C) to see where it stops. It just prints a fast serie of “C” as if the parameter “frq” doesn’t exist (or empty).

And b.t.w. where is declared that pin 5 is an input?

What do you suggest? Is something I can do the get it running?

Thanks for your patient support. :slight_smile:

#include <FreqCounter.h>

void setup() {
Serial.begin(57600); // connect to the serial port
Serial.println(“Frequency Counter”);
}

long int frq;
void loop() {

FreqCounter::f_comp= 8; // Set compensation to 12
Serial.println(“A”);
FreqCounter::start(1000); // Start counting with gatetime of 100ms
Serial.println(“B”);
while (FreqCounter::f_ready == 0) // wait until counter ready
Serial.println(“C”);
frq=FreqCounter::f_freq; // read result
Serial.println(frq); // print result
delay(20);
}

What kind of Arduino are you using? The library seems to be defined for the Arduino with the 168 ship, not the 328.

And b.t.w. where is declared that pin 5 is an input?

The library is hard-coded to work with only that pin.

Yes: you are right: I'm using Arduino 328. So, should I forget abpou that sketch ? :( Can you suggest me a good Frq. Counter library/sketch for 328?

Thank you

I'm having the same problem, I got an Arduino with ATMega328, compiled the same software, fixed the capital V to make it compile, all that stuff and I have it connected straight to the PWM Timer1 output of another AVR (ATMega168 on my breadboard running a fan controller program I'm working on) and it isn't outputting any frequency. Is there any reason that the program only works on the 168 and not the 328 (last I checked they're identical chips except one has more memory)?

EDIT: Easy fix, whoever coded the frequency counter library threw in a check that only compiles the code if the target is an ATMega168, delete those two lines (the #if and #endif following it) in the FreqCounter.cpp file, save it, and then re-compile your Arduino code. it works great!

Great CalcProgrammer1. It works fine indeed !!! :D You are a genius ! Next time I'll sweep an oil lamp I'll expect you to pop up ;)

hello everybody is there a way to measure TWO frequencies, one in each of two signals? Or, even better, two frequencies in the same signal? In other terms, can arduino perform some FFT? thanks!

In other terms, can arduino perform some FFT?

Yes, of course. Google, and ye shall find.

Thanks AWOL In fact it seems like this topic is already being discussed on the forum. Anyway I am still trying to acquire an audio signal; then I'll be able to think about how to treat it. paolo

I have tried using this library (with modification for 328) and example sketch but I’m not getting results to the console. I’m using a Duemilanove with ATMega328.

It compiles and this is the output I see:

Frequency Counter
0  Freq: 0
1  Freq: 65536
2  Freq: 0
3  Freq: 0
4  Freq: 0
5  Freq: 0
6  Freq: 0

I’ve got a 250Hz square wave I’m trying to measure. Should I be feeding this into digital pin 5 or analog pin 5? I’ve tried every pin on the board with no luck.

Here’s the sketch:

// Frequency Counter Lib example
//
#include <FreqCounter.h>

// Switch on LED on pin 13 each second

void setup() {
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(7, OUTPUT);
Serial.begin(57600); // connect to the serial port

Serial.println(“Frequency Counter”);

}

unsigned long frq;
int cnt;

void loop() {

// wait if any serial is going on
FreqCounter::f_comp=106;
FreqCounter::start(1000);

while (FreqCounter::f_ready == 0)

frq=FreqCounter::f_freq;
Serial.print(cnt++);
Serial.print(" Freq: ");
Serial.println(frq);
delay(200);

}

It seems the frequency counter does work on my Arduino, as verified by the faulty grounding on my macbook sending a small 60Hz signal through my wooden desk and picked up by the bare Arduino PCB!

Unplugging the laptop fixes that anomaly but still the counter won't read any intentional signals!

Is there a minimum threshold voltage the signal must be for proper detection? Will it read a sine wave? Is there a "trigger" level that's not being met? I would love to get this to work!

Solved. I was accidentally sending ± signal to arduino. Vertical shift up fixed the issue.