April 27, 2024, 11:50:50 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Prop-1 Programming Template

Started by JonnyMac, February 12, 2007, 07:32:24 PM

Previous topic - Next topic

JonnyMac

February 12, 2007, 07:32:24 PM Last Edit: August 30, 2011, 12:33:02 PM by JonnyMac
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 ]-------------------------------------------------------



Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

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.
Jon McPhalen
EFX-TEK Hollywood Office