Thanks guys, I think I will try the interrupt feature before anything else. I wasn't aware that this was possible.
Still kinda new with Arduino, programming, etc.
Very helpful!
Here is something I threw together that might help you get started:
// frequency counter
// Uses pin 2 interupt to measure frequency of signal input
// Note micros() function has a 4 us resolution so 1000hz can be 996.02 or 1,000 at 1,000
// retrolefty 2/4/11
volatile unsigned long isrPeriod;
volatile unsigned long start_time;
volatile unsigned long timestamp;
volatile byte first = 1;
unsigned long speed;
void setup() {
Serial.begin(57600);
Serial.println ("Frequency counter starting"); // signal initalization done
attachInterrupt(0, countP, RISING);
delay(100);
} // End of setup
void loop() {
delay(100);
noInterrupts();
long period = isrPeriod;
interrupts();
float freq = 1/(float(period) * .000001);
speed = long(freq);
Serial.print("Freq = ");
Serial.print(freq);
Serial.print(" ");
Serial.print(speed);
Serial.println(" Hz.");
delay(100);
} // end of loop
void countP()
{
timestamp = micros();
if (first)
{
start_time = timestamp;
first = 0;
}
else
{
isrPeriod = timestamp - start_time;
first = 1;
}
}
Lefty