# RCTIME Examples

Syntax: RCTIME

NOTE: The example below is written for the BS2 and will run on any of the BS2-family modules. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2sx, BS2p, BS2pe, or BS2px.

    ' RCTIME1.BS2
    ' This program shows the standard use of the RCTIME instruction measuring
    ' an RC charge/discharge time. Use the circuit in the RCTIME description
    ' (in the manual) with R = 10K pot and C = 0.1 uF. Connect the circuit to
    ' pin 7 and run the program.  Adjust the pot and watch the value shown on
    ' the Debug screen change.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    RC              PIN     7

    result          VAR     Word

    Main:
      DO
        HIGH RC                             ' charge the cap
        PAUSE 1                             '   for 1 ms
        RCTIME RC, 1, result                ' measure RC discharge time
        DEBUG HOME, DEC result              ' display value
        PAUSE 50
      LOOP
      END

NOTE: The example below is written for the BS2 and will run on any of the BS2-family modules. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2sx, BS2p, BS2pe, or BS2px.

    ' 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
        Adjust      CON     $0C0            ' x 0.75 us per unit
      #CASE 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: ",
              DEC Result, CR
        HIGH Coil                           ' release relay
        PAUSE 1000                          ' wait one second
      LOOP
      END

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012