BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – RCTIME
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 367
Figure 5.34: Relay Circuit for
Demo Program RCTIME2.bs2.
Demo Program (RCTIME2.bs2)
' RCTIME2.BS2
' This program illustrates the use of RCTIME as a fast stopwatch. The
' program energizes a relay coil, then measures how long it takes for the
' relay contacts to close. The circuit for this program can be found in
' the manual. Note that RCTIME doesn't start timing instantly -- as with
' all PBASIC instructions, it must be fetched from program EEPROM before
' it can execute.
' {$STAMP BS2}
' {$PBASIC 2.5}
Coil PIN 6
RC PIN 7
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
Adjust CON $200 ' x 2 us per unit
#CASE BS2SX
Adjust CON $0CC ' x 0.8 us per unit
#CASE BS2P, BS2PX
Adjust CON $0C0 ' x 0.75 us per unit
#ENDSELECT
result VAR Word
Main:
DO
LOW Coil ' energize relay coil
RCTIME RC, 1, result ' measure time to contact closure
result = result */ Adjust ' adjust for device
DEBUG "Time to close: ",
relay contact
relay coil
10 k
P6
P7
Vss
Vdd
Vdd
Relay: 5 VDC reed
relay with 20 mA
coil, eg., Radio
Shack #275-232
All
2
NOTE: This example program can be
used with all BS2 models. This program
uses conditional compilation techniques;
see Chapter 3 for more information.