Datasheet
Chapter 3: EEPROM Tricks and Program Tips · Page 109
The code block below takes less time than an RCTIME command would over a black
surface. It starts like it's going to take an
RCTIME measurement, by setting P9 high and
waiting 1 ms for the V
0
to approach 5 V. Instead of taking an RCTIME measurement, the
code bock changes P9 from output to input. That's the same thing the
RCTIME command
does internally, and it's what causes the voltage to start to decay. Instead of waiting for
the voltage to decay all the way to 1.4 V like the
RCTIME command would, this code
block sends a
PULSOUT command to an I/O pin whose circuit will not be affected by it
(the pushbutton).
HIGH 9
PAUSE 1
INPUT 9
PULSOUT 6, threshold
qtiStateLeft = IN9
What about the pushbutton?
True, P6 is connected to the pushbutton, but while the pushbutton is not being monitored,
PULSOUT commands can be sent to it. It is safe to be used as an output because of the 470
Ω current-limiting resistor between the I/O pin and the pushbutton terminal. Regardless of
whether the pushbutton is pressed or not pressed, the I/O pin is protected. Before the
pushbutton is checked, P6 will have to be set back to input with the command INPUT 6, or
if you have used the PIN declaration for it in your program, INPUT pbSense.
Keep in mind that the
Duration of this PULSOUT command is the threshold variable.
Figure 3-15 shows what happens in terms of the signals. The instant the
PULSOUT
command finishes is the instant the threshold amount of time has passed. The code block
takes a snapshot of
IN9 at that instant by copying the value it stores into a variable named
QtiStateLeft. If the QTI sees white, V0 will have decayed below 1.4 V, and IN9 will
store 0. If the QTI sees black, V0 will not have decayed below 1.4 V, and
IN9 will
store 1.