Adding extra
Inputs and Outputs
Page 12
INDEX
There are many ways to design a project using the PIC LAB-1.
Here are three:
1. Design a project around the inputs and
outputs of the PIC LAB-1.
2. Write a program for the PIC LAB-1 and include instructions
for additional inputs, such as switches. Connect the switches to the underside
of the board and test everything before making a prototype.
3. Use the PIC LAB-1 as a module and connect it to a
"base-board" containing the remainder of the circuitry - such as
relays, driver transistors etc - like a "plug-in" or
"add-on" module.
The actual layout you chose is up to you.
In this chapter we will cover the circuitry required to add inputs and
outputs.
Up to 13 inputs and 13 outputs can be created with a PIC16F84, so the potential
is enormous. We will only be showing a small part of the
capability.
The four features we will cover are:
1. Creating an input.
2. Creating an output with Low, Medium and HIGH driving capability.
3. Creating an input and output on a single line.
4. Creating two separate inputs on a single line.
With all devices connected to the microcontroller, you have to remember one
thing. The output is only capable of delivering 20mA and if it delivers more
current than this, it will be damaged.
That's why it is very important to prevent devices such as switches causing a
short-circuit. A switch can very easily create a short. If a switch-line
is made an output and is LOW while the switch is pressed, damage will
occur. That's why you need to look at a design before damage
occurs.
CREATING AN INPUT
An input line is created by simply writing a few instructions in a program.
These instructions are placed in SetUp.
For example, to make the lowest line of Port A, an INPUT, the following instructions
are needed. These must be placed inside
BSF 03,5 and
BCF 03,5.
|
BSF 03,5
MOVLW 01
MOVWF 05
BCF 03,5
|
;Go to Bank 1
;Load W with 0000 0001
;Make RA0 input
;Go to Bank 0 - the program memory area.
|
|
The input line
(pin 17) will then detect a HIGH or LOW.
The amplitude of the HIGH must be as large as possible and can be about 500mV
lower than rail voltage. The low must be as small as possible and can be about
500mV. If the input voltage does not reach these excursions, a definite
HIGH or LOW may not be detected.
The input to the micro is high-impedance and very little current is required
to register a HIGH or LOW. That's all you need to know.
Micro input line
If the input voltage is present for a long period of time (in microcontroller
terms), there will be no problem detecting the signal.
But if it is only present for a short period of time, or of insufficient amplitude,
an amplifier or pulse-stretcher will be required.
If the signal is a tone, a clever program can be produced to create a
varying-width window. This will prevent the signal synchronising with the
window and not being detected.
Audio
Audio2
Audio3
Audio4 |
CLRF
13h
MOVLW 0A0h
MOVWF 1A
MOVF 1A,0
MOVWF 1B
DECFSZ 1B,1
GOTO Audio3
BTFSS 05,1
GOTO Audio4
INCFSZ 1A,1
GOTO Audio2
RETURN
INCF 13h
GOTO Audio2 |
;File
13h counts audio "lows"
;Create 50h loops! Yes 50h
;Copy 1A to W
;Copy W to 1B
;Look at audio input. Audio = LOW
;Increment file 1A to zero!
|
|
If the
signal is present for a very short period of time, a pulse stretcher will be
needed. This is simply a storage electrolytic placed on the input line to
increase the LOW time. Any value from 100n, 1u to 10u can be used.
If the output from
the device is insufficient to guarantee detection, an amplifier, similar to
the circuit above, will be needed.
Some of the tricks in getting an input device to interface to the micro, will
be in the program. You may need to look at the device a number of times before
making a decision. This will be mainly to remove background noise or incorrect
frequencies etc.
CREATING AN OUTPUT
Any of the 13 lines of a PIC16F84 microcontroller can be made an OUTPUT. The
line must be "set-up" (turned into) an output via the following
instructions:
|
BSF 03,5
MOVLW 0FEh
MOVWF 06
BCF 03,5
|
;Go to Bank 1
;Load W with 1111 1110
;Make line RB0 of Port B output
;Go to Bank 0 - the program memory area.
|
|
Any line that is made output can be made HIGH or LOW. To make a
line LOW, the corresponding
bit is "0":
|
MOVLW
00
MOVWF 06
|
;Load
0000 0000 into W
;Make RB0 LOW.
|
|
To make a line HIGH, the corresponding bit is "1":
|
MOVLW
01
MOVWF 06
|
;Load
0000 0001 into W
;Make RB0 HIGH.
|
|
Low Current
OUTPUT
A output from the PIC16F84 micro will deliver up to 20mA. It will also sink
20mA. This is sufficient for LEDs and 7-segment displays. The circuit below
shows LEDs connected to a micro:
If more than 20mA is needed, a buffer transistor can be
added.
Medium Current
OUTPUT
A low-current transistor (meaning a low collector current capability) can be
connected the output of a micro to deliver up to about 1 amp. At about 1 amp,
you can call the transistor a medium-current device.
High Current
OUTPUT
A high-current transistor (meaning a high collector-current capability) can be
connected the output of a micro to deliver currents above 1 amp.
Here is a list of types and their collector current capability:
There is a complex problem with delivering a current above 1
amp. The problem is this:
The output of the micro is 20mA. Any transistor with a collector current above
500mA has a gain of 20-200. To be realistic you should allow a gain of 50.
This means the collector current cannot be above 20 x 50 = 1,000mA =
1amp.
If you require a current higher than 1amp, two transistors will be
needed.
This can be in the form of a single package containing two transistors or
separate devices.
A LITTLE THEORY:
It works like this: For every mA of current delivered to the base, the
transistor will allow 50mA to pass through the collector-emitter
terminals.
What happens?
If you supply 1mA to the base of a transistor, it will deliver 50mA through
the collector-emitter circuit. What happens if you try to pass more than 50mA through the collector-emitter circuit?
We will take this in slow-motion.
Suppose we have a 12v supply rail and a load capable of taking a varying
current.
If the load current starts at 1mA, the transistor is fully turned on and about
11.5v appears across the load.
As the load current increases, the transistor remains fully turned on
and the conditions are as above.
When the current rises to 51mA, the transistor cannot remain fully turned on
and the voltage across it increases and thus the load does not get 11.5v but
11v. This causes the current to drop to 50mA. If the load tries to draw more
current, the voltage between the collector-emitter terminals increases and
thus the current through the circuit remains at a maximum of 50mA.
There are side-effects to this.
As the load tries to take more current, the voltage across the
transistor rises and thus the power lost in the transistor increases and it
heats up.
This may not be a problem with 50mA, but if 500mA is flowing the heat build-up
in the transistor can very soon cause the transistor to fail.
That's why you must not try to take more current than the calculations
allow.
OVER 1-AMP
If you require a current greater than 1 amp, you can use a single device
containing two transistors, called a darlington transistor. The circuit
below shows a darlington transistor connected to an ouptut of a PIC micro.
Individual transistors can be used to deliver currents greater
than 1 amp as shown below:
More
NEXT