24
Chris Shucksmith AS Electronics Project PIC Powered… Burglar Alarm System A microprocessor driven four channel security system. Chris Shucksmith [email protected] Original document 2001 Minor revisions 2006 This work is licensed under a Creative Commons Attribution-Noncommercial 2.5 License See http://www.shucksmith.co.uk/burglaralarm for terms and most recent version.

Alarm Project

Embed Size (px)

Citation preview

Page 1: Alarm Project

Chris Shucksmith AS Electronics Project

PIC Powered…

BurglarAlarm System

A microprocessor driven four channel security system.

Chris [email protected]

Original document 2001Minor revisions 2006

This work is licensed under a Creative Commons Attribution-Noncommercial 2.5 LicenseSee http://www.shucksmith.co.uk/burglaralarm for terms and most recent version.

Page 2: Alarm Project

Chris Shucksmith AS Electronics Project

AimI have decided to design and implement the electronic control unit for a burglar alarm system, suitable for operation in a small office/home environment. The unit needs to be easy to operate, with one button arm/disarm, and visual and audio indicators of alarm status.

This project was structured to meet the coursework requirements of the British AS-Level Electronics qualification and was submitted to the Examination Board for consideration in 2001 whilst a student of John Leggott College, Scunthorpe.

External Inputs4 Zone Inputs

Alarm OutputsContacts for the connection of

● External Buzzer

● External Strobe

Control Unit4 Continuously Monitored Zones4 LED’s – Status of each ZoneArm / Disarm and Reset SwitchesAlarm Status Indicators(s)

Page 3: Alarm Project

Chris Shucksmith AS Electronics Project

Research

Burglar AlarmsMost burglar alarm systems run from a fixed 12V power supply. This is also the standard operating supply voltage for usual subsystems such as any PIR Sensors, heat, pressure or magnetic sensors etc. Also the majority of the Strobe flashing lights and sirens available also run from 12V. Bearing this knowledge in mind, my burglar alarm control panel should run from a 12V supply, and when an alarm output has to be activated, a supply of 12V should be supplied.

A standard also exists for how input sensors operate. They normally use a normally closed (N.C.) loop for sensors, so that an alarm condition is signalled by a switch being opened within the sensor and cutting the circuit. This also means that should a burglar cut the wires to a sensor, then the loop will be cut and an alarm signal is generated.

Most commercial burglar alarms have the capability to monitor the input sensors separately, so that in the event of a burglary, it is known which sensors were and were not triggered so that the point of entry and extent of break in can be deduced.

Regulated PSU12V Power Supply

Control UnitProvide 12V for inputsSwitch 12V for outputs

Output DevicesSirens & Strobe Light

Require a 12V supply when required to sound / flash

Input SensorsContinuous 12V power supply to operate

Device to cut the loop when triggered

N.C. LoopPower Supply

Switched Output

Page 4: Alarm Project

Chris Shucksmith AS Electronics Project

Initial ThoughtsIn order to build the control centre, the main decision I need to make is what approach I will take for the main alarm processing. As most commercial alarms show which alarms have been triggered and which was first, I feel that the solution will either be based around a PIC Controller, or a system comprised of S/R Flip-Flops to remember the status of each zone.

The design can be thought of as several subsystems, which are one of Input, Output or Processing modules. Each subsystem can be built and tested separately:

Input Modules Processing Modules Output Modules

One solution is to base the security alarm processing part around a Programmable Interface Controller (PIC) Chip – which offers benefits in that its operation is defined by the designer by programming it with instructions detailing how to respond to the input / output pins, so monitoring the four zones, Arm / Disarm and Reset inputs can all be done with the one IC.

Alternatively I may decide to use conventional Boolean logic chips such as CMOS 74HC devices and construct a processing unit from several chips. This approach will be harder to build as there will be much more wiring, but will remove the need for me to learn the Microchip dialect assembly language and how to program the PIC Controller, which will require further research.

12V Power SupplyRegulator for 5V CircuitrySmoothing Capacitors

PIC Controller orLogic Gates System

When armed, and until reset:● Show and Latch Zone Inputs

● On First Zone Loop Cut, Activate alarm output signal

Green Armed LEDProtective ResistorCorrect Polarity

4 Input N.C. Loops Normally Closed TypeSimulation switches

12V Heavy Duty OutputTransistor driven RelayProtective Base resistor Relay Coil Diode in R. bias

