problems using ESP.getCycleCount to measure intervals
Posted: Thu Mar 15, 2018 1:32 am
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:
Any ideas?
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:
- count2 - count1: 588
- count3 - count2: 52
- count4 - count3: 332
Any ideas?