circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

December 2004, Issue 173

Light-to-Frequency Conversion (Part 1)
TSL230R-Based Pulse Oximeter


by Jeff Bachiochi

DIGITAL CONNECTION

Unlike Analog sensors, the TSL230R doesn’t require an A/D converter to get values into a microcontroller. The TTL-compatible output makes a direct interface possible to a microcontroller without the need for analog signal conditioning. If the sensor is at any distance from the rest of the electronics, a shielded cable isn’t necessary because low-level noise sensitive signals aren’t used. Applying the sensor’s frequency output to a microcontroller’s external interrupt input can simplify period or pulse counting. Although I hope the final circuit won’t need any active mode control for the TSL230R, having total control of the mode input pins makes experimenting much easier. A PIC running at 4 MHz has a 1-µs execution cycle, which is a nice whole number to work with for timing. A 16-bit timer using this 1 µs as the timebase can count up to ~65 ms before rolling over.

The timer’s count is directly related to the irradiance level. The smaller the count, the higher the frequency and the more light falling on the sensor. To make sense of this, you need to grab samples at a fixed rate (at least two times faster than the frequency of interest – Nyquist). For 200 bpm, or 3.3 bps, that would be approximately 7 Hz. I used a sample rate of 32 Hz (31.25 ms) for this project because it fits nicely into this timer’s range. 

Timer1’s overflow is set to 31.25 ms by loading the timer’s count with a constant at each overflow. Because of interrupt latency and instruction cycles for the interrupt routine code up to the point where the timer is loaded and begins counting, the actual value placed in the counter will be less than what’s required for 31,250 counts. The timer counts up to overflow, so the required value of counts must be subtracted from the rollover count (or the value complemented). A simulator (with a stopwatch or instruction counter) is helpful for determining the exact value necessary to obtain accurate timing.

The frequency of the TSL230R will increase as more light falls on its light-sensitive array. Although the sensor doesn’t produce zero frequency output for zero irradiance, the output is linear. Using the most sensitive mode, the maximum frequency could be 100 kHz (130 µW/cm2 at 640 nm) with a minimum frequency of approximately 1 Hz. This maximum frequency equals a Timer1 count of 10 with a Timer1 overflow at a minimum frequency because the 16-bit timer overflows at approximately 31 ms.

The only way to achieve a minimum frequency is with little or no irradiance. A Timer1 overflow can indicate an error or too little light. Too much light is a bit trickier to detect. A count of 10 would be impossible to detect in this case because the code execution for the interrupt lasts longer than the 10 µs for a period. So, counting edges (periods) would be missed and the count wouldn’t be accurate.

The instantaneous sampling approach requires the frequency to be measured once each sample period. This is achieved by enabling the external interrupt each time Timer1 overflows (31.25-ms sampling timer). After the external interrupt is enabled, Timer1’s count is sampled twice on each of the next two rising edges of the TSL230R frequency output. The difference in the two counts equals the period of the output in microseconds for that sampling period.

The sampling sum approach uses Timer1’s overflow (31.25-ms sampling timer) to read the accumulated period count and then flush it every sample period. The external interrupt is always enabled. Each rising edge of the TSL230R’s frequency output adds one to the number of periods. The accumulated count at each sample time is the sum of all the periods output during that sample time. This is essentially a period average for that 31.25 ms.