Arm / Disarm SwitchNon-latching VarietyPush to make

Red Alarm Status LEDProtective ResistorCorrect Polarity

D-Type Flip Flop LatchConnect Q’ to Data InputArm / Disarm to Clock Input

Reset SwitchNon-latching VarietyPush to make

4 Zone Status LED’sProtective Resistors

Page 5: Alarm Project

Chris Shucksmith AS Electronics Project

Hardware - PIC MicroprocessorI have available within the electronics department the equipment needed to program a range of PIC Controllers from Microchip. The device that seams most feasible is the 18 pin PIC 16F84. I have reproduce the most important parts from the Data Sheet for developers using this device from the Microchip website.

Source: Microchip PICmicro© Developers Web SiteURL: http://www.microchip.com/10/lit/pline/picmicro/families/16f8x/index.htm

PIC 16C84 Main Features● 1792(Bytes), 1024x14 (Words) of Programmable Memory● 20mA source and 25mA sink per I/O● 64 bytes data EEPROM● 2.0 – 5.0V Operation● 18 PDIP(P), 18 SOIC 300mil(SO) Packages

Data RAM(Bytes)

Speed(MHz)

I/OPorts

Timers ICSP

68 10 13 1+WDT Yes

Pin Assignment and Electrical Characteristics

Absolute Maximum RatingsAmbient temperature under bias -5°C to +12°CStorage temperature -6°C to +15°CVoltage on VDD with respect to VSS -0.3 to +7.5VVoltage on MCLR with respect to VSS -0.3 to +14VVoltage on any pin with respect to VSS (except VDD and MCLR) -0.6V to (VDD + 0.6V)Total power dissipation 800 mWMaximum current out of VSS pin 150 mAMaximum current into VDD pin 100 mAInput clamp current, IIK (VI < 0 or VI > VDD) 20 mAOutput clamp current, IOK (VO < 0 or VO > VDD) 20 mAMaximum output current sunk by any I/O pin 25 mAMaximum output current sourced by any I/O pin 20 mAMaximum current sunk by PORTA 80 mAMaximum current sourced by PORTA 50 mAMaximum current sunk by PORTB 150 mAMaximum current sourced by PORTB 100 mA

Page 6: Alarm Project

Chris Shucksmith AS Electronics Project

Pin Functions

Legend: I = Input O = Output I/O = Input/Output P = Power— = Not used TTL = TTL input ST = Schmitt Trigger input

Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.2: This buffer is a Schmitt Trigger input when used in serial programming mode.3: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

Page 7: Alarm Project

Chris Shucksmith AS Electronics Project

Microprocessor Architecture

Programming the PICIn the electronics department I have access to “PICtutor Deluxe” development boards, designed and sold by John Becker. These boards enable me to write my program for the device on a PC computer, test its operation using a software simulation, and then finally program my creation onto a PIC 16F84 device. I can then remove the chip from the PICtutor board and implant it into my circuit.Furthermore, the development board have a set of switches and LEDs to allow me to test the operation of my program in hardware. John has made the schematic to these boards available so that I can use this information as guidance on interfacing with this device in my own circuit.

The program for the device is typed into a PC using a text editor such as Microsoft Notepad. I then need to save the file, and use a program known as an assembler to compile the program into a hexadecimal file. This is then transmitted by another program to the development board, shown in this picture.

Page 8: Alarm Project

Chris Shucksmith AS Electronics Project

Specification

Requirements● Operating Voltage 12V Regulated Power Supply

● Input Zones 4 Standard individually-monitored Inputs

● Control Switches Two switches, Arm / Disarm and Reset for Ease of use

● Indicators When a zone has been tripped,- and preferably which was tripped first

● Alarm Output Switched 12V Output when during alarm conditionBe able to drive > 500mA output current

● Input Sampling Time > 20 Times each second

● Low Standby Current < 200 mA

Possible SolutionsAs the PIC chip itself can be used to poll the zone inputs and to remember which input was tripped first, I have decided to take this approach. However using a PIC Controller will require me to learn new skills in assembly language and research on how to interface the chip with external components.

Another solution is to provide the operation by using a series of logic gates to compare the state of the zone inputs against the status of an alarm / disarmed switch and then make a decision based on that information. The output then needs to be latched until the reset switch is pressed. This would have to be a simpler alarm system that what could be built using a PIC controller. However as you can see there is no support for showing which alarms were triggered or the order, as this would require considerable planning outside this simple idea.

