Você está na página 1de 24

Chris Shucksmith

AS Electronics Project

PIC Powered

Burglar Alarm System

A microprocessor driven four channel security system.


chris@shucksmith.co.uk

Chris Shucksmith

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.

Chris Shucksmith

AS Electronics Project

Aim
I 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 Inputs 4 Zone Inputs

Control Unit 4 Continuously Monitored Zones 4 LEDs Status of each Zone Arm / Disarm and Reset Switches Alarm Status Indicators(s)

Alarm Outputs Contacts for the connection of External Buzzer External Strobe

Chris Shucksmith

AS Electronics Project

Research
Burglar Alarms
Most 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.

Input Sensors Continuous 12V power supply to operate Device to cut the loop when triggered

Power Supply
Control Unit Provide 12V for inputs Switch 12V for outputs

N.C. Loop

Regulated PSU 12V Power Supply

Switched Output
Output Devices Sirens & Strobe Light Require a 12V supply when required to sound / flash

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.

Chris Shucksmith

AS Electronics Project

Initial Thoughts
In 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 12V Power Supply
Regulator for 5V Circuitry Smoothing Capacitors

Processing Modules

Output Modules 4 Zone Status LEDs Protective Resistors

4 Input N.C. Loops Normally Closed Type Simulation switches Reset Switch Non-latching Variety
Push to make

PIC Controller or Logic Gates System


When armed, and until reset: Show and Latch Zone Inputs On First Zone Loop Cut, Activate alarm output signal

12V Heavy Duty Output Transistor driven Relay Red Alarm Status LED Protective Resistor Correct Polarity Green Armed LED Protective Resistor Correct Polarity

Protective Base resistor Relay Coil Diode in R. bias

Arm / Disarm Switch Non-latching Variety Push to make

D-Type Flip Flop Latch Connect Q to Data Input Arm / Disarm to Clock Input

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.

Chris Shucksmith

AS Electronics Project

Hardware - PIC Microprocessor


I 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 Site URL: 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) 68 10 Speed (MHz) 13 I/O Ports Timers 1+WDT ICSP Yes

Pin Assignment and Electrical Characteristics

Absolute Maximum Ratings Ambient temperature under bias Storage temperature Voltage on VDD with respect to VSS Voltage on MCLR with respect to VSS Voltage on any pin with respect to VSS (except VDD and MCLR) Total power dissipation Maximum current out of VSS pin Maximum current into VDD pin Input clamp current, IIK (VI < 0 or VI > VDD) Output clamp current, IOK (VO < 0 or VO > VDD) Maximum output current sunk by any I/O pin Maximum output current sourced by any I/O pin Maximum current sunk by PORTA Maximum current sourced by PORTA Maximum current sunk by PORTB Maximum current sourced by PORTB

-5C to +12C -6C to +15C -0.3 to +7.5V -0.3 to +14V -0.6V to (VDD + 0.6V) 800 mW 150 mA 100 mA 20 mA 20 mA 25 mA 20 mA 80 mA 50 mA 150 mA 100 mA

Chris Shucksmith

AS Electronics Project

Pin Functions

Legend: I = Input = Not used Note

O = Output TTL = TTL input

I/O = Input/Output ST = Schmitt Trigger input

P = Power

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.

Chris Shucksmith

AS Electronics Project

Microprocessor Architecture

Programming the PIC


In 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.

Chris Shucksmith

AS Electronics Project

Specification
Requirements

Operating Voltage Input Zones Control Switches Indicators Alarm Output Input Sampling Time Low Standby Current

12V Regulated Power Supply 4 Standard individually-monitored Inputs Two switches, Arm / Disarm and Reset for Ease of use When a zone has been tripped, - and preferably which was tripped first Switched 12V Output when during alarm condition Be able to drive > 500mA output current > 20 Times each second < 200 mA

Possible Solutions
As 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.

Chris Shucksmith

AS Electronics Project

Chosen Solution
I 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 LEDs 4 Zone Status LEDs and 4 Zone Inputs Reset Switch PIC Controller

Chris Shucksmith

AS Electronics Project

Subsystems - 12V Power Supply


Description
The 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 DType 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. Description Part Number Manufacturer NATO

298-8514 IC, Voltage Regulator, 5V, L7805CV L7805CV ST MICROELECTRONICS

Wiring Diagram

Pin 1 is connected to the 12V Positive power supply rail Pin 3 is connected to the 0V Negative power supply rail Pin 2 is used as the 5V positive rail, with the existing negative rail I have used a smoothing electrolytic capacitor of 2200F in place of the 0.33F capacitor and a tantalum bead capacitor of 1F in place of the 0.1F capacitor. A heat sink is attached onto the L7805CV IC to dissipate the heat generated.

Problems
Immediately after connecting the voltage regulator to the 12V power supply, the power supplys current limiter activated. The current was displayed at over 2A, so obviously there was a problem. On reinspecting 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.

Testing
After 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.

Chris Shucksmith

AS Electronics Project

Subsystems - Arm/Disarm Switch and D-Type Latch


Description
The 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.

