Talking Electronics PIC Theory
                                                    

10 Tricks for the '508A

Tricks to expand the lines of the '508A  - plus a number of other things. 


Most of the ideas in this chapter can be found on the pages of this website, but just in case you want to go over the capabilities of the '508A, we have brought them together. 
Quite often when you are programming, the first thing you will run out of is output lines. Many projects need lots of drive lines and if you need more than about 8, you should go to another micro-controller. 
Don't expect an 8-pin chip to perform the impossible. 
The designers of the '508A have done an amazing job providing 5 output lines (and one input line) in an 8-pin chip, but even so, many projects run out of drive-lines. 
On other pages of this course we have shown how to expand the drive lines with a binary counter or shift register. This can increase the lines to more than 10 however if you want to add just one or two more devices than the chip is directly capable of handling (5), there are clever ways to connect them to the chip. 

1. LED AND PIEZO ON ONE LINE
One of the simplest combinations is a LED and Piezo on a single drive-line as shown in fig: 1. These can be combined because the requirements of a LED are different to a piezo. A LED requires a constant HIGH for it to illuminate while a piezo requires a HIGH-LOW-HIGH waveform at approx 3kHz to produce a tone. 

If the mark-space ratio of this waveform is kept short as shown in fig: 2, the LED will only illuminate very dimly. A short mark-space ratio means the "mark" is very small compared to the "space". A very 
short on-time (mark) and a long off-time (space) will not affect the tone from the piezo but will deliver very little energy to the LED and this is exactly what we want. 

On the other hand, each time the LED is activated, only a very small click will be heard, and this will hardly be noticeable. In this way the two devices can be combined on the same line. 

2. LED AND PUSH BUTTON ON ONE LINE
In this book, we show how to connect two and up to five or more push buttons on a single input line and generally you will not have any problems adding buttons to a project. But if you want to add a secret reset button (or a "cheat" button, for example), it can be added across an existing LED as shown in fig: 3. 

The resistor between the switch and micro acts as a safety resistor to prevent the output of the chip being damaged if the switch is pressed when the LED is activated, and it also acts as a dropper resistor for the LED. 
These two items will work in combination because the impedance of the LED is very high when no voltage is across it and when the micro turns the line into an input line, it sees the LED as a high impedance. In other words it is not detected so that when the switch is pressed the micro only sees the switch as a LOW. 

3. DIFFERENT PROGRAMS IN THE CHIP
Up to 5 different programs can be burnt into a single '508A and the required program can be accessed by soldering a resistor between one of the outputs and the "input-only" line - GP3, as shown in fig: 4. 
During turn-on, a special program will put a HIGH on each output in turn and the output containing the resistor will determine the program.

Combining 5 programs in one chip will reduce inventory costs as the required program can be selected by fitting the resistor in the appropriate place on the board.

4. LINE REVERSAL
If a device is connected between two output lines as shown in fig: 5, a program can be written so that the device sees a voltage reversal. When one output is HIGH the other is LOW and this is then reversed. 

The drive lines have a maximum output current of 25mA and this is enough to drive a number of different devices. If a red LED is connected in one direction and a green LED in the opposite direction, they can be turned on and off individually, as shown in fig: 6. 

If the two LEDs are placed near each other or combined in the one LED (called a tri-coloured LED), they will produce a number of colours including orange, depending on the mark-space waveform delivered to each LED.
A single LED containing red and green chips is available in 2 or 3 lead versions. The wiring for a 3-leaded tri-colour LED is shown in fig: 7. The tri-leaded version is shown in fig: 6. 

Tri-coloured LEDs are fairly expensive but if the project can cover the expense, they can be the basis of "running message" displays and simple TV screens. 
If you connect a piezo to two out-of-phase lines as shown in fig: 8b, the sound produced will be slightly louder than the arrangement in fig: 8a. 

When we talk about a piezo we really mean a PIEZO DIAPHRAGM. A piezo diaphragm is a passive device and is very similar to a capacitor as far as the circuit is concerned. Ceramic substrate on a metal diaphragm causes the metal to "dish" and bend to produce a high pitched sound. The size of the voltage (the amplitude) determines the intensity of the sound and the frequency of the waveform determines the tone.
The voltage across the piezo from one drive line is about 5v whereas the voltage seen by the piezo from two reversing lines is about 10v. Unfortunately this doesn't produce twice the sound output but the 
sound is slightly louder. If you want a louder output you should use a better-quality high-output diaphragm (such as from a Christmas card). 
The loudest output is a piezo siren and this is an active device containing a transistor oscillator and choke. These units operate from 5v to 15v and produce a very loud output while consuming only about 10mA to 15mA.

5. DRIVING LEDs
Each output line of a '508A can only deliver about 25mA. This current is determined by the size of the transistor delivering the current. The transistor inside the chip is only very tiny and if a higher current 
is drawn, it may be damaged. 

When a resistance of 200 ohms is connected from output to ground, a current of 25mA flows (when the output is HIGH). If the resistance is reduced, a higher current flows. This means a resistance of 200 
ohms or higher is required to make sure the current flow is less than 25mA. 
But if a LED is placed on the output, how is the resistance worked out?
A LED drops a voltage across it according to its colour. This is called the CHARACTERISTIC voltage or the CHARACTERISTIC VOLTAGE DROP. This voltage is constant, no matter how bright the LED is illuminated. 
For a red LED the characteristic voltage is 1.7v. 
For an orange LED the characteristic voltage is 1.9v. 
For a green LED the characteristic voltage is 2.1v. 
LEDs cannot be connected directly to the output of a drive-line without a voltage-dropping resistor. The reason is very technical but basically a red LED does not turn on AT ALL until exactly 1.7v is placed across it and if the voltage tries to rise above 1.7v, the LED will glow brighter, allow a very high current to flow and will be damaged. 
The only way to prevent damaging the LED is to provide it with a very accurate supply voltage or simply connect a resistor in series. If the value of the resistance is worked out, an accurate current can 
be delivered to the LED and everything will be ok. The LED will last 100 years! 
Suppose you want to deliver 25mA to a LED. 
If we take a red LED, the value of resistance can be worked out by Ohms law. The voltage across the resistor is: 5v - 1.7v = 3.3v 
I = V/R 
0.025 = 3.3/R
R = 132 ohms Use 130R resistor.

6. DRIVING LEDs IN PARALLEL AND SERIES
If a number of LEDs are required to be driven from a single output, you will need to connect them in parallel or series. There are limitations, however, as you will see. 
Firstly it is ok to connect two LEDs in series, provided you work out the value of the dropper resistor.
If a single red LED is connected to an output and supplied with 25mA via a 130 ohm resistor, when two LEDs are connected in series, the second LED will drop 1.7v and the supply voltage will be 5v - 3.4v 
= 1.6v. In this case the two LEDs will receive a current of 12mA from the 130 ohm resistor and they may be a lot duller than expected. 
To supply them with 25mA, the dropper resistor must be:
R = V/I
= 1.6/0.025
= 64 ohms
Use 68R resistor as shown in fig: 10. 

If three LEDs are connected in series, the total characteristic voltage drop will be 1.7v + 1.7v + 1.7v = 5.1v This is higher than the maximum voltage on the output line and in theory, the LEDs will not illuminate AT ALL, no matter what dropper resistor is used! 
This means only two LEDs can be connected in series to an output line. 
LEDs can be connected in parallel AND series as shown in fig: 11. Four LEDs is the maximum that can be driven from a single output line and this will deliver about 12mA to each LED. 

You will notice a separate dropper resistor is required for each column of LEDs because LEDs cannot be operated in parallel due to the 1.7v characteristic voltage required across each for perfect operation. 
For example: one LED may have a characteristic of 1.75v and another may have 1.65v characteristic. The 1.65v LED will rob the other of voltage and prevent it operating. More on this in our Notebook series.

7. DRIVING MORE THAN 4 LEDs
If more than 4 LEDs are required to be driven, a buffer transistor will be required as shown in fig: 12. This transistor will allow the LEDs to be driven from a 12v supply (or higher) and the number of 
LEDs can be increased to 6 per column for 12v. 