Page 9: Alarm Project

Chris Shucksmith AS Electronics Project

Chosen SolutionI have made the final decision to base my control centre around a PIC controller, however to reduce the complexity of the program, I have decided that some features of the alarm should be implemented in external chips. One situation where this would be possible would be to use a Latching D-Type flip-flop for the Arm / Disarm switch.

One issue that I need to consider is that the PIC controller requires a regulated power supply of 5V and it needs to be a stable power supply. This will need more investigation in the sub system designs. Also the PIC controller requires a clock pulse to operate, at the desired frequency of operation. As the device runs at up to 10 MHz, I have decided to use the maximum frequency that can be obtained. The device can (from datasheet) be clocked from a simple Resistor Capacitor combination alone using its internal oscillator, or the provision can be made to use a quartz crystal to resonate at the desired frequency. As the RC solution is much simpler, it is likely that this will be the solution I will use.

Sub-system Division 12V Power Supply Arm Disarm Switch 12V Heavy Duty Output Red Alarm and Green Armed LED’s 4 Zone Status LED’s and 4 Zone Inputs Reset Switch PIC Controller

Page 10: Alarm Project

Chris Shucksmith AS Electronics Project

Subsystems - 12V Power Supply

DescriptionThe alarm system requires two voltage levels for operation. One is the 12V supplied to the control panel, which is in turn distributed to the sensors and to the alarm outputs. The PIC controller and D-Type Flip-Flop Latch however require a 5V power supply.

In order to supply this voltage, I can use a regulation IC, such as the L7805CV chip, and I have obtained the following information and pictures from the data book for this IC:

RS Stock No. 298-8514 Description IC, Voltage Regulator, 5V, L7805CV Part Number L7805CV Manufacturer ST MICROELECTRONICS NATO

Wiring Diagram

Pin 1 is connected to the 12V Positive power supply railPin 3 is connected to the 0V Negative power supply railPin 2 is used as the 5V positive rail, with the existing negative rail

I have used a smoothing electrolytic capacitor of 2200μF in place of the 0.33μF capacitor and a tantalum bead capacitor of 1μF in place of the 0.1μF capacitor.

A heat sink is attached onto the L7805CV IC to dissipate the heat generated.

ProblemsImmediately after connecting the voltage regulator to the 12V power supply, the power supply’s current limiter activated. The current was displayed at over 2A, so obviously there was a problem. On re-inspecting the wiring diagram and pin out of the IC I could see that I had wired up the chip wrongly, and this was the cause of the excessively high current. The IC was very hot, but a heat sink was attached so the heat was dissipated. After inserting the IC the right way round everything was fine, and it appears the chip was not damaged.

TestingAfter wiring up the IC properly, the potential difference across the Vout of the IC and ground was measured, using a multi-meter to be 5.01V, so the IC and subsystem was deemed to be working fine.

Page 11: Alarm Project

Chris Shucksmith AS Electronics Project

Subsystems - Arm/Disarm Switch and D-Type Latch

DescriptionThe PIC controller requires an input one on of the input pins to enter alarmed mode, so that the inputs are scanned. The pin requires a normal CMOS logic signal of 0V / 5V from the switch. As I want to use the same type of switch for the reset and Arm / Disarm switch, I have decided to use a non latching press switch, normally open.

I need to divide the signal from this switch by two in order to give a latching input to the PIC. I can achieve this with a D-Type Flip-Flop, wired up as a divide by two counter or latch.

The D-type flip flop I am using is a SN74HC74N device, which contains two individual flip-flops. Again I have looked up this devices data sheet from the internet to supply this information:

Wiring Diagram

In order to make this IC divide by 2, the Q’ output is fed back in as the Data Input of the left Flip-Flop.. The output from the normally low push switch is wired to the Clock input. The output is taken from the Q output.

ProblemsThe first problem I had was that I was not getting a consistent on / off toggle from the D-type flip flop, sometimes the output remained in the initial state. It was suggested by my tutor that an effect called bounce, produced as the switch is activated, was making the D-type flip multiple times. To prevent this I have research a component called a Schmitt Trigger to give a clean de-bounced output. Here are some scanned images from the textbook “Electronic Products” by Collins Educational (ISBN 0 00 320012 4), showing the problem and a solution:

Page 12: Alarm Project

Chris Shucksmith AS Electronics Project

