I'm trying to measure some intervals that are too fast for the micros() function. So I want to use the clock cycle count (using ESP.getCycleCount) as the basis of my timing measurements. I ran a few tests to determine how feasible this approach is and the results weren't encouraging. Unfortunately, it seems that getCycleCount doesn't always take the same amount of time. But hopefully I'm doing something wrong.
My first test involved calling digitalRead followed by getCycleCount four times, storing the cycle count in a different variable each time. (Each digitalRead occurred on a different pin.) I expected the splits to be roughly the same, but they were wildly different. The same split across multiple runs was roughly the same, though. The following numbers are representative:
I then ran some tests using my oscilloscope. Basically digitalRead and getCycleCount calls sandwiched between digitalWrite High/Low pairs. Again I got wildly varying results - from as low as .3 microseconds to as long as 3.7 us. Doing just getCycleCount alone between the output pulses produced similar results.
Any ideas?