I will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?
Quote from: Corpze on Mar 01, 2013, 12:51 amI will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?For single samples you get 1086. Why? I don't know!freq = (pulses*1000)/(period*area);Is it any surprise that 10 pulses gets 10x the freq?Also you should mix your mixed-types math. As above you have by types: long = (long * int) / (short * float) <<=== not a good ideaThat whole business needs a total going-over. You can throw in casts (tell the compiler to treat a variable as a different type) but if you're not careful you won't get the equation you think. Without casts, as it is now, you're letting the compiler decide.Example of casting:long L;int I = 1000;float F = 0.1;L = (long) ((float I) * F);And thanks to the floating point math, the result won't likely be 100L. Yes 100L because it's cast as a long to go into a long variable. 100 is a 16-bit signed integer. 100L is a 32-bit signed integer. If the letter U is used, 100U is a 16-bit unsigned integer and 100UL is a 32-bit unsigned integer.If you use a constant and want it seen as a floating point then put in a decimal point, 100.0 is a 32-bit floating point value.Give the compiler less room to wiggle and you may get more predictable results.
But you are talking about pulses, the sensor outputs a frequency, that isn´t the same?
freq = (pulses*1000)/(period*area); irradiance = (freq/1000); magnitude = ZP - 2.5*log10(freq);