SolutionI have re-designed this sub-system to incorporate a SN74HC14 IC (CMOS Hex Schmitt-Trigger Inverter) and it is now arranged as follows:

The input from the switch is de-bounced by the Schmitt inverter, and the clean input is then passed into the lock input of the Flip-Flop. Each complete cycle of the switch alternates the output from the flip-flop, which is the output of this subsystem. The output is a digital CMOS 5V / 0V output

I am only using half of the flip-flop IC and one of the six inverters in the hex inverters.

The output from this sub system is fed into the PIC Controller on Port A Bit 0

TestingAfter wiring in a Schmitt Trigger, the latching action of the D-type worked perfectly, as tested using a multi-meter, and the output alternated from a few millivolts (≈0V) to 5.01V (≈5V) as expected.

Page 13: Alarm Project

Chris Shucksmith AS Electronics Project

Subsystems - 12V Heavy Duty Output

DescriptionAs the power output for the alarm siren and strobe light has to drive at least 500mA of current, I need to use a system that can handle such loads. The subsystem needs to be either a definite on or off output, and must be driven by the logical 0V / 5V 25mA output from the PIC Controller. In order to be able to supply not only this load, but also a range of higher and lower values of which the exact current requirements are not known, I have decided to use a Relay. This component will switch a load up to the full potential of the power supply. Unfortunately the relay requires more current to activate than the PIC Controller can supply, although driving the relay with a transistor switch can solve this.

Wiring Diagram Transistor used: BC441

Specifications: Material NPNTypical hFE 100@500mAIC (max) 2ABE Voltage Drop 0.7V

Protective Resistor CalculationIn order to ensure that the transistor is not destroyed, a protective resistor has to be used. The value of this depends on the current required to flow from the base to the emitter of the transistor. This base-emitter current controls the current allowed to flow through the relay and then from the collector to the emitter. The ratio of currents is the gain of the transistor (hFE).

The first task I needed to do was to measure the current required to flow through the relay coil to activate the relay. Using a multi-meter IC was found to be 100-120mA. You can see that this is within the maximum that can flow through the transistor, but exceeds the maximum that can flow through the PIC Controller, so the use of a transistor is justified. Knowing the gain of the transistor to be 100, the base current to produce this 120mA current is 100 times smaller, in this case 1.2mA.

Knowing the voltage of from the PIC will be 5V, and the transistor has a voltage drop of 0.7V, we can work out the required potential difference of the resistor:

VR = 5.0 – 0.7 = 4.3V

Finally, the resistance of R can be calculated:

R=VI= 4.3

0.0012=3583≈3.6k

In practise a slightly smaller value of R is used to ensure that the transistor is fully saturated on, and I have used 3.2KΩ

TestingWhen connected to the PIC Controller, and activated, the current flowing to the base was measured as about 2mA, although this is mostly due to rounding. This is well within the current requirements and activated the relay and external components with no problems.

Page 14: Alarm Project

Chris Shucksmith AS Electronics Project

Subsystems - Red Alarm and Green Armed LED’s

DescriptionTwo outputs from the PIC Controller are used to power light indicating diodes (LED’s) to give a visual indication to the user of the mode and status of the alarm system. The LED’s are rated as drawing 20-25mA of current with a voltage drop of 2 volts. I know that the PIC controller can provide an output of 25mA from the data sheet so this is not a problem. The PIC has a logical 1 output of 5V, so a protective resistor will be used to dissipate the other 3V. Both LED’s are identical in specification apart from colour, so the following Protective resistor calculation applies to them both.

Vsupply 5V Current 25mAPD over LED 2VPD over Resistor 3V

R=VI= 3.0

0.025=120

The nearest (higher) value resistor in the E24 Series is 120Ω

Wiring Diagram

TestingThis subsystem was initially tested by connecting it to the logical outputs from the Arm/Disarm switch subsystem to check the resistors were of the right value and that the LED’s were inserted with the correct polarity. The current did not exceed 25mA when tested, so the subsystem was connected to the PIC Controller.

Page 15: Alarm Project

Chris Shucksmith AS Electronics Project

Subsystems - 4 x Zone Status LED’s and Input Loops

DescriptionFour Switches simulate the sensors normally found in a burglar alarm system. These switches are of the normally open type. They are connected as in the wiring diagram, and when depressed raise the output to logical 1 – 5V. This is different to the standard loop type implementation for a burglar alarm.

