Hi,
I have been using the freqmeasuremulti library to measure frequency very well, however now I want to use the function freqmeasuremulti.countToNanoseconds() and I am getting some odd results. I tested it in my own program that is measuring the rpm of a bicycle crank and noticed an issue, so used a very stripped down version of the example provided and still get the wrong nanosecond values. I even put in 60,000,000 as the count expecting 1 billion ns as the return value, however I get 69,423,752. I have looked in the source code and have done the math by hand and it seems to work, but the value I am getting is not correct. I have also compared the count value vs the pulse width on the oscilloscope and they match up, so something is happening with the function to return the correct ns value. Maybe it is some simple error I am doing, but can't figure it out for the life of me. Thanks in advance.
PS- Hooked up a signal generator just to test more HZ and it seems to stop sending the correct nanoseconds at 13.9hz, 14hz is fine (71427248ns), however 13.9hz gives me 358328.41ns, but the sum of the count is correct. This is driving me crazy and hope someone has a bit more insight into the issue. Also countToFrequency returns the correct value in Hz.
I have been using the freqmeasuremulti library to measure frequency very well, however now I want to use the function freqmeasuremulti.countToNanoseconds() and I am getting some odd results. I tested it in my own program that is measuring the rpm of a bicycle crank and noticed an issue, so used a very stripped down version of the example provided and still get the wrong nanosecond values. I even put in 60,000,000 as the count expecting 1 billion ns as the return value, however I get 69,423,752. I have looked in the source code and have done the math by hand and it seems to work, but the value I am getting is not correct. I have also compared the count value vs the pulse width on the oscilloscope and they match up, so something is happening with the function to return the correct ns value. Maybe it is some simple error I am doing, but can't figure it out for the life of me. Thanks in advance.
PS- Hooked up a signal generator just to test more HZ and it seems to stop sending the correct nanoseconds at 13.9hz, 14hz is fine (71427248ns), however 13.9hz gives me 358328.41ns, but the sum of the count is correct. This is driving me crazy and hope someone has a bit more insight into the issue. Also countToFrequency returns the correct value in Hz.
Code:
#include <FreqMeasureMulti.h>
// Measure 3 frequencies at the same time! :-)
FreqMeasureMulti freq1;
void setup() {
Serial.begin(57600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(10);
Serial.println("FreqMeasureMulti Begin");
delay(10);
freq1.begin(6);
}
float sum1=0, sum2=0, sum3=0;
int count1=0, count2=0, count3=0;
elapsedMillis timeout;
static uint32_t a=60000000;//should be 1,000,000,000ns
void loop() {
if (freq1.available()) {
sum1 = sum1 + freq1.read();
count1 = count1 + 1;
}
// print results every half second
if (timeout > 500) {
if (count1 > 0) {
Serial.print(freq1.countToNanoseconds(a));
} else {
Serial.print("(no pulses)");
}
Serial.println();
sum1 = 0;
sum2 = 0;
sum3 = 0;
count1 = 0;
count2 = 0;
count3 = 0;
timeout = 0;
}
}
Last edited: