This is the lowest-cost dialing alarm on the market and shows what can be done with a PIC microcontroller. The complete circuit is shown below. You cannot see all the features of this project by looking at the circuit - most of them are contained in the program. So, read on and see what we have included. . .
The programming socket is not on the PC board - it has been added for the time when you want to modify the program and "burn" a new chip.
The arrows on the diagram show the direction of a signal. Outputs RA4 and RA6 produce rail voltage for the stages they are supplying.
Dial Alarm-2 has a single input (although a number of sensors can be placed in parallel on the same input line). The circuit requires a trigger pulse to turn on the Alarm. This is achieved by placing a 1u on the input line and keeping it discharged via two 100k resistors. When the input goes low, the 1u transfers the LOW to the micro and if the input remains LOW, the 1u charges via the second 100k resistor.
The micro executes the program and outputs a low on RB7 to turn on the LED in the opto-coupler and this causes the line to be "picked up" via a high-gain Darlington transistor. The micro then dials two phone numbers and produces a Hee Haw sound to alert the called party of an intrusion. The circuit also has a sensitive microphone with a high-gain amplifier. This is connected to the phone line when the alarm is triggered.
Amplified audio of the room is then passed down the line after the Hee Haw tone. This signal is clear enough to detect conversations and/or movement in the target area and the listener can determine the situation. If the sounds are determined to be family or staff etc, the alarm can be de-activated by pressing any of the buttons on the receiving phone. This will pass a tone down the line and is picked up by the alarm to shut it off. If the first number is not answered within a few seconds, a second number is called and the process is repeated. The two numbers are then called again and the alarm closes down. Simple but brilliant. The flow Diagram for the alarm is shown below:
The arrows on the diagram show the direction of a signal. Outputs RA4 and RA6 produce rail voltage for the stages they are supplying.
Dial Alarm-2 has a single input (although a number of sensors can be placed in parallel on the same input line). The circuit requires a trigger pulse to turn on the Alarm. This is achieved by placing a 1u on the input line and keeping it discharged via two 100k resistors. When the input goes low, the 1u transfers the LOW to the micro and if the input remains LOW, the 1u charges via the second 100k resistor.
The micro executes the program and outputs a low on RB7 to turn on the LED in the opto-coupler and this causes the line to be "picked up" via a high-gain Darlington transistor. The micro then dials two phone numbers and produces a Hee Haw sound to alert the called party of an intrusion. The circuit also has a sensitive microphone with a high-gain amplifier. This is connected to the phone line when the alarm is triggered.
Amplified audio of the room is then passed down the line after the Hee Haw tone. This signal is clear enough to detect conversations and/or movement in the target area and the listener can determine the situation. If the sounds are determined to be family or staff etc, the alarm can be de-activated by pressing any of the buttons on the receiving phone. This will pass a tone down the line and is picked up by the alarm to shut it off. If the first number is not answered within a few seconds, a second number is called and the process is repeated. The two numbers are then called again and the alarm closes down. Simple but brilliant. The flow Diagram for the alarm is shown below:
Dial Alarm-2 Flow Diagram
This alarm has been developed in response to a number of recent large robberies reported in the news. Robberies are a constantly increasing crime, but very few are reported, unless they have a "twist." Recently, the robbers navigated the conventional alarm system and broke into the night safe in the Manager's office. The haul was quite significant and it's surprising such a large amount of cash was kept on the premises. The weakest link in most alarm systems are the PIR detectors, used to detect movement. It's a known fact that they are very easy to foil. It's so easy we are forbidden to print details of how to do it. But many thieves must be aware of the trick and that's why a back-up system is essential.
The cheapest back-up system is the use of the phone line. I know what you are going to say. Cutting the telephone line is an easy matter and offers little security. But finding the line in a premises is not very easy and if there are two or more incoming lines, it's difficult to know which is connected to the dialler. Nothing is infallible, but for a lot less than $50 you can build this project and have a back-up to protect your property.
The other advantage of our design is the "set and forget feature." The alarm is designed to ring your mobile and if you keep your phone beside you 24 hours a day, you can have this peace of mind, whether you are in your office, factory, holiday house or quietly dining at your favourite restaurant.
You can protect any area where a telephone line can be installed. This includes houses-under- construction and outlying sheds.
Talking Electronics has been producing security devices for more than 15 years and this project is a culmination of those years of experience.
The high-sensitivity amplifier in the alarm is our development and comes from our highly successful Infinity Bug. This device connects to the phone line anywhere in the world and when the number is rung, the infinity bug answers the call and lets you listen in to the activities in the room. It's just like being there. We have used the same circuit in this project. When it is activated, you can easily work out if it has been triggered by staff, a family member or an intruder. At least it prevents unnecessarily attending 90% of false alarms and offers enormous peace of mind.
The secret lies in the placement of the triggering device. We have provided only one input (trigger input). And there's a reason for this. The idea is to place the sensor near the target area or on an actual device, near the microphone.
For instance, it you are protecting a house, a thief always goes to the main bedroom and rummages through the drawers and cupboards. In this case a drawer that is never used should be wired with a magnetic switch (reed switch) or a movement detector such as a mercury switch. These switches can be housed in a plastic case for easy screwing to a wall or door and are very reliable in operation. When the drawer is pulled out or the door opened, the switch is activated. If you are protecting a wall safe, the switch is placed near the safe in a clipboard or picture so that when the board or picture is moved, the alarm is activated. If a room is to be monitored, the switch is placed on the door so that when it is opened, the alarm is activated. If other valuables are being protected (such as a VCR, scanner etc) a suggestion is to place a clipboard against the item. The idea is the clipboard has to be moved to get at the "valuables." The clipboard contains a magnet and the switch is nearby. The clipboard keeps the switch open (or closed) and when it is moved, the alarm is activated.
The ideal arrangement is to avoid touching the clipboard, drawer, door or other "prop" during normal activities and this keeps the alarm activated at all times.
Another suitable trigger device is a pressure mat. This is something that can be avoided by "those in the know" and you can monitor an area during your absence. The alarm can be used for other things too. You can determine when your business premises are opened up in the morning by placing a pressure mat or reed switch on a door. The same can apply to a particular room in your establishment.
The purpose of this article is not only to produce the worlds smallest dialling alarm but also show you how the program runs so you can modify any of the routines to suit your own particular requirements.
The program can be re-written to dial only one number for two rings then hang up, or three rings, then again after 2 minutes or any combination to suit your requirements. Many mobile phones identify the caller on the display and you can keep track of the exact time of arrival and departure of different personnel.
The alarm can be programmed to monitor machinery and dial your mobile when a breakdown occurs. It can monitor water level or even your mail box. The possibilities are unlimited and it's just a matter of modifying the program to suit your own needs.
But before you change any of the program you have to understand what the program does and be capable of changing the instructions without upsetting the operation of the alarm.
Remember: A little knowledge is a dangerous thing. Before doing any re-writing of the program you need to read our notes on programming and carry out one small modification at a time.
This is really a very advanced project. The fact that is looks simple is the power of the microcontroller. It's taking the place of at least 10 chips in a normal alarm.
Timing and DTMF tones have all been converted to instructions of a program. And the advantage of a program is the simplicity of alteration. A time-interval can be changed or a phone number altered with a few lines of code. Even new features can be added without the need for additional hardware. This project uses the PIC16F628A to its maximum and shows what can be done with a PIC microcontroller.
You can program a new number or change a number at any time by using the 4 buttons. The number is stored in EEPROM so it will not be lost when the power is removed.
Before we go any further we must state that this project cannot be connected to the public telephone system. Only approved devices can be connected to the Public Phone System and any experimental device must be approved for experimentation and connected via a "telephone Line Separating Device." These are available from Altronic Imports for approx $100.
This is unfortunately the case and when we discuss connecting the project "to the line," we are referring to an experimental telephone system such as the one we have put together at Talking Electronics, to test and develop projects such as these.
See the section "Testing The Project" for more details of the Test Circuit. It consists of 27v derived from 9v batteries, a 12v relay, a telephone and a socket, all in series. The 12v relay is included to limit the current.
Dial Alarm-2 is not isolated from the phone line nor does it have any spike protection. Normal phones has 5,000v isolation The maximum input rejection of Dial Alarm-2 is 125v made up of 80v via the collector-emitter of the BD679 transistor and 45v via the collector-emitter of the BC547 transistor. The "ring-voltage" can be as high as 120v and the transistors are just at the point of zenering. They may clip the ring voltage if it exceeds 130v.
THE CIRCUIT
The circuit consists of 6 building blocks.
1. The trigger input.
2. The tone (whistle) detector.
3. The DTMF wave-shaping circuit.
4. The high-gain audio amplifier.
5. The microcontroller.
6. The programming buttons
1. THE TRIGGER INPUTS
The project is connected to a 6v supply at all times and to extend the battery life, the micro turns off after use. The current drops to less than 1uA.
The trigger must be a pulse to prevent the circuit re-triggering. This is called a TRIGGER PULSE.
Two trigger inputs have been provided.
L trigger is a LOW trigger and this means the switch connects between the L Trigger input and 0v.
The H Trigger connects between the H Trigger line and 5v rail. See below for circuit.
CONNECTING MORE INPUT DEVICES
Input devices are connected to the "L Trigger" (Low Trigger) and "H Trigger" (High Trigger) inputs.
For a sensor such as a mercury switch (tilt switch) or reed switch, it does not matter if they are placed on the L Trigger or H trigger. The alarm is "polling" both inputs.
But if the trigger device is a transistor or output from an alarm module, you need to know if the trigger will be LOW or HIGH when activated. The second diagram below shows how to connect these to the Alarm.
Only one input has been shown on the main circuit but if you want to add a High Trigger, the following circuit can be added. You will have to add the necessary code to the program to detect the H Trigger.
Adding a HIGH Trigger
Connecting tilt switch "high" and "low"
Connecting tilt switch "high" and "low"
Connecting transistor "low" and output of PIR Module "high"
More than one trigger device can be fitted to the alarm provided they are connected in parallel as shown in the diagram below.
2. THE TONE DETECTOR
The simplest building block in the project is the Tone Detector. It is designed to detect any tone of about 500Hz on the phone line such as a whistle or DTMF. When this tone is detected, the alarm will turn off. In this case the hardware does the detection.
The circuit amplifies the signal on the phone line and this turns on the second transistor. On the output is a 1u electrolytic. The stage sits with the collector at rail voltage, due to the biasing components keeping the first transistor on and the second transistor off. When a signal is delivered, the first transistor turns off and the collector of the second transistor goes low. This causes the electrolytic to discharge. This will be detected by the micro as a LOW.
3. THE DTMF WAVE-SHAPING CIRCUIT
Dialing a phone number is carried out by sending a tone down the line. So that whistling can not carry out a dialing operation, the telephone company decided to make the tone impossible to produce "by accident."
Each dialing tone consists of two frequencies, sent at the same time. These frequencies must be in the shape of a sinewave as the detecting device "locks onto" each of the frequencies at the same
time and produces a very-fast result. The only problem is a micro can only produce a square wave.
To convert a square wave into a sinewave, we need a wave shaping circuit. In essence this consists of charging and discharging a capacitor with a square wave and "picking off" the waveform.
The charging of a capacitor is exponential but if we take the beginning of the curve and compare it to a sinewave, the two match up fairly closely.
That's what we have done. We have charged a 100n capacitor very quickly via a 1k resistor so that it is nearly fully charged and then we begin to discharge it. The result is a fairly "peaky" sine wave. The waveform is picked off the capacitor via a 4k7 resistor and passed into an amplifier transistor (same transistor that amplifies the audio at the target zone). The two tones are produced at the same time by the micro and combined after the square waves have been shaped.
The component values have been especially chosen to produce the required sinusoidal waveform. The 10u on the output is very critic al as it determines the amplitude of the DTMF as well as the shape of the signal.
Getting the DTMF tone generator to work was one of the most difficult parts of this project as the tone detectors at the exchange are very "exacting" and critical.
Although we have generated ten tones in the micro, there are tone-generating chips that produce 16 tones, while only 12 tones are used on the telephone keypad. The additional 4 tones are shown on the diagram below as A, B, C and D. The two symbol keys are called "star" (*) and "hache" (hash) key # (also known as the pound key).
The extra tones can be generated by the program but are not needed in our situation. In the early days of DTMF, the 4 extra tones were used by the telephone companies to route the calls and create call-charges. The basis of defeating these charges was through "blue boxes" held to the mouth-piece, while creating the extra tones. Things have been tightened up since then.
The high gain amplifier is the two-transistor amplifier at the bottom-right of the circuit. It is used to pick up sounds in the target area during an alarm activation. It is directly coupled to the phone line via a Darlington transistor and bridge. The bridge delivers the correct polarity to the circuit, irrespective of the polarity of the phone line and the change in impedance of any of the components connected to the phone line will result in a signal being sent down the line. The output stage of the high-gain amplifier is one of these components and it is biased ON via a 220k resistor. This turns it ON only very slightly, so that the audio signal will drive it correctly. The "load" for the transistor is all the other components connected in series with the transistor and this includes the "holding-in" relay and any isolating transformer at the exchange.
So, we have a two-transistor high-gain amplifier. A 20mV signal from the microphone will produce a 1,000mV signal on the collector of the first transistor and this will be passed to the output transistor.
The amplitude of the waveform across the output transistor is about 2-3v.
The unusual layout of the circuit may be confusing. The pre-amplifier section is powered from the micro while the output transistor is driven from the phone line and the AC signal through the 100n is amplified by the buffer (output) transistor.
The audio amplifier is turned off when the DTMF tone is sent down the line and when a "turn-off tone" is being detected from the receiving party.
5. THE MICROCONTROLLER
The heart of the project is the microcontroller. It is a 18-pin chip with 15 input/output lines and one input-only line (RA5 - pin 4) and one line that is "input and half-output" (RA4 - pin 3). The output lines change from low-to-high-to-low very quickly and each line can deliver a maximum of 25mA.
The program inside the micro determines what happens on each of the lines and the parts around the micro are merely interfacing components. In other words they adapt or modify or amplify a signal to suit the micro or phone line.
The micro never stops "running" and it executes instructions at the rate of one million per second (1 MIPS).
You need to understand PIC language to program the micro and Talking Electronics has produced
PIC Programming pages on the web to help you develop a program.
6. THE PROGRAMMING BUTTONS
The 4 programming buttons are connected to a single line and a button-press is determined by the length of time it takes to discharge the 100n capacitor.
The capacitor is firstly charged by making the line a "high-output" and then turning it into an input and testing it at regular intervals to see when it is low.
We have already calculated how long it should take for the various buttons to discharge the 100n and we look at these intervals. But we don't know if a button has been pressed at exactly the beginning of the discharge cycle or part-way through. This will give a false reading. So we look initially to see if any of the buttons have been pressed and then repeat the cycle knowing the button has already been pressed.
The resistor values have been chosen to give different timing intervals for each button.
INSERTING A PHONE NUMBER
The micro is fully programmed but no phone numbers have been placed in EEPROM.
However we have placed a series of 1's to represent the first phone number and 2's to represent the second phone number.
The first thing you must do is install your own numbers.
ADDING A NEW PHONE NUMBER
1. Press first button (1st Phone No) for first phone number or 2nd button (2nd Phone No) for second number.
2. Keep first or second button pressed for 10 seconds. The first or second phone number will appear on the 7-segment display and then the bottom, middle, top segments will illuminate to show the number has been erased. You will now see the lower segment illuminated.
3. Use the Incr Digit button to scroll though the numbers.
4. Press Store when appropriate digit shows on 7-segment display.
5. When all the digits of the phone number have been inserted, turn the project OFF. Turn on again.
VIEWING NEW NUMBER
1. Press first button for half-second for (1st Phone No) for first phone number or press 2nd button for half-second for (2nd Phone No) for second number. Pressing longer than 5 seconds will erase the number.
CHANGING A NUMBER
1. Press first button (1st Phone No) for first phone number to be changed or press 2nd button (2nd Phone No) for second number.
2. Keep first or second button pressed for 10 seconds. The first or second phone number will appear on the 7-segment display and then the bottom, middle, top segments will illuminate to show the number has been erased. You will now see the lower segment illuminated.
3. Use the Incr Digit button to scroll though the numbers.
4. Press Store when correct digit shows on 7-segment display.
5. When all the digits of the phone number have been inserted, turn the project OFF. Turn on again.
Note:
If the display shows "junk" or dashes when button 1 or 2 is pressed, press 1st or 2nd button for 10 seconds to clear the display. You will now be in "programming mode" and can insert new phone number. Turn project off when finished and turn it on. Dial Alarm-2 is now "armed."
Dial Alarm-2 does not have a delete or cancel button when in the programming mode.
If you make a mistake when adding a new phone number, turn the project OFF and ON. Push 1st or 2nd button for 10 seconds to get into programming mode and go to the instructions: Adding A New Phone Number, above.
THE PHONE VOLTAGE
Before designing any project for operation on the phone line, you have to understand how the 50v line operates. It's not like a normal 50v power supply. You cannot simply design something for 50v on your bench power-supply and connect it to the phone line.
The phone line is a 50v battery (actually slightly higher than 50v - about 52v - however some of the newer phone systems deliver a voltage as low as 35v - 40v) with a 1k relay in series with one line. When you short the two phone lines together, the relay pulls in to indicate the handset has been lifted. Under these circumstances the current flowing through the line will be 50/1,000 = 50mA. The relay will drop out at 15mA and so you can add devices to the phone line until the current falls to about 15mA without the line dropping out. It is best to keep the current high to prevent the line dropping out.
Most phones drop about 8 - 12v across them when they are working and this voltage can be used by the phone for the amplifying circuits, tone generators etc. Our design has a separate supply, however it could be designed to use the phone voltage, if you wish. The 8v-10v across the audio output transistor gives it plenty of voltage for a good waveform. The audio is sensitive enough to hear a clock ticking in the target area.
The 10v is produced by the 560R resistor plus the effective resistance of the audio output transistor that has been turned on slightly via the 220k base-bias resistor.
The DTMF transistor is also turned on and this provides a load that has an effect on producing the 8-10v we need to keep the line "active."
The 10v is produced by the 560R resistor plus the effective resistance of the audio output transistor that has been turned on slightly via the 220k base-bias resistor.
The DTMF transistor is also turned on and this provides a load that has an effect on producing the 8-10v we need to keep the line "active."
BUILDING THE PROJECT
All the components fit onto a PC board labelled Dial Alarm-2. The placement of each component is clearly shown by the overlay on the board and the only component requiring careful attention is the bridge.
The bridge has positive (+) and negative (-) marked on the top of the device as well as AC inputs indicated by squiggle lines. Here is the original prototype. It has been designed with exactly the same layout as the PC board (shown below) to make it easy to design the board and prevent any mistakes. This is one of the secrets of "getting things right."
All the components fit onto a PC board labelled Dial Alarm-2. The placement of each component is clearly shown by the overlay on the board and the only component requiring careful attention is the bridge.
The bridge has positive (+) and negative (-) marked on the top of the device as well as AC inputs indicated by squiggle lines. Here is the original prototype. It has been designed with exactly the same layout as the PC board (shown below) to make it easy to design the board and prevent any mistakes. This is one of the secrets of "getting things right."
Dial Alarm-2 built on matrix board - the kit comes with PC board (shown below)
Button details
PC board for Dial Alarm-2
The outside case of the electret microphone must go to the negative rail. The microphone can be fitted to a short length of twin lead or fine screened microphones lead (as supplied in the kit) so it can be positioned near the audio you wish to detect.
Solder the 8-pin IC socket for the microcontroller to the board so that the cut-out, covers the cut-out on the board. This way the chip will always be fitted around the correct way.
The 4-core telephone cable comes with 4-pin plugs crimped on each end. A 4-pin modular telephone socket is soldered to the board.
| |
|
TESTING THE PROJECT
The project is tested either on a 50v line or the Test Circuit shown in the diagram below. The supply is three 9v batteries.
The project is tested either on a 50v line or the Test Circuit shown in the diagram below. The supply is three 9v batteries.
It does not matter which way around the phone or Dial Alarm-2is connected as both have a diode bridge to accept either polarity. When the mercury switch is activated, the alarm sends a Hee Haw tone down the line and this is detected by listening to the line via another telephone connected in series with the Dial Alarm-2 project, as shown in the diagram above. The audio from the room is then sent down the line. After 15 seconds the Hee Haw is produced again over the audio and this is repeated at a further 15 seconds. The project then closes down, waits a few seconds then dials the second number and repeats the operation. The two numbers are dialled again and the Alarm closes down.
You can repeat the sequence in the Test Circuit and during the listening period, push any of the buttons on the phone to send a DTMF tone down the line.
The project will close down.
If the input of the alarm is connected to a reed or mercury switch on a door, the door will have to be closed again to produce another trigger pulse.
You can repeat the sequence in the Test Circuit and during the listening period, push any of the buttons on the phone to send a DTMF tone down the line.
The project will close down.
If the input of the alarm is connected to a reed or mercury switch on a door, the door will have to be closed again to produce another trigger pulse.
IF THE PROJECT DOESN'T WORK
If the project doesn't work you will have to go to one of the following sections:
1. The turn-on circuit.
The project turns ON when a trigger pulse is detected on RA5 or RA7. RA5 detects a LOW and RA7 detects a HIGH. Make sure the project is in "Active" mode by pressing button 1 and viewing the 1st phone number.
Make sure RA5 is HIGH when the project is in active-mode and RA7 is LOW. The trigger pulse will be very brief.
2. The tone detector amplifier
The operation of the Tone Detector circuit is very clever. The quiescent conditions are set by the two 100k biasing resistors. This puts the base of the first transistor at mid rail.
The emitter will be slightly less than this and the first transistor will be turned ON and the second transistor will be OFF.
When a signal is delivered to the first transistor, some part of the waveform will turn the transistor OFF and the emitter will drop just like an emitter-follower. The base of the second transistor will remain fixed by the 10u and when the first transistor turns off, the current though the lower 10k resistor will reduce and the voltage across this resistor will reduce. This means the base-emitter voltage of the second transistor will increase. This will turn on the second transistor and it will discharge the 1u. The 1u will discharge faster than it can charge via the 10k resistor and this will result in a LOW and be detected by the micro.
This means the signal actually passes through the stage via the emitters and not via the base of the second transistor. This circuit is a form of Schmitt Trigger. The voltage across the 1u is very easy to detect via a multimeter.
3. The DTMF Section.
The quickest way to determine if this section is working is to pick up the phone and activate the alarm, by tilting the mercury switch.
You will hear the DTMF tone being sent down the line if you have the project on a test-rig."
If these tones are not heard, you can produce a constant DTMF tone for say "0" by inserting the following instructions into the program:
Replace the last instruction for the sub-routine DTMF with: goto DTMF The first data-byte in EEPROM must be 3fh. Make sure they are removed after the testing is complete.
Placing a piezo between pin 17 and ground will allow you to hear one of the tones and between pin 18 and ground, the other tone.
The tones will be produced continuously and you can view them on a CRO and observe their wave-shape entering the phone line.
4. The High-Gain Audio Amplifier
The audio amplifier consists of two stages. The pre-amplifier (the low-signal stage) and the buffer stage (output stage).
The pre-amplifier section consists of a standard common-emitter amplifier with AC coupling (capacitor coupling) to the microphone.
You will need either a CRO or an audio tracer to listen to or observe the signal from the microphone through to the output transistor.
Our circuit had a gain of 50, with a 20mV signal (whistle) from the microphone producing 1,000mV (1v) signal into the base of the pre-amplifier stage. The output transistor amplifies this to produce a signal of about 3v on the phone line. You will need a CRO to view the waveforms if you think the audio stages are not operating correctly. A dual-trace CRO is best so you can observe the input and output of a particular stage at the same time.
This completes the coverage of all the individual building blocks in the circuit. If a fault still persists, the best way to tackle the problem is to get another electronics person to check the board. It may be a simple mistake such as swapping two components, a solder bridge or dry joint.
As a last resort, you can build another kit and with the second project working, compare the two.
If the project doesn't work you will have to go to one of the following sections:
1. The turn-on circuit.
The project turns ON when a trigger pulse is detected on RA5 or RA7. RA5 detects a LOW and RA7 detects a HIGH. Make sure the project is in "Active" mode by pressing button 1 and viewing the 1st phone number.
Make sure RA5 is HIGH when the project is in active-mode and RA7 is LOW. The trigger pulse will be very brief.
2. The tone detector amplifier
The operation of the Tone Detector circuit is very clever. The quiescent conditions are set by the two 100k biasing resistors. This puts the base of the first transistor at mid rail.
The emitter will be slightly less than this and the first transistor will be turned ON and the second transistor will be OFF.
When a signal is delivered to the first transistor, some part of the waveform will turn the transistor OFF and the emitter will drop just like an emitter-follower. The base of the second transistor will remain fixed by the 10u and when the first transistor turns off, the current though the lower 10k resistor will reduce and the voltage across this resistor will reduce. This means the base-emitter voltage of the second transistor will increase. This will turn on the second transistor and it will discharge the 1u. The 1u will discharge faster than it can charge via the 10k resistor and this will result in a LOW and be detected by the micro.
This means the signal actually passes through the stage via the emitters and not via the base of the second transistor. This circuit is a form of Schmitt Trigger. The voltage across the 1u is very easy to detect via a multimeter.
3. The DTMF Section.
The quickest way to determine if this section is working is to pick up the phone and activate the alarm, by tilting the mercury switch.
You will hear the DTMF tone being sent down the line if you have the project on a test-rig."
If these tones are not heard, you can produce a constant DTMF tone for say "0" by inserting the following instructions into the program:
Replace the last instruction for the sub-routine DTMF with: goto DTMF The first data-byte in EEPROM must be 3fh. Make sure they are removed after the testing is complete.
Placing a piezo between pin 17 and ground will allow you to hear one of the tones and between pin 18 and ground, the other tone.
The tones will be produced continuously and you can view them on a CRO and observe their wave-shape entering the phone line.
4. The High-Gain Audio Amplifier
The audio amplifier consists of two stages. The pre-amplifier (the low-signal stage) and the buffer stage (output stage).
The pre-amplifier section consists of a standard common-emitter amplifier with AC coupling (capacitor coupling) to the microphone.
You will need either a CRO or an audio tracer to listen to or observe the signal from the microphone through to the output transistor.
Our circuit had a gain of 50, with a 20mV signal (whistle) from the microphone producing 1,000mV (1v) signal into the base of the pre-amplifier stage. The output transistor amplifies this to produce a signal of about 3v on the phone line. You will need a CRO to view the waveforms if you think the audio stages are not operating correctly. A dual-trace CRO is best so you can observe the input and output of a particular stage at the same time.
This completes the coverage of all the individual building blocks in the circuit. If a fault still persists, the best way to tackle the problem is to get another electronics person to check the board. It may be a simple mistake such as swapping two components, a solder bridge or dry joint.
As a last resort, you can build another kit and with the second project working, compare the two.
THE PROGRAMThe program presented in this article has reduced features. The full version comes with the kit. This version only dials one number and does not detect a whistle to turn off. A PIC16F628A containing the full program is available for $15.00 plus $5.00 post - if you want to provide your own parts and PC board. A full kit is available by emailing Colin Mitchell.
However this program will provide a lot of features for experimenting.
The program does not follow the conventional line of looping Main and calling sub-routines. This program loops Main and goes to a sub-routine, depending on the result of a button press or trigger. From the sub-routine the micro goes to another sub-routine, depending on 1st number or 2nd number requirement and will go to a loop, requiring the project to be turned off. Refer to the following diagram to see how the micro advances through the various sub-routines. If a trigger pulse is detected, the micro will advance down Main and dial the two numbers (twice) and produce Hee Haw and listen for a tone to turn off. At the end, the project will return to "active state," waiting for another trigger pulse.
Here is the file for Dial Alarm-2, in 4 different forms. The program is a reduced version for experimenting. Full version is supplied in the Dial Alarm-2 kit.
DialAlarm2-1No.asm
DialAlarm2-1No.hex
DialAlarm2-1NoAsm.txt
DialAlarm2-1NoHex.txt
However this program will provide a lot of features for experimenting.
The program does not follow the conventional line of looping Main and calling sub-routines. This program loops Main and goes to a sub-routine, depending on the result of a button press or trigger. From the sub-routine the micro goes to another sub-routine, depending on 1st number or 2nd number requirement and will go to a loop, requiring the project to be turned off. Refer to the following diagram to see how the micro advances through the various sub-routines. If a trigger pulse is detected, the micro will advance down Main and dial the two numbers (twice) and produce Hee Haw and listen for a tone to turn off. At the end, the project will return to "active state," waiting for another trigger pulse.
Here is the file for Dial Alarm-2, in 4 different forms. The program is a reduced version for experimenting. Full version is supplied in the Dial Alarm-2 kit.
DialAlarm2-1No.asm
DialAlarm2-1No.hex
DialAlarm2-1NoAsm.txt
DialAlarm2-1NoHex.txt
;**************************************************************** ; Started 15/8/2009 Reduced version 6-10-2009 ; DIAL ALARM-2 with Hee Haw ;This is a reduced version of the program. ; It does not dial the second number and does not turn off ; via whistle or DTMF. It only detects a LOW trigger input on RA5. ;A PIC16F628A containing the full program is available for $15.00 plus $5.00 post, if you ; want to provide your own parts and PC board. A full kit is available by emailing Colin Mitchell. ; ;Port B drives 7 segment display ; ;Project comes on with a number for first and second phone number. ;To clear fist phone number, push "First Phone Number for 10 secs ; "_" will appear 16 times then "_" "-" "-" This indicates number erased ;and "incr digit" will work for first phone number. Store each number ;and switch project off when finished. New number will now be available ;for dialling. If fist number is "_" you must hold first sw for 10 secs to ;get into "Incr digit" to produce first number via incr Digit and Store. ; ;**************************************************************** list P = 16F628 ;microcontroller include |
MODIFYING THE PROGRAM To work on the program, you need to buy a PROGRAMMER (PICkit2 - see above or Multi Chip Programmer) and put the chip on a prototyping board with a 5-pin programming socket so it can be "burnt." The connections for the Programming Socket are shown on the Dial Alarm-2 circuit above.
The next thing you will need is the .asm file and open it in NotePad2. Notepad2 is called a text editor and it will display the code in columns so that each line can be assembled in MPASM to create a .hex file. Call your program by a different name so that you can identify your changes.
MPASM will also produce a .lst file that shows any mistakes you have made. When your program is mistake-free, MPASM will produce a .hex file.
Download MPASM (v02.70), click: MPASM. The latest version of MPASM is very messy. Use the one we provide.
You will also need a text program such as TextPad or NotePad
You cannot use the .asm file above for TextPad as it has added spaces. These spaces will upset MPASM when it tries to compile the file to produce a .hex file. If you get an error on a line (from MPASM) that seems to be correct, try re-typing the line(s) as it may contain unseen spaces!
Then use Chip Programmer - PICkit2 or Multi Chip Programmer - to "burn" the program into the chip. The phone numbers are stored in EEPROM and are changed via software when the project is powered. You don't need to "burn" them into the chip.
If the program does not work, you may be told about and Emulator or Single Stepper, that will "solve all your problems." Let's see . . .
USING AN EMULATOR
An Emulator is a single-stepping program that goes though the code, one instruction at a time, so you can see what is happening.
A Single-Stepper program comes on the CD with PICkit-2 and you can use it if you wish. We have found it helpful in some ways as you can see the contents of each register before and after an instruction has been executed and this will let you know why an instruction may not be working. It is most helpful when executing a Boolean instruction as the result has to be worked out on paper and the single-stepper will let you check the result.
Our method of developing a program is slightly different. We suggest using the "cut and paste" method of creating a project.
Start by using one of the projects already available on our website by clicking HERE and removing the unwanted sub-routines. You will then have a layout for the processor, a few equate files, some sub-routines and Main.
Fir the micro to an experimental PC board containing 5 pins for In-Circuit Programming, add a LED and resistor and create a sub-routine that loops and blinks the LED.
You have now started.
Add a few more lines of code and test its operation.
This is exactly how we start every project.
It's wishful thinking to write a large program and expect it to "run." It possibly won't. Just add a few lines at a time and check the operation.
For the Dial Alarm-2 project, we tested each section separately and this consisted of more than 7 different blocks.
Not only do you have to get the electronics to work but you also need to get the program to interface to the block.
This is where an Emulator or Single-Stepper falls down. It cannot detect if the electronics section is working and responding to the code.
For instance it cannot detect switch-bounce or if the 7-segment display is showing the correct segments.
Secondly, delays take a long while to execute and either the emulator skips over them or takes a long time to execute.
I have used a single-stepper and emulator for the PIC and these are some of the problems it did not solve.
By far the best method is MINE. It's simple and it works every time. It's back to basics.
If you are having trouble detecting if the micro is advancing though a sub-routine correctly, add an instruction that takes the micro to a small routine that outputs a tone to a piezo diaphragm or blinks a LED.
Put a GOTO instruction, say before a CALL instruction. If the LED blinks, the micro has reached the instruction. Then put the GOTO after the CALL. If the LED does not blink, the micro has not come out of the sub-routine. It may be stuck in the sub-routine or jumped to another address. Go to the sub-routine and work your way through each line with the GOTO concept.
It may be time-consuming but it is the only real way to follow the actual progress of the microcontroller. This approach was used to solve a problem with the original tone routine in the Alarm. The investigation solved the problem and also showed the sub-routine was not well-designed. A much simpler routine was put in its place. So, the hands-on approach solved two things at the same time.
A CRO was also used initially to check the quality of the DTMF waveform. It appeared to be perfect on the screen but was only being accepted by the exchange 80% of the time. By changing the wave-shaping components, the acceptance rose to 100%. The difference between the two waveforms could not be seen on the CRO, but a 8870 DTMF tone detector detected the difference. This is another case of going back to basics and using your knowledge of electronics to improve the quality of a waveform.
The point I am making is this . . .
All the tools of assistance for getting a project up-and-running have been provided in the articles on Talking Electronics website. The only test equipment you need is a multimeter (either analogue or digital) and a Logic Probe. Don't dream: "If only I had an emulator!" or "If only I had a CRO." You can do it all with basics and that is what the Talking Electronics PIC course is all about. Building this project and some of our other projects will show you how things go together, so you can design your own projects.
As I said above, one of the biggest problems is working out the correct order for testing a project. Things have to be done in the correct order and this quite often requires stripping the project down to the simplest circuit. In our case the first section to work on was the DTMF tones. Once these were 100% accepted by the exchange, the turn-on circuit and opto-coupler sections could be added. Then the audio amplifier had to be placed in parallel with the DTMF section without affecting the quality of the waveform of either the tones or the audio. This was quite a challenge and even though the final circuitry is simple, a lot of testing had to be done to make sure other designs were not better. The DTMF circuit was loaded with capacitors and resistors to see if the tone was still recognised by the exchange. This way you know you have a margin-of-error and any tolerances generated in the building of the project will not affect the outcome.
As each problem was solved, the project got nearer completion. By working with basics, the feeling is the project is advancing.
With the Dialling Alarm, there were more than 10 things to sort out.
Producing digits on the 7-segment display
Detecting 4 buttons
Reading and writing to EEPROM
The DTMF tone - duration, amplitude, clarity, getting 100% acceptance on the line,
The Darlington transistor
The audio amplifier, reducing hum, reducing motor-boating, improving output amplitude, gating.
The tone detecting circuit - detecting a tone but not detecting noise or talking
None of these would have been helped with an emulator or CRO. There is too much circuitry interdependence and the big problem with a CRO is the introduction of hum when the earth clip is connected to the project.
If there is any magic package or device that speeds up the process of development, I will let you know.
The next thing you will need is the .asm file and open it in NotePad2. Notepad2 is called a text editor and it will display the code in columns so that each line can be assembled in MPASM to create a .hex file. Call your program by a different name so that you can identify your changes.
MPASM will also produce a .lst file that shows any mistakes you have made. When your program is mistake-free, MPASM will produce a .hex file.
Download MPASM (v02.70), click: MPASM. The latest version of MPASM is very messy. Use the one we provide.
You will also need a text program such as TextPad or NotePad
You cannot use the .asm file above for TextPad as it has added spaces. These spaces will upset MPASM when it tries to compile the file to produce a .hex file. If you get an error on a line (from MPASM) that seems to be correct, try re-typing the line(s) as it may contain unseen spaces!
Then use Chip Programmer - PICkit2 or Multi Chip Programmer - to "burn" the program into the chip. The phone numbers are stored in EEPROM and are changed via software when the project is powered. You don't need to "burn" them into the chip.
If the program does not work, you may be told about and Emulator or Single Stepper, that will "solve all your problems." Let's see . . .
USING AN EMULATOR
An Emulator is a single-stepping program that goes though the code, one instruction at a time, so you can see what is happening.
A Single-Stepper program comes on the CD with PICkit-2 and you can use it if you wish. We have found it helpful in some ways as you can see the contents of each register before and after an instruction has been executed and this will let you know why an instruction may not be working. It is most helpful when executing a Boolean instruction as the result has to be worked out on paper and the single-stepper will let you check the result.
Our method of developing a program is slightly different. We suggest using the "cut and paste" method of creating a project.
Start by using one of the projects already available on our website by clicking HERE and removing the unwanted sub-routines. You will then have a layout for the processor, a few equate files, some sub-routines and Main.
Fir the micro to an experimental PC board containing 5 pins for In-Circuit Programming, add a LED and resistor and create a sub-routine that loops and blinks the LED.
You have now started.
Add a few more lines of code and test its operation.
This is exactly how we start every project.
It's wishful thinking to write a large program and expect it to "run." It possibly won't. Just add a few lines at a time and check the operation.
For the Dial Alarm-2 project, we tested each section separately and this consisted of more than 7 different blocks.
Not only do you have to get the electronics to work but you also need to get the program to interface to the block.
This is where an Emulator or Single-Stepper falls down. It cannot detect if the electronics section is working and responding to the code.
For instance it cannot detect switch-bounce or if the 7-segment display is showing the correct segments.
Secondly, delays take a long while to execute and either the emulator skips over them or takes a long time to execute.
I have used a single-stepper and emulator for the PIC and these are some of the problems it did not solve.
By far the best method is MINE. It's simple and it works every time. It's back to basics.
If you are having trouble detecting if the micro is advancing though a sub-routine correctly, add an instruction that takes the micro to a small routine that outputs a tone to a piezo diaphragm or blinks a LED.
Put a GOTO instruction, say before a CALL instruction. If the LED blinks, the micro has reached the instruction. Then put the GOTO after the CALL. If the LED does not blink, the micro has not come out of the sub-routine. It may be stuck in the sub-routine or jumped to another address. Go to the sub-routine and work your way through each line with the GOTO concept.
It may be time-consuming but it is the only real way to follow the actual progress of the microcontroller. This approach was used to solve a problem with the original tone routine in the Alarm. The investigation solved the problem and also showed the sub-routine was not well-designed. A much simpler routine was put in its place. So, the hands-on approach solved two things at the same time.
A CRO was also used initially to check the quality of the DTMF waveform. It appeared to be perfect on the screen but was only being accepted by the exchange 80% of the time. By changing the wave-shaping components, the acceptance rose to 100%. The difference between the two waveforms could not be seen on the CRO, but a 8870 DTMF tone detector detected the difference. This is another case of going back to basics and using your knowledge of electronics to improve the quality of a waveform.
The point I am making is this . . .
All the tools of assistance for getting a project up-and-running have been provided in the articles on Talking Electronics website. The only test equipment you need is a multimeter (either analogue or digital) and a Logic Probe. Don't dream: "If only I had an emulator!" or "If only I had a CRO." You can do it all with basics and that is what the Talking Electronics PIC course is all about. Building this project and some of our other projects will show you how things go together, so you can design your own projects.
As I said above, one of the biggest problems is working out the correct order for testing a project. Things have to be done in the correct order and this quite often requires stripping the project down to the simplest circuit. In our case the first section to work on was the DTMF tones. Once these were 100% accepted by the exchange, the turn-on circuit and opto-coupler sections could be added. Then the audio amplifier had to be placed in parallel with the DTMF section without affecting the quality of the waveform of either the tones or the audio. This was quite a challenge and even though the final circuitry is simple, a lot of testing had to be done to make sure other designs were not better. The DTMF circuit was loaded with capacitors and resistors to see if the tone was still recognised by the exchange. This way you know you have a margin-of-error and any tolerances generated in the building of the project will not affect the outcome.
As each problem was solved, the project got nearer completion. By working with basics, the feeling is the project is advancing.
With the Dialling Alarm, there were more than 10 things to sort out.
Producing digits on the 7-segment display
Detecting 4 buttons
Reading and writing to EEPROM
The DTMF tone - duration, amplitude, clarity, getting 100% acceptance on the line,
The Darlington transistor
The audio amplifier, reducing hum, reducing motor-boating, improving output amplitude, gating.
The tone detecting circuit - detecting a tone but not detecting noise or talking
None of these would have been helped with an emulator or CRO. There is too much circuitry interdependence and the big problem with a CRO is the introduction of hum when the earth clip is connected to the project.
If there is any magic package or device that speeds up the process of development, I will let you know.
By adding some instructions to output to a display, you can see if the micro is going past the code you are having trouble with.
We also suggest creating your program by using sub-routines from other projects that are known to work correctly.
There is only one problem with an Emulator or Single-Stepper. They are nice, but relying on them is a crutch. You tend to think they will solve your problems.
This is a dangerous misconception because, in most cases the final solution will be to go back to basics. They can be of assistance, but I am going to show the real way to problem-solving is using "tricks-of-the-trade."
The big problem with an emulator is INPUTS. If you have a push button in a circuit, the emulator does not carry out the operation of the push button.
The way to learn programming is to go through a project that has been written by some one else and study each line of code. You need to know two things. Firstly you need to know what each instruction is doing and then you need to know why the instruction has been used. In the Dial Alarm-2 program we have used a very simple format called linear programming.
The sub-routines are long and very few calls are made. In addition we have used very few Boolean commands and the simplest way to convert from a display value to a numerical equivalent.
The sub-routines are long and very few calls are made. In addition we have used very few Boolean commands and the simplest way to convert from a display value to a numerical equivalent.
Không có nhận xét nào:
Đăng nhận xét