The 4 Zone status LED’s are used to show if the corresponding switch has been pressed (zone triggered) and which was triggered first. These are directly driven from the pins of the PIC Controller, and have a protective resistor of 120Ω because the LED’s are of the same type as the LED’s used above for the alarm system indicators.

All four switches and LED’s are connected to Port B of the PIC Controller, with the switches on the bits 0-3 (least significant) and the LED’s on the upper four bits, 4-7.

Wiring Diagram

Subsystems - Reset Switch

DescriptionThe final input / output subsystem is the reset switch. This is a simple push to make switch wired up exactly the same as the zone switches above. This provides the input to the final IO Pin of the PIC Controller, and is used to reset the burglar alarm once triggered into an alarm condition.

Wiring Diagram

Page 16: Alarm Project

Chris Shucksmith AS Electronics Project

Subsystems – PIC Controller

DescriptionThe PIC Controller is the heart of this project and provides most of the processing of the entire system. It determines the which outputs must be switched on given the current conditions of the available inputs and the situation of various internal flags which reflect the list of alarms triggered and which was first.

The PIC Controller has been programmed with the program I have written in assembly language. There was an initial version which allowed me to get the project working, which was then expanded on to give the final version currently in use. These programs are listed in Appendix A and Appendix B.

As well as the required stable 5V power supply and 0V connections, the PIC Controller has pins for connecting to control and interpret inputs from all the other subsystems. Also there are pins which control the function of the PIC Controller, which need wiring in accordance with the recommendations in the PIC Controller data book. I need to keep the MCLR input at 5V for the PIC to operate, and need to provide a resistor and capacitor for the clock of the on board processor, which are shown below.

Wiring DiagramThe connections to other subsystems are omitted to simplify this diagram. The subsystems are connected as illustrated in the appropriate subsystem diagrams.

Page 17: Alarm Project

Chris Shucksmith AS Electronics Project

Software Revision 1 – Basic Operation

; PROJECT.ASM, Revision 1; Christopher Shucksmith, 10/02/2001; Electronics AS Level Project;; Uses a PIC 16F84 as a burglar alarm, monitoring 4 zones on PORTB 0-3. When an input is logical; 1 AND Armed signal on PORTA 0 is logical 1, then alarm sirens are issued on PORTA 2. PORTA 3 ; indicates the state of the Armed Signal (except when triggered), PORTA 4 indicates PIC power;#DEFINE PAGE0 BCF $03,5#DEFINE PAGE1 BSF $03,5

TRISA: .EQU $05PORTA: .EQU $05TRISB: .EQU $06PORTB: .EQU $06

.ORG 4 .ORG 5

PAGE1; Control Port A - 0arm, 1reset, 2alarm, 3armed, 4power

MOVLW %00000011 ;Define B0 and B1 as input MOVWF TRISA ; B2, B3 and B4 as output

; Data Port B - 4 zone loop inputs, 4 zone LED Outputs MOVLW %00001111 ;Define RB0-RB3 as input and RB4-RB7 as output

MOVWF TRISB PAGE0

RESET: BSF PORTA,4 ; set power light onBCF PORTA,2 ; set sirens offCLRF PORTB ; set all zone lights off

BTFSS PORTA,0 ; are we armed ? [BitTestFileSkipSet]GOTO NOTARMED ; no - show not armed statusGOTO ARMED ; no, go back and keep checking

NOTARMED BCF PORTA,3 ; show not armed statusGOTO RESET

ARMED: BSF PORTA,3 ; show armed statusBTFSC PORTB,0 ; is zone 1 triggered ?GOTO ALARM1BTFSC PORTB,1 ; is zone 2 triggered ?GOTO ALARM2BTFSC PORTB,2 ; is zone 3 triggered ?GOTO ALARM3BTFSC PORTB,3 ; is zone 4 triggered ?GOTO ALARM4GOTO RESET

ALARM1: MOVLW %00010000 ;show zone 1 triggered firstMOVWF PORTBBSF PORTA, 2 ; turn sirens onBTFSS PORTA,1 ; check for reset? [BitTestFileSkipSet]GOTO ALARM1 ; not a reset so keeping loopingGOTO RESET ; have been reset, so reset

