Frequency Counter Library

michael_kaeppler:
Hi all,
I'd like to ask the question why it is necessary to disable Timer0 before starting the counting process?

  • Michael

Most likely because the free running timer0 interrupts used by the arduino start-up code to support the delay() and millis() and micros() function would add a element of variable latency to responding to the timer interrupt used by the frequency counter function.

Hi, I'm trying to use Arduino Uno with 2 flow sensors.
They pulse at 3300 per litre. I have them hooked up to pins 4 and 5 on my arduino.
My question is can I use FreqCounter to read each one separately and over a 1 second period?
I have looked through the code and I can't see anywhere to allocate the pins I want it to read..

Hi, I'm trying to use Arduino Uno with 2 flow sensors.
They pulse at 3300 per litre. I have them hooked up to pins 4 and 5 on my arduino.
My question is can I use FreqCounter to read each one separately and over a 1 second period?
I have looked through the code and I can't see anywhere to allocate the pins I want it to read..

I've had a quite look through the C++ coding. If I change every occurance of T1 with the relevant T number for pin4 or 6?
If anyone knows where i can find those T numbers that would be awesome :slight_smile:

I am new to the site, but I have been programming micros and Arduino for a little time now. I like the code and it works great. I am using it with a variable reluctance sensor and some support circuitry. I wanted to use you code and take the frequency value and output an analog signal in a ratio of the frequency. For example I take the frq from the example and ledBrightness=map(frq,0,fastestFrequency,0,255) but i cannot seem to get a signal out with the analogWrite() command. Does this library mess with the timer that controls the PWM timing of the analogWrite() command?

Been using the Frequency Measurement Library, it's great. Been using it to measure the speed and RPM on my car. Is there a way of measuring 0 frequency to show 0 speed or 0 RPM at all?

Thanks.

matinzk:
Been using the Frequency Measurement Library, it's great. Been using it to measure the speed and RPM on my car. Is there a way of measuring 0 frequency to show 0 speed or 0 RPM at all?

Thanks.

Just as a heads up, if you are getting your signal from a hall effect sensor you should be able to read zero speed, but from what I have been looking up, most speed sensors are a much cheaper variable reluctance sensor. As I understand it, variable reluctance (VR) sensors do not do well at slow speeds. This code and my VR sensor off of a Borg-Warner T5, for a S-10, cannot go down to 0 rpm. I can only get to 10s or rpm. Hall effect sensor can take true zero speed measurements. Good luck.

I am using this:
http://interface.khm.de/index.php/lab/experiments/frequency-measurement-library/

Are we talking about the same library? Is the above library in the link able to detect zero RPM and speed?

This is the hall effect sensor we use: http://www.digital-speedos.co.uk/hall-effect-speed-sensor-for-drift-gauges-non-magnetic-382-p.asp

Have you considered using a light based counter? Shine an IR light at whatever is spinning and fix piece of something shiny to it. Then point an IR detector at it which should detect rotation.

How can I do this with a car? Especially the engine rpm?

matinzk:
How can I do this with a car? Especially the engine rpm?

Maybe you can fix something shiny or use shiny paint on one of the main belts?

Please do not paint belts. The paint may damage the belt (thanks to the enclosed / entrained solvents) and lead to premature cracking. Not only are modern belts very expensive to replace, losing one will usually leave you stranded. Not the best way to impress the missus.

Instead use a hall-effect or optical rig on a sprocket or similar device that does not need physical modification.

Constantin:
The paint may damage the belt (thanks to the enclosed / entrained solvents) and lead to premature cracking.

Honestly this is not my place to expertise but it would seem there is certain types of paints that would not be a problem.

Not only are modern belts very expensive to replace, losing one will usually leave you stranded. Not the best way to impress the missus.

Last time I looked, the belts were not all that expensive. But losing one can indeed leave you stranded but alas this is a risk with any type of engine modification.

SmeezeKitty, do as you wish.

All I can tell you is that I had to replace every rubber hose on a diesel engine because some lugnut sprayed them with the same 'Perkins blue' as the rest of the engine. And to do that, we got to lift the engine out of the boat, drain it of all fluids, etc. Not the fastest fix.

Every hose had cracked thanks to this painting treatment. Given how important belts are, I wouldn't mess with them and pick up the desired signal elsewhere.

I got this to work well on one sensor, using my Arduino UNO.

