hallo , after many tests made with interrupt i was not able to count pulses on an arduino pin with a pulse frequency over 200 hz without loosing them.
i looked for a program using internal arduino counter connected to pin 5 to the timer used as a counter. it seem to work and i did some changings but i was not able more to see it working.
may you help me about ?
this is listing
/*
Count pulses on pin 5 via Timer-1
Start with rising edge on pin 2
Stop with falling edge on pin 2
ToDo:
- deal with overflows
*/
unsigned long counts;
void setup() {
Serial.begin(19200);
// pinMode(2, INPUT); digitalWrite(2, HIGH); // trigger on pin-2 = PD2 = interrupt-0
pinMode(5, INPUT); digitalWrite(5, HIGH); // pulses on pin-5 = PD5 = T1
TCCR0A=0; // setup timer-0
TCCR0B=0;
TIMSK0=0;
TCCR2A=0; // setup timer-2
TCCR2B=0;
TIMSK2=0;
TCCR1A=0; // setup timer-1
TCCR1C=0;
TIMSK1=0;
GTCCR=0;
TCNT1=0; azzero contatore
}
void loop() {
Serial.println ("Pstart...............................");
while (counts<1000) {
TCCR1B=0; // stop count
counts = TCNT1; // read count
Serial.print ("counts ....");// print count
Serial.println (counts);
TCCR1B=7; // start count
delay(100);
}
Serial.println ("end........................")
Serial.print ("counts .");
Serial.println (counts);
TCNT1=0;
}