ALARM2: MOVLW %00100000 ;show zone 2 triggered firstMOVWF PORTBBSF PORTA, 2 ; turn sirens onBTFSS PORTA,1 ; check for reset? [BitTestFileSkipSet]GOTO ALARM2 ; not a rest, keeping loopingGOTO RESET ; have been reset, so reset

ALARM3: MOVLW %01000000 ;show zone 3 triggered firstMOVWF PORTBBSF PORTA, 2 ; turn sirens onBTFSS PORTA,1 ; check for reset? [BitTestFileSkipSet]GOTO ALARM3 ; not a rest, keeping loopingGOTO RESET ; have been reset, so reset

ALARM4: MOVLW %10000000 ;show zone 4 triggered firstMOVWF PORTBBSF PORTA, 2 ; turn sirens onBTFSS PORTA,1 ; check for reset? [BitTestFileSkipSet]GOTO ALARM4 ; not a rest, keeping loopingGOTO RESET ; have been reset, so reset

.END ;final statement

Page 18: Alarm Project

Chris Shucksmith AS Electronics Project

Software Revision 2 – Initial Trigger Display

; PROJECT.ASM, Revision 2; Christopher Shucksmith, 10/02/2001; Electronics AS Level Project;; Uses a PIC 16F84 as a burglar alarm, monitoring 4 zones on PORTB 0-3. When an input is logical; 1 AND Armed signal on PORTA 0 is logical 1, then alarm sirens are issued on PORTA 2. PORTA 3 ; indicates the state of the Armed Signal (except when triggered), PORTA 4 indicates PIC power

; Revision 2 - shows subsequent alarms as a flashing output, first alarm as a steady output

#DEFINE PAGE0 bcf $03,5#DEFINE PAGE1 bsf $03,5

TRISA: .EQU $05PORTA: .EQU $05TRISB: .EQU $06PORTB: .EQU $06

AlarmFirst: .EQU $0C ; First alarm to be triggeredAlarmSecond: .EQU $0D ; subsequent alarmsDELAY: .EQU $0E ; Delay counters for flashingDELAY2: .EQU $0F ; inner delay counter for flashing

.ORG 4 .ORG 5

PAGE1; Control Port A - 0arm, 1reset, 2alarm, 3armed, 4power

movlw %00000011 ;Define B0 and B1 as input movwf TRISA ; B2, B3 and B4 as output

; Data Port B - 4 zone loop inputs, 4 zone LED Outputs movlw %00001111 ;Define RB0-RB3 as input and RB4-RB7 as output movwf TRISB

PAGE0

RESET: bsf PORTA,4 ; set power light onbcf PORTA,2 ; set sirens offmovlw %00000000movwf AlarmFirstmovwf PORTBbtfss PORTA,0 ; are we armed ? [BitTestFileSkipSet]GOTO NOTARMED ; no - show not armed statusGOTO ARMED ; no, go back and keep checking

NOTARMED bcf PORTA,3 ; show not armed statusGOTO RESET

ARMED: bsf PORTA,3 ; show armed statusbtfsc PORTB,0 ; is zone 1 triggered ?GOTO ALARM1btfsc PORTB,1 ; is zone 2 triggered ?GOTO ALARM2btfsc PORTB,2 ; is zone 3 triggered ?GOTO ALARM3btfsc PORTB,3 ; is zone 4 triggered ?GOTO ALARM4GOTO RESET

ALARM1: movlw %00010000 ;show zone 1 triggered firstGOTO SECONDALARM ; scan for other alarms

ALARM2: movlw %00100000 ;show zone 2 triggered firstGOTO SECONDALARM ; scan for other alarms

ALARM3: movlw %01000000 ;show zone 3 triggered firstGOTO SECONDALARM ; scan for other alarms

ALARM4: movlw %10000000 ;show zone 4 triggered firstGOTO SECONDALARM ; scan for other alarms

Page 19: Alarm Project

Chris Shucksmith AS Electronics Project

SECONDALARM: movwf AlarmFirstmovwf AlarmSecondmovwf PORTBbsf PORTA, 2 ; turn sirens on

SECONDSCAN: movf AlarmFirst,0movwf PORTB

movlw 100 ; bias value to make 1 call appx 2s movwf DELAY ; put 15 > DELAY

LNDELAY1: clrf DELAY2 ; Clear Delay2LNLOOP1: btfsc PORTA,1 ; check for reset? [BitTestFileSkipClear]

