Hello, I am hoping someone has insight into what might be causing a phenomenon I cannot explain!
Here is the basic setup:
- I am using an Arduino Nano clone (from Elegoo) to turn on an infrared LED by setting digital pin 2 (in output mode) to HIGH.
- I then use an OSRAM TSL237 light-to-frequency converter to measure the intensity of the LED output. (The ultimate intent is to pass the infrared beam through a sample to measure the clarity of the sample.)
- To measure the frequency of the signal from the TSL237, I am using the ATmega328P's timers (either timer 0 or timer 1 on input pin 4 or 5, respectively) to count pulses from the TSL237.
- I use internal timer 2 to measure 1 second and count pulses from the TSL237 using either timer 0 or timer 1 during that time, which provides a direct measurement of the frequency of the signal in Hz.
So that's the basic setup. (I'd be happy to provide more details if they would be useful!) It all works well except for one phenomenon I cannot explain. After turning on the device, the measured frequency increases over time for about 8-10 minutes and then stabilizes. Here is an example of typical frequency measurements, at approximately 12-second intervals, after startup:
I am currently unable explain this behavior. Here's what I've tried:
- I suspected this was somehow linked to the temperature of the MCU, so I added code to pull the temperature reading from the ATmega328P's internal temperature sensor. Sure enough, the curve looks about the same, and if I do a simple linear regression of the frequency measurement and the MCU temperature, I get R^2 of 0.8-0.9. So that seems to strongly suggest this is somehow caused by the temperature of the MCU.
- After discovering that, I wondered if the change in measured frequency could by caused by the Nano's ceramic resonator heating up, which would cause its frequency to decrease. If so, that would explain the artifact of getting higher frequency readings with hotter internal temperatures: the duration of a second, as measured by resonator ticks, would increase, leading to higher frequency readings. To test this, I hooked the Nano's timer input to an external signal source that should have been stable (a 250 kHz PWM signal generated by an Arduino Uno R3 that had been running for ~10 minutes to ensure temperature stabilization). To my surprise, the relationship between the Nano's internal MCU temperature and the measured frequency disappeared. The Nano measured a fairly steady signal frequency of ~250 kHz the entire time! So that seemed to disprove the resonator hypothesis.
- Next, I wondered if maybe the voltage of the pin I'm using to turn on the LED (digital pin 2) was changing as the MCU heated up, causing the LED output to change. Very unlikely, I know, but I hooked up a multimeter to the output of pin 2 to check. It read a voltage of 4.76-4.77 V the entire time.
At this point, I am at a complete loss for what to try next! The TSL237 and infrared LED are both far away (relatively speaking) from the Nano, so I don't see any way temperature could be affecting them. Regardless, according the TSL237 datasheet, its frequency output is quite temperature-stable and actually decreases slightly with increasing temperature.
I've confirmed that I can effectively "solve" this problem by letting the device warm up for ~10 minutes before taking frequency measurements, but that is obviously not very satisfying!
I suspect I'm overlooking something obvious, and I'd greatly appreciate any suggestions for where to look next! Thank you!



