long start, stop = 0;
volatile long Timer2_overflow_counter = 0;
long duration = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
TCCR2B = (1 << CS21);
TIMSK2 = (1 << TOIE2);
}
void loop() {
/*
start = micros();
// put your main code here, to run repeatedly:
//Serial.println(runtime);
delayMicroseconds(2000);
stop = micros();
duration = (stop - start);
Serial.println(duration);
*/
/*
Serial.print(micros());
Serial.print(" ");
Serial.println(runtime());
*/
delay(1000);
}
ISR(TIMER2_OVF_vect){
Timer2_overflow_counter++;
//Serial.println(Timer0_overflow_counter);
}
long runtime(void){
uint8_t timer2_value = TCNT2;
long duration = (Timer2_overflow_counter * 32768 ) + (timer2_value * 64);
return duration;
}