GOTO RESET ; have been rest, so resetbtfsc PORTB,0 ; is zone 1 triggered ?bsf AlarmSecond,4 ; show also zone 1btfsc PORTB,1 ; is zone 2 triggered ?bsf AlarmSecond,5 ; show also zone 1btfsc PORTB,2 ; is zone 3 triggered ?bsf AlarmSecond,6 ; show also zone 1btfsc PORTB,3 ; is zone 4 triggered ?bsf AlarmSecond,7 ; show also zone 1

; incriment delay 2incfsz DELAY2,1 ; increment (add 1 to) the value of DELAY and check

; if it has reached zero (rolled over from 255 to 0) goto LNLOOP1 ; executed only if COUNT is not yet 0

incfsz DELAY,1goto LNDELAY1

movf AlarmSecond,0movwf PORTB

movlw 100 ; bias value to make 1 call appx 2s movwf DELAY ; put 15 > DELAY

LNDELAY2: clrf DELAY2 ; Clear Delay2LNLOOP2: btfsc PORTA,1 ; check for reset? [BitTestFileSkipClear]

GOTO RESET ; have been rest, so resetbtfsc PORTB,0 ; is zone 1 triggered ?bsf AlarmSecond,4 ; show also zone 1btfsc PORTB,1 ; is zone 2 triggered ?bsf AlarmSecond,5 ; show also zone 1btfsc PORTB,2 ; is zone 3 triggered ?bsf AlarmSecond,6 ; show also zone 1btfsc PORTB,3 ; is zone 4 triggered ?bsf AlarmSecond,7 ; show also zone 1

; incriment delay 2incfsz DELAY2,1 ; increment (add 1 to) the value of DELAY and check

; if it has reached zero (rolled over from 255 to 0) goto LNLOOP2 ; executed only if COUNT is not yet 0

incfsz DELAY,1goto LNDELAY2

goto SECONDSCAN

.END ;final statement

TestingThe PIC Controller was programmed with a test program supplied with the development kit. This rippled all of the pins as outputs with a night-rider effect. This was used to check that the PIC controller’s processor was active. My burglar alarm program was then sent to the device and the subsystems connected together

Success! All the subsystems reacted as expected with the PIC controller, and the project was now fully functional.

Page 20: Alarm Project

Chris Shucksmith AS Electronics Project

Component Layout

Reset Switch

Red & Green LED’s

Heavy Duty Output Reset 4 Zone Switches & LED’s

Arm Disarm Switch PIC Controller 12V Power Supply

Power SupplyVoltage Regulator

Heat sinkSmoothing Capacitor

Zone I/OZone Switches

Zone LED’sPull-up Resistors

Protective Resistors

PIC ControllerTiming Resistor &

Capacitor

Heavy Duty OutputTransistor

Protective resistorRelay

Protective Diode

Arm / Disarm SwitchD-Type Flip FlopSchmitt Inverter

CapacitorPotential Divider

ResistorsPress Switch

Reset SwitchPull-up

Resistor

Status LED’sProtective Resistors

Page 21: Alarm Project

Chris Shucksmith AS Electronics Project

System DetailsWhen the alarm system is disarmed, no LED’s are activated, so there is only the IC devices activated, and so the current reading for the entire program is only 10.0 – 20.0mA. There is some slight variation because the PIC controller’s current consumption is not constant and fluctuates with the program section being executed.

If the user then presses the Arm/Disarm button, the armed LED (Green) lights to indicate the change in state. The current consumption at this point increases to 25-30mA, which is predictable as the only increase in load is that of the LED and protective resistor. As before, there are current fluctuations because of the nature of the PIC.

In this armed state, if any one of the Zone Simulator switches is pressed, then the PIC triggers the Alarm output pin. This is connected to the second status LED, the Alarm LED, and also to the base of the transistor. This fully saturates the transistor and allows enough current to flow to activate the relay, which switches the heavy load to the external strobe light and siren. Within another millisecond or so the LED corresponding to the Zone Switch triggered is illuminated as a steady, continuously on, supply.

The current compunction at the moment is found by disconnecting the siren and strobe so that only the project’s readings are shown. In the state of only one device triggered, the current has risen to 130-140mA, which when you remember the current though the relay coil alone is 100-120mA, is a sensible figure.

If any additional zone switches are depressed while the PIC is in this alarm state, there is no change in the Alarm output, but again the corresponding LED is illuminated. However this time, the trigger is known to be less important, and is indicated with a flashing LED output, as are any further triggers, (until all four zones are activated). In this way it is clear for the user to see which zone/sensor was activated first by the steady pulse.

