Dane Weston’s book on Color BASIC for the
Pocket Mini Computer is available at
It’s possible to modify the Color BASIC source code
to include a new faster RCTIME command. (I’ve done this,
However, if we don’t need precise or fast resistance
measurement, the simplest way to measure the decay time
is not to speed up the timer, but to slow down the decay
instead. We can do this easily on the Amigo just by using
a (much) bigger capacitor in our decay circuit.
FIGURE 6: Using a 100 uFd capacitor in the RC decay circuit slows the discharge time enough that we can measure it directly from Color BASIC.
Figures 6 and 7 illustrate an Amigo RC decay circuit
that uses a 100 uFd electrolytic capacitor to measure the
variable resistance of a photocell. The 100 uFd cap slows
the capacitive discharge time by a factor of 10,000
compared to the typical 0.01 uFd capacitor, allowing
enough time for the tinyBASIC interpreter in Color BASIC
to track resistance values down to about 100 ohms.
Resolution isn’t great — not good enough for an
accurate Amigo ohmmeter — but it’s perfect for interfacing
homebrew resistive sensors to your Color BASIC
Recall that Spin itself is an interpreted language that
operates in a similar fashion, so Color BASIC is an
interpreter running within an interpreter. The upshot is that
Color BASIC executes many (usually thousands) Propeller
clock cycles for each line of your program code. So, a
Color BASIC software timer is just too slow to measure
the capacitor discharge of a typical RC decay circuit. We
need another answer.
Set up the circuit as shown in Figure 7 on your Amigo
breadboard, noting the polarity of the electrolytic (striped
negative lead connected to ground), then enter and run
the Color BASIC snippet that follows. You should see the
value of your decay timer change with various light levels
on the photocell, with brighter light levels producing lower
My setup could distinguish which lights in the room
were on or off, or indicate when my shadow passed
across the photocell as I walked across the room.
Here’s the code snippet, followed by a brief
description of how Color BASIC implements the RC decay
10 CLS 20 PRINT “““100uf RCTime Test” 25 REM —- Charge the Cap —- 30 OUTA =1 40 PAUSE 100 45 REM —- Start the Timer —- 50 c=0 55 REM —- Start the Discharge & Wait —- 60 IF INA =0 THEN GOTO 90 70 c=c+1 80 GOTO 60 85 REM —- Report Timer Value —- 90 LOCATE 10,4: PRINT c, 100 GOTO 30
FIGURE 7: Continuous light level measurement using a 100 uFd capacitor and photocell with your Amigo — a little slow, but effective!
The RC decay algorithm has four steps: (1) Charge
the capacitor to some known value V0; ( 2) Start the
software timer and begin discharging the capacitor; ( 3)
Wait until the decay voltage Vt equals some desired
reference; and ( 4) Stop the timer and report the results.
Here’s how the code snippet implements the
44 January 2018