Go Down

Topic: Measure nightsky with TSL237 (Read 12 times) previous topic - next topic

GoForSmoke


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?


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 idea

That 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.
I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Corpze

#26
Mar 01, 2013, 03:55 am Last Edit: Mar 01, 2013, 04:12 am by Corpze Reason: 1


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?


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 idea

That 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.



To be honest, i don´t understand anything of what you just wrote :/

Maybe i should just start over with a basic frequency counter and go from there?

Basicly, all i wanna do is translate frequence to mag/arcsecond2, and because the sensor is linear, wouldn´t it be quite easy to do that?

I am fairly new to arduinos and coding, i have just got a steppermotor to work with two buttons and a lcd-display :/

Is this the way to go maybe?:

I have one sensor, capable of sending between 0.00x Hz to 1000kHz
I also have a luxmeter, so i can calibrate the sensorvalue roughly.

if i has a light that shines with 100 lux, and the sensor is sending 20 kHz, can i from there convert to mag/arcsecond2?

I dont need any pulsecounter any else of the data, i am just interested of Mag/AS2

Is this possible?

BR/ Daniel

GoForSmoke

How about get the setup working without converting to frequency and -then- take that step?

Just show the pulses, your raw data, as you point at darker or lighter things right in the house. That will let you test and debug everything but the convert and I and or others will walk you through the conversion to the best of our abilities?

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Corpze

That sounds good :)

But you are talking about pulses, the sensor outputs a frequency, that isn´t the same?

is Pulse the time and freq the hight of the wave? And the dutycycle of the sensor is 50%, is that because it ouputs a square wave or something?

I did all the maths in the sketch last night, just to see how things work together like pulses, frequency an so forth. One thing i i stumbled upon is the "Gate time", what exactly is that, because that one is set to 100ms in the sketch, but somwhere on the internets, i read that the Gatetime should be set to 1000ms to get "the true freq of the sensor"?

//

GoForSmoke

Quote
But you are talking about pulses, the sensor outputs a frequency, that isn´t the same?


I'm just going off your variable names.
How about leaving this part out until you have reliable 'pulses' then?

Code: [Select]

  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  magnitude = ZP - 2.5*log10(freq);


that's where your mixed-types math is a totally different issue, let's cut that in the attempt to troubleshoot and get back to it when the rest is ready.





I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Go Up