Problems
The 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:

Chris Shucksmith

AS Electronics Project

Solution
I 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 flipflop, 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

Testing
After 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.

Chris Shucksmith

AS Electronics Project

Subsystems - 12V Heavy Duty Output


Description
As 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 Typical hFE IC (max) BE Voltage Drop NPN 100@500mA 2A 0.7V

Protective Resistor Calculation


In 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 baseemitter 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: V 4.3 R= = =35833.6k I 0.0012 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

Testing
When 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.

Chris Shucksmith

AS Electronics Project

Subsystems - Red Alarm and Green Armed LEDs


Description
Two outputs from the PIC Controller are used to power light indicating diodes (LEDs) to give a visual indication to the user of the mode and status of the alarm system. The LEDs are rated as drawing 2025mA 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 LEDs are identical in specification apart from colour, so the following Protective resistor calculation applies to them both. Vsupply PD over LED PD over Resistor
R=

5V 2V 3V

Current 25mA

V 3.0 = =120 I 0.025 The nearest (higher) value resistor in the E24 Series is 120

Wiring Diagram

Testing
This 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 LEDs were inserted with the correct polarity. The current did not exceed 25mA when tested, so the subsystem was connected to the PIC Controller.

Chris Shucksmith

AS Electronics Project

Subsystems - 4 x Zone Status LEDs and Input Loops


Description
Four 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 LEDs 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 LEDs are of the same type as the LEDs used above for the alarm system indicators. All four switches and LEDs are connected to Port B of the PIC Controller, with the switches on the bits 0-3 (least significant) and the LEDs on the upper four bits, 4-7.

Wiring Diagram

Subsystems - Reset Switch


Description
The 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

Chris Shucksmith

AS Electronics Project

Subsystems PIC Controller


Description
The 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 Diagram
The connections to other subsystems are omitted to simplify this diagram. The subsystems are connected as illustrated in the appropriate subsystem diagrams.

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: PORTA: TRISB: PORTB: .EQU .EQU .EQU .EQU $05 $05 $06 $06 .ORG 4 .ORG 5 PAGE1 MOVLW %00000011 MOVWF TRISA MOVLW %00001111 MOVWF TRISB PAGE0 RESET: BSF PORTA,4 BCF PORTA,2 CLRF PORTB BTFSS PORTA,0 GOTO NOTARMED GOTO ARMED NOTARMED ARMED: BCF PORTA,3 GOTO RESET BSF PORTA,3 BTFSC PORTB,0 GOTO ALARM1 BTFSC PORTB,1 GOTO ALARM2 BTFSC PORTB,2 GOTO ALARM3 BTFSC PORTB,3 GOTO ALARM4 GOTO RESET MOVLW %00010000 MOVWF PORTB BSF PORTA, 2 BTFSS PORTA,1 GOTO ALARM1 GOTO RESET MOVLW %00100000 MOVWF PORTB BSF PORTA, 2 BTFSS PORTA,1 GOTO ALARM2 GOTO RESET MOVLW %01000000 MOVWF PORTB BSF PORTA, 2 BTFSS PORTA,1 GOTO ALARM3 GOTO RESET MOVLW %10000000 MOVWF PORTB BSF PORTA, 2 BTFSS PORTA,1 GOTO ALARM4 GOTO RESET ; Control Port A - 0arm, 1reset, 2alarm, 3armed, 4power ;Define B0 and B1 as input ; B2, B3 and B4 as output ; Data Port B - 4 zone loop inputs, 4 zone LED Outputs ;Define RB0-RB3 as input and RB4-RB7 as output

; set power light on ; set sirens off ; set all zone lights off ; are we armed ? [BitTestFileSkipSet] ; no - show not armed status ; no, go back and keep checking ; show not armed status ; show armed status ; is zone 1 triggered ? ; is zone 2 triggered ? ; is zone 3 triggered ? ; is zone 4 triggered ?

ALARM1:

;show zone 1 triggered first ; ; ; ; turn sirens on check for reset? [BitTestFileSkipSet] not a reset so keeping looping have been reset, so reset

ALARM2:

;show zone 2 triggered first ; ; ; ; turn sirens on check for reset? [BitTestFileSkipSet] not a rest, keeping looping have been reset, so reset

ALARM3:

;show zone 3 triggered first ; ; ; ; turn sirens on check for reset? [BitTestFileSkipSet] not a rest, keeping looping have been reset, so reset

ALARM4:

;show zone 4 triggered first ; ; ; ; turn sirens on check for reset? [BitTestFileSkipSet] not a rest, keeping looping have been reset, so reset

.END

;final statement

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: PORTA: TRISB: PORTB: .EQU .EQU .EQU .EQU $05 $05 $06 $06 .EQU .EQU .EQU .EQU $0C $0D $0E $0F ; First alarm to be triggered ; subsequent alarms ; Delay counters for flashing ; inner delay counter for flashing

AlarmFirst: AlarmSecond: DELAY: DELAY2:

