Thanks rvnash. For now, since I know it is a Photon, I hardcoded the rollover time and it seems to work. MAX_MICROS is simply 2^32/120
void isrduration1()
{
// if the pin is low, its the start of an interrupt
if(digitalRead(D3) == LOW)
{
StartPeriod1 = micros();
}
else
{
// if the pin is high, its the rising edge of the pulse so now we can calculate the pulse duration by subtracting the
// start time from the current time returned by micros()
if(StartPeriod1 && (pulse1 == false))
{
EndPeriod1 = micros();
if(StartPeriod1 < EndPeriod1)
duration1 = EndPeriod1 - StartPeriod1;
else
duration1 = MAX_MICROS - StartPeriod1 + EndPeriod1;
StartPeriod1 = 0;
pulse1 = true;
}
}
}
Can anyone point me to the docs for this, please - Iām a huge fan of free-running unsigned counters, and am massively glad to hear this is done, now I just want to learn how to use it right.
I recall that the usual micros() is to read the millis() timer count, know its freq. and calculate micros within the current millis() interval (i.e., interpolating).
Then multiply last millis() count to be micros and add the interpolation value.
Thanks stevech, yes, thatās how I re-implemented it. Previously it was taking a 32-bit clock counter and dividing it, resulting in a rollover period of 2^32 / Clock_Hz.