Datasheet

Chapter 3: EEPROM Tricks and Program Tips · Page 97
The QRD1114 has an IRLED in it that shines IR light on the surface it's facing. Unlike
the IR object detectors we just finished testing, this device does not need to flash the IR
on/off at 38.5 kHz. That's because the QTI is designed to be held close enough to its
target surface that IR from the window and the lamps in the room won't be as likely
interfere.
Figure 3-10 shows a simplified version of the QTI circuit with the power already turned
on. The IR LED shines infrared on the nearby surface, which reflects this light, and it
bounces back onto the base of the IR transistor. A white surface will reflect most of the
IR while a black surface will absorb it. When more IR is reflected and strikes the base of
the IR transistor, it lets more current through from the capacitor to Vss. When less IR is
reflected, the IR transistor lets less current through from the capacitor to Vss.
Figure 3-10
Simplified Version of
the QTI Circuit
By setting I/O pin P9 high for a while (1 ms), the voltage V
0
at the lower plate of the
capacitor approaches 5 V. When P9 is set to an input, V
0
will start to decay because P9 is
no longer forcing it to 5 V. The time it takes the voltage to decay to 1.4 V is controlled
by the IR transistor. Here's how:
More IR at the transistor's base, more current through the transistor.
More current through the transistor, less decay time.
Less IR at the transistor's, base, less current through the transistor.
Less current through the transistor, more decay time.
The
RCTIME command measures the time it takes for the voltage to decay to around 1.4 V
and stores it in a variable. Here is a code snippet that sets P9 high, pauses for 1 ms, then