Here's a useful template for keeping your Prop-1 programs organized. The template includes code for debouncing the input to prevent false starts -- especially important when using a PIR sensor.
Updated to allow for Active-High (trigger input is "1") or Active-Low (trigger input is "0") trigger signals.
' =========================================================================
'
' File......
' Purpose...
' Author....
' E-mail....
' Started...
' Updated...
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Sio = 7 ' SETUP = UP; no ULN
SYMBOL Trigger = PIN6 ' SETUP = DN
' -----[ Constants ]-------------------------------------------------------
SYMBOL Yes = 1
SYMBOL No = 0
SYMBOL TrOn = 1 ' active-high trigger
SYMBOL TrOff = 0
SYMBOL IsOn = 1 ' active-high I/O
SYMBOL IsOff = 0
SYMBOL Baud = OT2400
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2 ' for debounce loop
' -----[ Initialization ]--------------------------------------------------
Power_Up:
' put code here that only happens at power-up/hard reset
Reset:
PINS = %00000000 ' all off
DIRS = %00111111 ' P5..P0 are outputs
' -----[ Program Code ]----------------------------------------------------
Main:
timer = 0 ' reset debounce timer
Check_Trigger:
PAUSE 5 ' scan delay
IF Trigger = TrOff THEN Main ' check trigger input
timer = timer + 5 ' update timer
IF timer < 100 THEN Check_Trigger ' check timer
' program code here
GOTO Reset
' -----[ Subroutines ]-----------------------------------------------------
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -----[ User Data ]-------------------------------------------------------
As more and more Prop-1 customers are making use of industrial sensors that have "open collector" outputs I have modified my standard template to accommodate this. For example, you may get a sensor that is listed as "open collector" or "NPN" type output. What this means is that the signal will pull the trigger line to ground when active.
To use an active low signal you need to:
-- remove the ULN influence from P6 -- cut pin 2 or the ULN2803, or pin 1 of the ULN2003
-- move the P6 SETUP jumper to the UP position
-- connect the W(hite) wire to the sensor output, the B(lack) wire to to sensor common or ground.
In the listing above you'll find values for TrOn (trigger on) and TrOff (trigger off). For Active-Low signals the TrOn value will be 0 and the TrOff value will be 1.