I want to measure a frequency of 2-3khz very precise.
For that I simply used a counter in a while loop.
The results accuracy was ok, but every second the duration was a bit shorter (one peak) and every ten second the duration was shorter over a few points.
Here's a plot of the signal:
Because the peaks are always with the sam timedifference, I thought that the problem would be, that two interrupts trigger at 1 and 0.1Hz. I tried to stop them with cli(); but that didn't change anything. I'd say it got even worse...
So is this an interrupt, that I can't disable or what else could it be?
I am using a Teensy 4.1 with Teensyduino 1.53 and Arduino 1.8.5 on Windows.
P.s. just adding the durations over 10s doesn't work for me, because I need to have the data with at least 80Hz.
For that I simply used a counter in a while loop.
Code:
for (int i = 0; i < 10; i++) {
while (digitalReadFast(9) == HIGH)
duration++;
delayMicroseconds(1); //just for stability
while (digitalReadFast(9) == LOW)
duration++;
delayMicroseconds(1);
}
The results accuracy was ok, but every second the duration was a bit shorter (one peak) and every ten second the duration was shorter over a few points.
Here's a plot of the signal:
Because the peaks are always with the sam timedifference, I thought that the problem would be, that two interrupts trigger at 1 and 0.1Hz. I tried to stop them with cli(); but that didn't change anything. I'd say it got even worse...
So is this an interrupt, that I can't disable or what else could it be?
I am using a Teensy 4.1 with Teensyduino 1.53 and Arduino 1.8.5 on Windows.
P.s. just adding the durations over 10s doesn't work for me, because I need to have the data with at least 80Hz.