November 21, 2024, 10:03:51 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


prop 1 board retaining the program for repeat

Started by Jerry, September 28, 2015, 03:11:12 PM

Previous topic - Next topic

Jerry

Guys I'm having trouble with my prop 1 board retaining the program for repeat. I can load the program and when it is triggered it will run output pin 6 and 7 correctly . When it resets and is triggered again pin 7 runs correctly but, pin 6 does not.  I have attached a copy of the program for review. Any help would be appreciated,    Thanks

' =========================================================================
'
'   File....... Alarm-PIR.BS1
'   Purpose.... trigger an alarm and light on motion detect
'   Author.....
'   E-mail.....
'   Started....
'   Updated...
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================

' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  PIR            = PIN6               'Pin for PIR Sensor
SYMBOL  Light          = 6                    'Pin for Light
SYMBOL  Alarm         = 7                    'Pin for Alarm


' -----[ Constants ]-------------------------------------------------------

SYMBOL IsOn   = 1                           ' for active-high in/out
SYMBOL IsOff  = 0

' -----[ Initialization ]--------------------------------------------------

Reset:

PAUSE 20000


IF PIR = 1 THEN Main                ' wait for PIR activity


' -----[ Program Code ]----------------------------------------------------

Main:

  IF Pir = IsOFF THEN Main

      HIGH Light
      HIGH Alarm
      PAUSE 20000
      LOW Light
      LOW Alarm




  GOTO Reset

JonnyMac

You've been ensnared by a trap that is easy to fall into: you're re-using the same pin for two functions.

Here's the deal: the Prop-1 has eight IO (input-output) points; the program defines each point as an input or an output. On the controller, we use the pin headers for TTL (5V) inputs and outputs. When a pin is in output mode, it also turns on the transistor inside the ULN so that you can switch on a 12V device. What I mean to say is that PIN6 and OUT6 are connected.

In your program you're scanning P6 (input) and then making it an output (with HIGH) to turn on the Light. When you turn off the light the pin is still in an output state and writing 0 to the output. When you look at the input bit (PIN0) it is still seeing 0, no matter what is happening with the PIR. For those that are wondering, we have protection resistors on the board to prevent a short circuit in the event that a pin is made an output and low and is presented with a high signal (what we get from an active PIR).

The reason your program works again when you re-download, reset, or cycle the power, is that all pins default to input mode after a reset/power-up.

A second note: PIRs are very twitchy and, as with human-centric inputs (e.g., buttons), should be debounced. "Debouncing" is a software technique to ensure that we have a real signal, not just transient noise.

Here's my version of your program. Note that I use a slightly different style with constants versus HIGH and LOW.

' =========================================================================
'
'   File...... Alarm-PIR.BS1
'   Purpose... Trigger an alarm and light on motion detect
'   Author....
'   E-mail....
'   Started...
'   Updated... 28 SEP 2015
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Light           = PIN5                  ' use V+/OUT5
SYMBOL  Alarm           = PIN4                  ' use V+/OUT4


' -----[ Constants ]-------------------------------------------------------

SYMBOL  YES             = 1
SYMBOL  NO              = 0

SYMBOL  TR_ON           = 1                     ' active-high trigger
SYMBOL  TR_OFF          = 0

SYMBOL  IS_ON           = 1                     ' active-high I/O
SYMBOL  IS_OFF          = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  timer           = B2                    ' for debounce loop


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  PAUSE 20000                                   ' PIR warm-up/reset


' -----[ Program Code ]----------------------------------------------------

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 10                                      ' scan delay
  IF Trigger = TR_OFF THEN Main                 ' check trigger input
    timer = timer + 10                          ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  Light = IS_ON                                 ' activate outputs
  Alarm = IS_ON
  PAUSE 20000

  GOTO Reset


Jon McPhalen
EFX-TEK Hollywood Office

Jerry