If the transistor can handle 100mA, four columns can be made, allowing 24 LEDs to be illuminated. 
In this way segments of a large pattern can be illuminated and by referring to some of the projects we have included, the lines of the '508A can be expanded to twelve or more and an impressive display can be created. 

8. CONNECTING A GLOBE
A globe is a device that requires a very high start-up current. This is something you may not be aware of. The start-up or warm-up current for a globe is about 6 times its operating current and although this 
current is drawn for only a very short period of time, it is one of the reasons why a globe does not work in some circuits. The high start-up current prevented one of our flip-flop circuits working. The resistance of the leads from the project to the battery was sufficient to prevent the circuit starting-up. That's why it is important to remember everything we discuss.
To drive a globe from an output of the microcontroller, a buffer transistor is needed. 
Any type of transistor will be suitable providing its current handling ability is about 600mA for each 100mA of operating current for the globe. A suitable drive circuit is shown in fig: 13. 

The globe can be dimmed by delivering a variable mark-space waveform. Fig:2 shows the type of waveform with the on-time represented by the "mark" portion of the waveform. 

9. CONNECTING A RELAY
Most relays require more than 25mA for operation and need a 12v supply. 
For this a buffer transistor is required. Fig: 14 shows how a relay is connected to an output of the '508A. The diode across the relay prevents voltage from the relay getting into any of the supply lines and affecting the operation of the microprocessor. 

When the relay is turned off (de-energised) the collapsing magnetic field of the coil generates a very high voltage and this can be passed to the supply rail if it is not "snubbed." The diode absorbs (snubs) 
this voltage. 

10. CREATING SECURITY WIRING FOR AN ALARM 
When designing an alarm project, the wiring between the sensors and the control panel must not be able to be cut otherwise the alarm system is useless!
Making the wiring FULLY SECURE is very complex but a simple way to prevent the wires being cut or joined together (without detection) involves a line-sensing feature called LINE REVERSAL. 
Most alarms consist of pin switches or reed switches with the windows and doors physically keeping the switch closed or having a magnet to keep the contacts of a reed-switch closed. If the door or window is opened, the circuit becomes open and the alarm is activated.
This is called a CLOSED LOOP detection circuit.
It's very easy to see that if the two wires going to the alarm panel are joined together near the alarm panel, the alarm will not activate when a window or door is opened. 
To overcome this problem a diode is placed in the line near one of the sensors as shown in fig: 15. 

The alarm is required to send out a HIGH on one line and detect the high on the other line. The alarm then sends out a HIGH on the other line and since the diode is reverse biased for this condition, the 
alarm must sense a low on the first line. 
This "line testing" is done many times per second and if the line is shorted, the program will detect the interference. The only limitation to this system is the micro will not detect a diode fitted across the two lines near the alarm panel. The thief has to know of this limitation and the diode has to be fitted around the correct way to defeat the system. 
How many thieves carry a diode with them and know how to fit it?

11. CONNECTING A MOTOR
In theory you can connect a motor to two drive-lines and get forward and reverse operation. 
But unfortunately a motor requires a very high start-up current and the drive lines of a '508A are not capable of delivering this current. The solution is to use transistor buffers in the bridge arrangement 
of fig: 16. 

Lines A and B are two outputs from a '508A. There is an important point to remember when programming the output lines to prevent a short-circuit occurring with the bridge.
You will notice that if both A and B are HIGH at the same time, transistors L, M and X, Y will be turned on at the same time and a short-circuit will occur on the power rail. 
To prevent this from happening lines A and B must be LOW at the beginning of the program. 
By taking line A HIGH, transistors M and X are turned on and this delivers voltage to the motor to turn it in the clockwise direction. 
To control the RPM of the motor, line A can be given a variable mark-space ratio.
To reverse the motor, line A must be taken low and after a short delay, line B can be taken HIGH. This will deliver voltage to the motor via transistors Y and L and cause the motor to revolve in the opposite 
direction. Reverse RPM can be adjusted with a variable mark-space pulse. 


Previous  PageHome PageNext Page

Prepared by Colin Mitchell   1 - 1 - 2001