Chapter 6: Light Sensitive Navigation with Photoresistors
· Page 209
RCTIME
. The
RCTIME
command is designed to measure RC decay time on a circuit like
the one in Figure 6-10. Here is the syntax for the
RCTIME
command:
RCTIME
Pin, State, Duration
The
Pin
argument is the number of the I/O pin that you want to measure. For example, if
you want to measure P6, the
Pin
argument should be 6. The
State
argument can either
be 1 or 0. It should be 1 if the voltage across the capacitor starts above 1.4 V and decays
downward. It should be 0 if the voltage across the capacitor starts below 1.4 V and
grows upward. For the circuit in Figure 6-10, the voltage across the capacitor will start
close to 5 V and decay to 1.4 V, so the
State
argument should be 1. The
Duration
argument has to be a variable that stores the time measurement, which is in 2 µs units. In
this next example program, we’ll measure the RC decay time on the photoresistor circuit
connected to P6, which is the photoresistor on the Boe-Bot’s left.
To measure RC decay, the first thing you have to do is make sure you have declared a
variable that will store the time measurement:
timeLeft VAR Word
These next three lines of code charge the capacitor, measure the RC decay time and then
store it in the
timeLeft
variable.
HIGH 6
PAUSE 3
RCTIME 6,1,timeLeft
To get the measurement, the code implements these three steps:
1.
Start charging the capacitor by connecting the circuit to 5 V (using the
HIGH
command).
2.
Use
PAUSE
to give the
HIGH
command enough time to charge the capacitor in the
RC circuit.
3.
Execute the
RCTIME
command, which sets the I/O pin to input, measures the
decay time (from almost 5 V to 1.4 V), and stores it in the
timeLeft
variable.
Example Program: TestP6Photoresistor.bs2
√
Reconnect power to your board.
√
Enter, save, and run TestP6Photoresistor.bs2.