As the LED’s are continually changing there on off status, the current readings change a lot, but peak at about 210mA. When connected to the strobe and siren, each which draw an additional 200-300mA, the total current is about 700mA

Assuming a current of 700mA, and a voltage of 12V, the total amount of power used by the project and the external alarm components can be calculated.

Power =Voltage×Current=12V×0.7A=8.4W

Page 22: Alarm Project

Chris Shucksmith AS Electronics Project

SafetyIn order to ensure that I was working safely, I ensured that the power supply voltage was constantly at a safe voltage and that it was the correct voltage for the subsystem being tested. I always ensured that I switched off the power supply whilst modifying and building my project. I was careful not to operate the voltage regulator IC without the heat sink, as this can get hot especially when the alarm system is at full load (alarm condition) for extended periods of time. I was careful to test each subsystem to ensure that its current requirements did not exceed the output of the previous system, and that all components were operating within there voltage and current (power) limits, and that protective resistors were used when necessary.

Limitations and ModificationsOperating Voltage 12V Regulated Power SupplyThe project functions fully form a 12V regulated supply, providing that it can supply the required current of +700mA when under full load

Input Zones 4 Standard individually monitored InputsThe project has four switches to simulate four zones, and an individual input to the PIC Controller monitors each individually

Control Switches Two switches, Arm / Disarm and Reset for Ease of useThere are two main switches to operate the system, which can be seen on the photographs of the system and there operation is described above.

Indicators When a zone has been tripped, and preferably which was tripped firstThere is an individual LED’ for each zone which shows when the zone has been activated, and also which was trigged first using a system of flashing and constant LED’s.

Alarm Output Switched 12V Output when during alarm conditionBe able to drive > 500mA output current

The switched alarm output is provided by the transistor and relay system, and has been tested in operation with a commercial siren and strobe flasher (see photographs), and can supply a load to them only limited by the maximum current of the relay (3A) and the power supply’s abilities to deliver such a current.

Input Sampling Time > 20 Times each secondThe PIC Controller has a clock speed approaching 10Mhz, and the program scans the IO lines in a tight loop for changes. I estimate that each individual IO line is tested at least 1000 times a second, although in reality it is probably a factor of ten larger.

This would be one area where use could be made of the single spare IO pin of the PIC Controller. It would be an interesting modification to the program to toggle the logical output of this pin after every test. This square-wave pulse could then be timed using an oscilloscope.

Low Standby Current < 200 mAAs stated above, when in the armed status, the current drawn is only 30mA and so is a fraction of the specification’s value. This is partly due to the low current consumption of the PIC Controller, and that the majority of the project is not receiving any power at this time.

Page 23: Alarm Project

Chris Shucksmith AS Electronics Project

AcknowledgementsMicrochip PIC 16F48 Data Sheet (PDF Document from www.microchip.com )Research on PIC Pin-out, functions, clock rates, wiring, and “official” Assembly Language documentation.

“Electronic Products” by Collins Educational (ISBN 0 00 320012 4)Denouncing cause and solution – Schmitt Trigger arrangement and sample usage.

Matrix Electronics PICtutor package (Demo from www.matrixelectronics.co.uk )Used for a complete tutorial to using the PIC Controller, and the “deluxe development board” supplied with this package was used for programming the PIC with my code.

John Leggott College – Departmental resources and tutorsThanks to the input and dedication of tutors and the use of the IT and electronics facilities of the department, this project evolved from an idea to reality.

RS Electronics Web SiteUsed for the selection and purchase of the siren, and for obtaining specification of transistor, and relay, and for downloading data sheets for the voltage regulator and flip-flop IC’s.

PPP (PIC Parallel Programmer) & TASM (Table Driven Assembler)These are the software programs I used to compile my source code (listed in the appendix) from the text file into machine code for use by the PIC. The compiler I used is TASM, and is available free for evaluation use. The assembler program creates an .obj file, which is then sent to the development board using the PPP program shown below, available freely for private use.

Page 24: Alarm Project

Chris Shucksmith AS Electronics Project

Integration PhotographThis final picture shows the complete alarm system connected to a standard 12V flashing strobe and ear-piercing siren. They are easily switched by the high-current output provided by the relay. The connections to stranded cable are made using screw-block connectors.