Timer 1 to count the time between comparator interrupts,
Wouldnt using interrupts be a better method of calculating durations? this has a 4-microsecond accuracy
This will display the current reading every 50 milliseconds but it will update the time every cycle.the
Like:
volatile unsigned long DurationTime;
volatile unsigned long XTime;
volatile unsigned long LastTime;
void XTimer( )
{
XTime = micros(); // micros() return a uint32_t
DurationTime = XTime - LastTime; // Calculate the change in time
LastTime = XTime; //store the time
}
void setup() {
attachInterrupt(0, XTimer, RISING );// Set interrupt on pin 2 (interupt 0)
Serial.begin(115200);
}
void loop() {
static unsigned long SpamTimer;
if ((millis() - SpamTimer) >= (50)) {
SpamTimer = millis();
Serial.println(DurationTime);
}
}
Z