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.

Here is an improved version of the frequency counter sketch. There were a couple of problems with the previous version:

- when you attach the interrupt, you can get an immediate interrupt if this input is already high. This resulted in some jitter in the frequency reading. So I now ignore the first interrupt.

- if the pulse count (i.e. frequency multiplied by the sample time in seconds) was greater than about 4000 then the calculation would overflow. So I have changed it to use floating point calculation instead. This also give a more precise result when the number of cycles counted is low.

void setup(){ Serial.begin(19200); // this is here so that we can print the result pinMode(3, OUTPUT); // put a PWM signal on pin 3, then we can connect pin 3 to pin 2 to test the counter analogWrite(3, 128);}

One thing I found while testing this is that the PWM frequency on pin 3 is not 488.28Hz as documented at http://playground.arduino.cc/Main/TimerPWMCheatsheet, it is in fact 490.20Hz. This makes sense, since timers 1 and 2 on the Uno are configured in phase-correct PWM mode, in which the timer counts from 0 to 255 and then back again, giving 510 steps not 512. The PWM frequency on pin 5 (controlled by timer 0 in fast PWM mode) is 976.57Hz as documented.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

To measure the frequency of a sine wave, you can either convert it to something resembling a square wave using additional hardware, or you can use the built-in analog comparator. I have found that the analog comparator is extremely sensitive and you need good wiring layout to avoid getting spurious counts due to noise.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.