I'm developing with the Arduino UNO a device that uses a TSL238 light-to-frequency photodiode to measure light.
Just because in astronomy the 'standard' is a negative logaritmic one unit, I use log10 function (from math.h) here to pass from Hz (output of the TSL237, measured with pulseIn as the pulses are pretty slow for FreqCounter and FreqPeriod) to the logaritmic unit system with an offset of 22.0 .
magnitude = 22.0-2.5*log10(frq);
But something isn't ok with that simple operation.
1.03hz => 21.970mag
1.01hz => 21.994mag (that's OK, decreasing frequency means higher magnitude)
0.92hz => 22.91 (that doesn't seem to be correct. I expected 22.091)
0.91hz => 22.98 (also incorrect!)
0.78hz => 22.272 (correct!)
0.64hz => 22.480 (correct!)
What is wrong in the 22.0-2.5*log10(0.92) and 22.0-2.5*log10(0.91) ?
Update. Maybe it's losing a digit between . and 9?. I mean 22.091 and 22.098 sounds pretty accurate. I'm using the printDouble function from here:
http://www.getbugged.com/2008/11/22/how-to-serialprint-a-double-on-an-arduino/ (original version wrote by Mem here in the Arduino forums,
http://arduino.cc/forum/index.php/topic,44216.0.html) to get a bit more decimals.
Thanks in advance,
Minaya