.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 ; bcf PORTA,2 ; movlw %00000000 movwf AlarmFirst movwf PORTB btfss PORTA,0 GOTO NOTARMED ; GOTO ARMED ; bcf PORTA,3 GOTO RESET bsf PORTA,3 btfsc PORTB,0 GOTO ALARM1 btfsc PORTB,1 GOTO ALARM2 btfsc PORTB,2 GOTO ALARM3 btfsc PORTB,3 GOTO ALARM4 GOTO RESET set power light on set sirens off

; are we armed ? [BitTestFileSkipSet] no - show not armed status no, go back and keep checking

NOTARMED ARMED:

; show not armed status ; show armed status ; is zone 1 triggered ? ; is zone 2 triggered ? ; is zone 3 triggered ? ; is zone 4 triggered ?

ALARM1: ALARM2: ALARM3: ALARM4:

movlw %00010000 GOTO SECONDALARM movlw %00100000 GOTO SECONDALARM movlw %01000000 GOTO SECONDALARM movlw %10000000 GOTO SECONDALARM

;show zone ; scan for ;show zone ; scan for ;show zone ; scan for ;show zone ; scan for

1 triggered first other alarms 2 triggered first other alarms 3 triggered first other alarms 4 triggered first other alarms

Chris Shucksmith
SECONDALARM: movwf AlarmFirst movwf AlarmSecond movwf PORTB bsf PORTA, 2 ; turn sirens on movf AlarmFirst,0 movwf PORTB

AS Electronics Project

SECONDSCAN:

LNDELAY1: LNLOOP1:

movlw 100 ; bias value to make 1 call appx 2s movwf DELAY ; put 15 > DELAY clrf DELAY2 ; Clear Delay2 btfsc PORTA,1 ; check for reset? [BitTestFileSkipClear] GOTO RESET ; have been rest, so reset btfsc PORTB,0 ; is zone 1 triggered ? bsf AlarmSecond,4 ; show also zone 1 btfsc PORTB,1 ; is zone 2 triggered ? bsf AlarmSecond,5 ; show also zone 1 btfsc PORTB,2 ; is zone 3 triggered ? bsf AlarmSecond,6 ; show also zone 1 btfsc PORTB,3 ; is zone 4 triggered ? bsf AlarmSecond,7 ; show also zone 1 ; incriment delay 2 incfsz 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,1 goto LNDELAY1 movf AlarmSecond,0 movwf PORTB movlw 100 ; bias value to make 1 call appx 2s movwf DELAY ; put 15 > DELAY clrf DELAY2 ; Clear Delay2 btfsc PORTA,1 ; check for reset? [BitTestFileSkipClear] GOTO RESET ; have been rest, so reset btfsc PORTB,0 ; is zone 1 triggered ? bsf AlarmSecond,4 ; show also zone 1 btfsc PORTB,1 ; is zone 2 triggered ? bsf AlarmSecond,5 ; show also zone 1 btfsc PORTB,2 ; is zone 3 triggered ? bsf AlarmSecond,6 ; show also zone 1 btfsc PORTB,3 ; is zone 4 triggered ? bsf AlarmSecond,7 ; show also zone 1 ; incriment delay 2 incfsz 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,1 goto LNDELAY2

LNDELAY2: LNLOOP2:

goto SECONDSCAN .END ;final statement

Testing
The 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 controllers 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.

Chris Shucksmith

AS Electronics Project

Component Layout

Arm / Disarm Switch


D-Type Flip Flop Schmitt Inverter Capacitor Potential Divider Resistors Press Switch

PIC Controller

Timing Resistor & Capacitor

Power Supply

Voltage Regulator Heat sink Smoothing Capacitor

Heavy Duty Output Reset Switch Status Pull-up LEDs


Resistor Protective Resistors Transistor Protective resistor Relay Protective Diode

Zone I/O Zone Switches Zone LEDs Pull-up Resistors Protective Resistors

Arm Disarm Switch

PIC Controller

12V Power Supply

Reset Switch

Heavy Duty Output

Reset 4 Zone Switches & LEDs

Red & Green LEDs

Chris Shucksmith

AS Electronics Project

System Details
When the alarm system is disarmed, no LEDs 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 controllers 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 projects readings are shown. In the state of only one device triggered, the current has risen to 130140mA, 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 LEDs 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 = VoltageCurrent = 12V0.7A = 8.4W

Chris Shucksmith

AS Electronics Project

Safety
In 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 Modifications


Operating Voltage 12V Regulated Power Supply The 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 Inputs The 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 use There 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 first There 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 LEDs. Alarm Output Switched 12V Output when during alarm condition Be 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 supplys abilities to deliver such a current. Input Sampling Time > 20 Times each second The 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 mA As stated above, when in the armed status, the current drawn is only 30mA and so is a fraction of the specifications 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.

Chris Shucksmith

AS Electronics Project

Acknowledgements
Microchip 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 tutors Thanks 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 Site Used 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 ICs. 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.

Chris Shucksmith

AS Electronics Project

Integration Photograph
This final picture shows the complete alarm system connected to a standard 12V flashing strobe and earpiercing 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.

Você também pode gostar