November 23, 2024, 04:32:54 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.


Alarm System

Started by Karl Fields, April 07, 2011, 09:06:23 PM

Previous topic - Next topic

Karl Fields

Jon and John have done some really great things for us in the past (well in the present also and I'm sure in the future!) so though I might share a few of the completed projects, and to let you know that it's not all about props!

First one is our compound alarm system, which was probably the most difficult:

The object was to provide 'intruder alert' when someone breeches the barbwire fencing surrounding our 3 acre compound after hours. The original scenario simply used a prop1 and IR sensors, but boy is that a lot of walking to go check when detection occurs! Much to Jon's chagrin :) we went with using a prop1 for each 'zone' with all of the prop1s tied to a prop2 which did the main control and led activation.

When a zone was triggered, an alarm panel light would activate showing which zone was hot. Lights and sirens also went off. After a programmable amount of time, the system would reset and go back to monitoring, however it would lite the 'was activated' LED so if I was gone, I could see that something happened while when I returned.

Another wrinkle was that we needed to set the alarm and allow enough time to exit the compound. Originally we used an Parallax RFID system, but ended up just turning the system on manually and exiting within the time alloted setting. Sometimes simplified is better!

On to the programs. This is the zone alarm program that was installed on each prop1, which monitored the IRs:

[code]' =========================================================================
'
'   File...... KF_Zone_Alarm_2009.BS1
'   Purpose... Karl Fields security system -- Zone Alarm Monitor
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 30 JUL 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Monitor sensor input until active
'  -- continue to monitor sensor activity during dwell time
'  -- if sensor active through dwell
'     -- set alarm output
'     -- pull alarm buss low (OUT5)
'     -- go back to scanning
'  -- if alarm clear then kill alarm output (LED stays lit)
'  -- if master clear input reset everything
'
' Connect N.C. sensor to P7.W and P7.B
'  -- or between OUT7 and GND with mods below
'
' Connect clear control signal from Prop-2 to OUT6 with ULN mods below
'
' IO and ULN setup:
'  -- remove ULN2803 from socket
'  -- remove pins 1, 18, 2, and 17 from ULN2803
'  -- jumper socket pin 1 to pin 18 with #24 solid wire
'      * this makes OUT7 terminal an input
'  -- jumper socket pin 2 to pin 17 with #24 solid wire
'      * this makes OUT6 terminal an input
'  -- reinstall ULN; ensure jumpers to do not connect clipped pins


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


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

SYMBOL  SensorIn        = PIN7                  ' SETUP = UP
SYMBOL  ClearCtrl       = PIN6                  ' SETUP = UP

SYMBOL  Alarm           = PIN5                  ' OUT5 to Prop-2

SYMBOL  LED5            = PIN4                  ' alarm counts
SYMBOL  LED4            = PIN3
SYMBOL  LED3            = PIN2
SYMBOL  LED2            = PIN1
SYMBOL  LED1            = PIN0


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

SYMBOL  IsLow           = 0
SYMBOL  IsHigh          = 1

SYMBOL  IsOff           = 0
SYMBOL  IsOn            = 1

SYMBOL  DWELL_TIME      = 5000                  ' five seconds


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

SYMBOL  flags           = B0
SYMBOL   sensor         =  BIT7
SYMBOL   clear          =  BIT6

SYMBOL  state           = B2
SYMBOL  idx             = B3

SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00111111                              ' multi-led configuration

  state = 0

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

Main:
  flags = %11000000                             ' preset for active
  FOR idx = 1 TO 20                             ' debounce
    flags = flags &/ PINS                       ' invert active low
    PAUSE 5
  NEXT
  timer = timer + 100                           ' update timer


' This code allows the normal state processor to be interrupted since
' the clear command (from the Prop-2) can come at any time, even when
' this module doesn't have an active alarm.

Check_Clear:
  IF clear = IsOff THEN Run_State               ' interrupt on clear input
    IF state = 3 THEN Run_State                 ' if there, don't reset timer
      state = 3
      timer = 0


' State handler; routes program to appropriate code

Run_State:
  IF state = 0 THEN Check_Sensor
  IF state = 1 THEN Verify_Alarm
  IF state = 2 THEN Run_Alarm
  IF state = 3 THEN Clear_Alarm


' This state simply waits for the sensor input (P7) to go active

Check_Sensor:
  timer = 0
  IF sensor = IsOff THEN Main
    state = 1
    GOTO Main


' This state monitors the sensor input (P7) during the DWELL_TIME period.
' If the sensor stays active throughout then it's considered a valid alarm.

Verify_Alarm:
  IF sensor = IsOn THEN Check_Dwell             ' still active?
    state = 0                                   ' no, false alarm
    GOTO Main

Check_Dwell:
  IF timer < DWELL_TIME THEN Main               ' else check dwell time
    state = 2                                   ' dwell exceeded, alarm valid
    GOTO Main


' This turns on the Alarm output (to Prop-2) and LED indicator.  The program
' will loop through this state until there is a pulse (from the Prop-2) on
' the ClearCtrl input (P6).

Run_Alarm:                                    ' hold here for clear signal
  Alarm = IsOn
  LED1 = IsOn
  timer = 0
  GOTO Main


' This state waits for the clear pulse (from the Prop-2) to end and then
' checks to see how long it was.  A short pulse clears the Alarm output but
' leaves the LED on.  A long pulse does a total reset.

Clear_Alarm:
  IF clear = IsOn THEN Main                     ' wait for pulse end
  IF timer > 1000 THEN Reset                    ' long pulse?
    Alarm = IsOff                               ' no, short pulse
    state = 0
    GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Alarm_Bits:
  EEPROM (%00100000)                            ' Alarm only (pad)
  EEPROM (%00100001)                            ' 1 event
  EEPROM (%00100010)                            ' 2 events
  EEPROM (%00100100)                            ' 3 events
  EEPROM (%00101000)                            ' 4 events
  EEPROM (%00110000)                            ' 5 events
  EEPROM (%00111111)                            ' 6+ events


Then we needed the program for the prop2, which basically monitored the prop1s and did the control after alter functions:


' =========================================================================
'
'   File...... KF_Alarm_Master_2009.BS2
'   Purpose... Karl Fields security system -- Master Controller
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 30 JUL 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Master controller for modular security system.

' IO and ULN setup:
'  -- remove ULN2803 from socket
'  -- remove pins 1 and 18 from ULN2803
'  -- jumper socket pin 1 to pin 18 with #24 solid wire
'      * this makes OUT15 terminal an input
'  -- reinstall ULN; ensure jumpers to do not connect clipped pins
'
' OUT15 (input) is alarm buss from Prop-1 controllers
' OUT12 (output) is alarm clear signal to Prop-1 controllers
'
' Bypass button
' -- connect N.O. button between P14.W and P14.B
'
' Reset button
' -- connect N.O. button between P13.W and P13.B


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


' -----[ Conditional Defitions ]-------------------------------------------


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

SensorPort      PIN     15                      ' SETUP = UP (<- OUT15)
BtnBypass       PIN     14                      ' SETUP = UP (P14.W/P14.B)
BtnReset        PIN     13                      ' SETUP = UP (P13.W/P13.B)
ClearCtrl       PIN     12                      ' SETUP = DN (OUT12 ->)

Ctrl            VAR     OUTC                    ' pins 11..8
AlarmOut        PIN     11
RedLed          PIN     10
YellowLed       PIN     9
GreenLed        PIN     8


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

No              CON     0
Yes             CON     1

IsOff           CON     0
IsOn            CON     1


SILENT_ALARM    CON     5000
HORN_TIME       CON     30000


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

flags           VAR     Byte
sensor         VAR     flags.BIT7
bypass         VAR     flags.BIT6
reset          VAR     flags.BIT5

idx             VAR     Byte
state           VAR     Byte

timer           VAR     Word


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

Master_Reset:
  DIRH = %00011111                              ' set output pins
  ClearCtrl = IsOn                              ' pulse on
  PAUSE 1500                                    ' long pulse

Start:
  OUTH = %00000000                              ' all off
  state = 0
  timer = 0


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

' Debounce inputs and create 100ms loop timing

Main:
  flags = %11100000                             ' preset inputs
  FOR idx = 1 TO 20                             ' debounce
    flags = flags & ~INH                        ' invert active low
    PAUSE 5
  NEXT

  timer = timer + 100                           ' update timer


Check_Reset:
  IF (reset = Yes) THEN Master_Reset            ' allow reset at any time


Check_Bypass:
  IF (bypass = Yes) THEN Start


Handle_State:
  IF state = 0 THEN Monitor_Alarm               ' green
  IF state = 1 THEN Alarm_Detect                ' yellow
  IF state = 2 THEN Horn_On                     ' red + horn
  IF state = 3 THEN Clear_Alarm                 ' red + clear zone alarm


Monitor_Alarm:
  Ctrl = %0001                                  ' green on
  IF (sensor = IsOn) THEN
    state = 1
    timer = 0
  ENDIF
  GOTO Main


Alarm_Detect:
  Ctrl = %0010                                  ' yellow on
  IF (timer >= SILENT_ALARM) THEN
    state = 2
    timer = 0
  ENDIF
  GOTO Main


Horn_On:
  Ctrl = %1100                                  ' horn on, red on
  IF (timer >= HORN_TIME) THEN
    state = 3
    timer = 0
  ENDIF
  GOTO Main


Clear_Alarm:
  Ctrl = %0100                                  ' horn off, red on
  ClearCtrl = IsOn                              ' clear pulse on
  IF (timer >= 500) THEN                        ' pulse done?
    GOTO Start                                  ' restart
  ENDIF
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------




That's it! Only took Jon about an hour to crank it all out - with the documentation!

Of course I'm kidding, just wanted to let others know how much I really appreciate the help and assistance that EFX provides.

Karl





[/code]