Go Down

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

Corpze

I had all the hardware at home, except for the sensor, UV/IR block filter and lens that on its way (5 USD worth of hardware) It is kind of a learning thingy, maybe it isn't any idéa of keep on going with this :/

GoForSmoke

If you count pulses for 1800 or even 180 seconds and something bright doesn't intrude, you can get less error than if count 1 or 3 seconds. Can get... because there's always a way to can't anything.

If you count pulses and see that a certain time has elapsed then you will be off by the fraction of the last pulse that didn't make it unless you exactly end the time period on a pulse start. So there you have the fraction error but that is divided by the number of pulses when you determine the average length of just 1 pulse (the inverse of frequency) so the more pulses, the better.

To do that, have an interrupt increment the pulse count and in loop() set up a timer the way it's done in BlinkWithoutDelay and when the interval is reached, copy pulse count and use that with the time interval you set up, do the math and you can have frequency. The longer the interval, the closer to precise you can be as long as something doesn't intrude on the patch of sky you're watching.

OTOH you can set up an interrupt to count some number of pulses and see how long that took, maybe completely in the IRQ. Then your loop() code just watches for the IRQ to update the how-long-it-took variable and report that. You will have pulses and time. 

Why not a library?
You keep wondering what library to use. You keep wondering if the library you use is the problem. That's because you don't know what they do and it is a problem trying to troubleshoot with such an unknown.

In this case what the library does is not difficult and you will doubtless benefit from learning. Just take your time, identify what it is your don't know and learn those pieces as you put it together.

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

Corpze

I understand :-) i thing i will give it a try, i think i finally know how you mean :-)

GoForSmoke

So you have used interrupts and know to make variables used in interrupts as volatile?
And you know that time is kept in unsigned long variables?

How long can you aim at dark sky to get measurements? 3 seconds? 30 s? 300 s? 30 minutes?

Maybe the best way will be to count pulses and see how long that takes.
....
You understand, if I stop when pulse count is done I can know how many whole usecs (microseconds) it takes but I can't know the fraction of a usec after the last full usec. If it was 400001.7 usecs, I will miss the .7. That is an unavoidable (and small) source of error.
If I stop on a time count while also counting pulses then I can know the usecs and how many pulses but not the fraction. If 100 seconds takes 50.8 pulses, my 100 second read only sees 50.
....
Since pulses are so big compared to usecs there will be more possible error counting over a set time than counting a set number of pulses and seeing how long that took. I would rather have a fraction of a usec (really, Arduino is good to 4 usecs which is still very small) as error than a fraction of a much bigger pulse as error.
What decides the method for me is the way with the smaller error. In this case, it's pretty clear?


So big open to the forum just to be sure question --- can you read micros() in an interrupt?


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

Corpze


So you have used interrupts and know to make variables used in interrupts as volatile?
And you know that time is kept in unsigned long variables?

How long can you aim at dark sky to get measurements? 3 seconds? 30 s? 300 s? 30 minutes?

Maybe the best way will be to count pulses and see how long that takes.
....
You understand, if I stop when pulse count is done I can know how many whole usecs (microseconds) it takes but I can't know the fraction of a usec after the last full usec. If it was 400001.7 usecs, I will miss the .7. That is an unavoidable (and small) source of error.
If I stop on a time count while also counting pulses then I can know the usecs and how many pulses but not the fraction. If 100 seconds takes 50.8 pulses, my 100 second read only sees 50.
....
Since pulses are so big compared to usecs there will be more possible error counting over a set time than counting a set number of pulses and seeing how long that took. I would rather have a fraction of a usec (really, Arduino is good to 4 usecs which is still very small) as error than a fraction of a much bigger pulse as error.
What decides the method for me is the way with the smaller error. In this case, it's pretty clear?


So big open to the forum just to be sure question --- can you read micros() in an interrupt?





No i haven´t really used interrupts more then those that allready have been written in existing code... I have read the reference about interrupts and there are two kinds? internal and external? the external ones are located on pin2 and 3 on the uno. Is one of those inputs usable for me?

I think 10sec will be the highest time i want to measure (the original SQM-meter measures on 2sec)

So 10000ms of measurements is a number i can start with.

I understand that i will lose the .x count of the pulses if the time runs out :)


Go Up