Pages: [1]   Go Down
Author Topic: Frequency Counter  (Read 5995 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Downloaded from where?

Can you post you sketch now?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Quote


#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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, there is something wrong. [glow]V[/glow]oid and [glow]v[/glow]oid are not the same type. Change the return type for loop to void (with a lower case v).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley

Quote
#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);
}

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thank you
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: January 14, 2010, 01:26:18 pm by CalcProgrammer1 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great CalcProgrammer1.
It works fine indeed !!! smiley-grin
You are a genius ! Next time I'll sweep an oil lamp I'll expect you to pop up  smiley-wink
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26219
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In other terms, can arduino perform some FFT?
Yes, of course.
Google, and ye shall find.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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:


Quote



// 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);


 
  
}  

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: