I am now trying the base examples from both the FreqCount and FreqCounter libraries. This is my current code:
/* FreqCount - Example with serial output
* http://www.pjrc.com/teensy/td_libs_FreqCount.html
*
* This example code is in the public domain.
*/
#include <FreqCount.h>
void setup() {
Serial.begin(9600);
FreqCount.begin(100);
}
void loop() {
if (FreqCount.available()) {
unsigned long count = FreqCount.read();
Serial.println(count);
}
}
And here is an example of the drift I am seeing:
http://secure.dfcs.net/extranet/arduino/drift.pdfI like the idea of an external timer, but I haven't been able to find any code examples that work for frequency counting. I am learning as quickly as I can, but am definitely over my head as far as the "proper" way to structure timed loops on an Arduino. I have used a National Instruments SBRIO and LabView before, but that was a bit higher-level.
From what I have read, it sounds like I need to determine the resolution I want to achieve given the sensor I am using. Then, I need to maximize that resolution on the software side by tweaking the AREF voltage so that my 10bit counters are most effective. I am having a hard time understanding which things I need to control and which things are beyond necessary.
I have a high-brightness red LED hooked up to the 3.3V pin on my UNO with an 8.2k resistor. This seemed to give me a middle-of-the-range light intensity reading on the TSL235R. It was an arbitrary decision though. Should I dim the LED even more so that my square wave frequency is slower? I also have a setup with a 100k pot on the 3.3V pin. I can get very low readings from that as well, but it seems like the resolution I am getting is also less. I am assuming that with a higher frequency, there are more steps between 0 and the highest value. So, if the sensor starts by returning a frequency of 80000 Hz (for example) there are a lot more "steps" in that than there would be if I turned the LED down to produce values in the 1000 Hz range. Am I missing something?
Resolution aside, there is nothing that is changing in my setup that I can see producing a drift like this other than a problem with my timer or counting setup. This drift is consistent across 3 different Arduinos.
I'll also take suggestions for steps I could take to debug this properly. I have a function generator, an oscilloscope, and all sorts of chips, resistors, and caps to build test rigs with. I have so many variables that I don't know where to head next to try to figure out what is wrong. My code is so short that it seems like it has to be something more fundamental with the FreqCount and FreqCounter libraries that I am missing.
Many thanks.
Ryan