Hi,
Im using micros() to read a frequency between around 10 and 150Hz.
Im using this code:
void readDiff() {
uint32_t currentTime = micros();
diff1 = currentTime - timer1;
timer1 = currentTime;
}
Since micros() returns a uint32_t (unsigned long), timer1 is defined as uint32_t and diff1 is defined as uint16_t.
This works OK. My problem is that I get some weird numbers on some even frequencies.
For example:
100Hz -> 10000 microS. -> OK
99 Hz -> 10100 microS. -> OK
98Hz -> 42972 microS. -> Wrong
97Hz -> 10310 micros. -> OK
96 Hz -> 43185 microS. -> Wrong
95 Hz -> 10527 microS. -> OK
94 Hz -> 43406 microS. -> Wrong
and so on...
This starts at around 65Hz.. Im trying to hook a oscilloscope to my circuit tomorrow but this should be a normal 3.3V Pulse Signal.
Any ideas?