But I have not been able to get it to work at all on a Leonardo. [ Serial doesn't even print the 'Frequency Library' line at the start] Have there been major changes to serial for Leonardo?

Another question is, how would I be able to expand this to multiple sensors without using multiple Arduinos?

Hello to everybody, first of all I'm not an expert altought I have succeed so far with some small Arduino based project.
I'm now trying to develop a radioastronomic receiver (radiometer) controlled by Arduino.
Now the topic:

  • I have an Arduino Uno rev.2 with an Ethernet shield with microSD slot (both not yet used, but useful later on)
  • In order to control the receiver I have to program 2 different PWM on 2 different pins
  • for what I read on the web pages, I can use the instruction analog.write(pin,pwm) on the pins 3,5,6,9,10,11 if not already used by other devices
  • the pin 5 (T1) is used to read the OL frequency of the receiver by means of the library FreqCounter.h herewith discussed..
  • pin 3 seems to be used by the Eth shield as well as the pins 0,1,2,4,10,14,15
  • thus, "fre to be used" for my purpose, remain the pins 6,9,11

Unfortunately only the output on the pin 6 works. Pins 9 and 11 always are at low level, no PWM, even with no shield on top of the Arduino Uno.
The board works fine is I do not call the frequency reading routine.
What I'm doing wrong? Waht shall I do to fix the trouble?
On the following a draft of the cose I'm using. Please note it's a very early draft of what I would do, so several variables are defined but not used yet.

Many thanks to all for the help!
Pierluigi

#include <FreqCounter.h>

// OL input on digital pin #5

const short pwm1=9; // pin 9 is 8 MSB PWM
const short pwm2=6; // pin 6 is 8 LSB PWM

long int frq; //frequency read
long int IF=10700000; // first IF of the Rx
const short prescaler=8; // scale factor of the ext. prescaler
const long int fastro1=25610000; // astro1 = 1st frequency
const long int fastro2=13385000; // astro2 = 2nd frequency
long int OLnow; // current OL frequency
long int RXnow; // current RX frequency
long int errore=0; // frequency error

int pwmh; // 8 MSB of PWM
int pwml; // 8 LSB of PWM

float Vastro1=0.2035; // VCO nominal input for fastro1
// float Vastro2=3; // VCO nominale per rx frequenza fastro2

int bitbase1=Vastro165535/5; // total PWM bits (res.16) of feed forward VCO a freq. astro1
// int bitbase2=Vastro2
65535/5; // bit di PWM totali (risoluzione 16) del feed forward tensione VCO a freq. astro1

void setup() {
Serial.begin(9600); // connect to the serial port
Serial.println("Frequency Counter");
}

void loop() {

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

frq=FreqCounter::f_freq; // read result
OLnow= frq*prescaler; // OL frequency calculation
RXnow= OLnow-IF; // RX frequency from IF and OL
errore= RXnow-fastro1; // tuning freq. errorcalcolo errore di sintonia

pwmh= bitbase1/256;
pwml= bitbase1-256*pwmh;

analogWrite(pwm1, pwmh);
analogWrite(pwm2, pwml);

Serial.print("bitbase1= ");
Serial.print(bitbase1);
Serial.print(" pwmh= ");
Serial.print(pwmh);
Serial.print(" pwml ");
Serial.print(pwml);
Serial.print(" frq= ");
Serial.print(frq);
Serial.print(" OLnow= ");
Serial.print(OLnow);
Serial.print(" RXnow= ");
Serial.print(RXnow);
Serial.print(" Errore= ");
Serial.println(errore);
delay(20);
}

How about a variation on the frequency counter lib that takes its input from the analog comparator? This would avoid the need for a preamplifier. You wouldn't be able to count the input directly in counter 2 because AFAIK it can't be clocked from the analog comparator output. However, you could use the analog comparator interrupt to count pulses, and use timer 1 as before to define the gate time.

Hey,
first of all, thanks for the great library!

I have a small issue with my LEDs and this library. They are working if I give them the value "HIGH" or "255". But however they are not working with a lower value. I have tested the leds in an other sketch. So they are correctly wired and working fine, also the arduino. It seems to be a problem with the "FreqCounter::start(100);", if I remove it, the lower values are working, but of course the frequency counter not...

has someone an idea? thanks in advance!

Assuming you mean the frequency counter library at http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/, it uses timers 1 and 2, and disables timer 0 during the gate time. This means that none of the PWM pins on a Uno will work while you are measuring a frequency.

If the frequency you want to measure is less than about 10kHz, there are other ways of measuring it that take over only one timer, or even no timers at all.

Sorry, I forgot to mention it ... you are right, I am using this library: http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/. And I am using a Arduino Duemilanove.

The frequency I'd like to measure are under 10kHz. Do you have an example code in which one or more timers are disabled? I tried to look for an other library, but all of them are using the 3 timers ... so I would be really glad if you can help me out!
thanks in advance.

  1. What will be the approximate frequency, and how accurately do you need to measure it?

  2. Will the input be a 5V square wave, or would you like to use the built-in analog comparator to allow much smaller input signals?