Hi everyone,
I've been working on an open source lab tool in my free time and am having some issues with drift. I am using the TAOS TSL-235R sensor...five of them...attached to an Arduino Due on five digital IO pins. They all gather light data in the form of a digital signal which is linear with light intensity. The device outputs a frequency ranging from 0 to 500kHz depending on the brightness of the light. I got the sensors to all output their values at the same time once per second but there is slight drift after 24 hours worth of readings. Its not too bad but if this sensor needs to run for multiple days at a time, the drift can be a serious problem.
Here is an excel screen shot of the drift over 24 hours. Y axis is Absorbance (logarithm of light difference) and X value is time in seconds.
Again its not too bad and the end of day drift was 1% (~0.02 absorbance units)
My question is what can I modify to fix this drift?
Could anyone recommend a better timing method then delay?
As the frequency coming from the sensor gets larger and the interrupts occur more often, the error in the timing would increase, no?
Any tips to make the process smoother/faster/better?
The code simply increments an unsigned long integer every time a rising edge is detected on any/all of the five sensors. This interrupts the main loop which just calculates the frequency from the previously stated long int and dumps data down the serial line at 115200 baud. I read that very little should be done during the ISR thus there is little happening. I spoke with a friend who suggested firing each sensor one after the other so the interrupts don't fire over each-other but further reading said you would need to explicitly enable interrupts during an interrupt else the micro just blocks others. I need the final output to be the frequency coming off the device with as much fidelity as possible. Please excuse the quality of my code, I am still learning. My thanks in advance for any and all help/advise/criticism. Here is my code:
volatile unsigned long cnt1 = 0;
volatile unsigned long oldcnt1 = 0;
volatile unsigned long t1 = 0;
volatile unsigned long hz1=0;
volatile unsigned long cnt2 = 0;
volatile unsigned long oldcnt2 = 0;
volatile unsigned long t2 = 0;
volatile unsigned long hz2;
volatile unsigned long cnt3 = 0;
volatile unsigned long oldcnt3 = 0;
volatile unsigned long t3 = 0;
volatile unsigned long hz3;
volatile unsigned long cnt4 = 0;
volatile unsigned long oldcnt4 = 0;
volatile unsigned long t4 = 0;
volatile unsigned long hz4;
volatile unsigned long cnt5 = 0;
volatile unsigned long oldcnt5 = 0;
volatile unsigned long t5 = 0;
volatile unsigned long hz5;
void setup(void)
{
Serial.begin(115200);
attachInterrupt(52, irq1, RISING);
attachInterrupt(50, irq2, RISING);
attachInterrupt(48, irq3, RISING);
attachInterrupt(46, irq4, RISING);
attachInterrupt(44, irq5, RISING);
}
void loop(void)
{
delay(1000);
hz1 = cnt1-oldcnt1;
hz2 = cnt2-oldcnt2;
hz3 = cnt3-oldcnt3;
hz4 = cnt4-oldcnt4;
hz5 = cnt5-oldcnt5;
oldcnt1=cnt1;
oldcnt2=cnt2;
oldcnt3=cnt3;
oldcnt4=cnt4;
oldcnt5=cnt5;
Serial.print(hz1);
Serial.print(",");
Serial.print(hz2);
Serial.print(",");
Serial.print(hz3);
Serial.print(",");
Serial.print(hz4);
Serial.print(",");
Serial.println(hz5);
}
void irq1()
{
cnt1++;
}
void irq2()
{
cnt2++;
}
void irq3()
{
cnt3++;
}
void irq4()
{
cnt4++;
}
void irq5()
{
cnt5++;
}