Escolar Documentos
Profissional Documentos
Cultura Documentos
AS Electronics Project
PIC Powered
Chris Shucksmith
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.
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
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
4 Input N.C. Loops Normally Closed Type Simulation switches Reset Switch Non-latching Variety
Push to make
12V Heavy Duty Output Transistor driven Relay Red Alarm Status LED Protective Resistor Correct Polarity Green Armed LED Protective Resistor Correct Polarity
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
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
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
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
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
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
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
Wiring Diagram
Transistor used: BC441 Specifications:
Material Typical hFE IC (max) BE Voltage Drop NPN 100@500mA 2A 0.7V
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
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
Wiring Diagram
Wiring Diagram
Chris Shucksmith
AS Electronics Project
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
; 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
; 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
.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 ?
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:
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
PIC Controller
Power Supply
Zone I/O Zone Switches Zone LEDs Pull-up Resistors Protective Resistors
PIC Controller
Reset Switch
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.
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.