This is only a preview of the December 2000 issue of Silicon Chip. You can view 33 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Build A Bright-White LED Torch":
Items relevant to "2-Channel Guitar Preamplifier, Pt.2: Digital Reverb":
Items relevant to "Driving An LCD From The Parallel Port":
Items relevant to "A Morse Clock - Look Mum, No Hands!":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Fun with comparators
This month, we’ll have a play with comparators. Most people
regard comparators as pretty basic and boring devices but
they should be regarded as important building blocks. You can
do all sorts of functions apart from comparators. Examples
are Schmitt triggers, oscillators, timers, pulse generators,
AND and OR gates and even zero voltage crossing detectors.
By LEO SIMPSON
We will have a play with a “bog
standard” device, the LM393 dual
comparator but remember that virtu
ally everything we do will be applica
ble to other comparators such as the
equally “bog standard” LM339 quad
comparator or other higher perfor
mance comparators.
OK. So what is a comparator? It’s
74 Silicon Chip
very similar to an op amp. It has a
differential input stage, with noninverting (+) and inverting (-) inputs.
The two inputs are used to “compare”
two signals or two voltages and then
the output indicates whether one
input is higher (or lower) than the
other. Typically, one input will be
tied to a reference (REF) voltage while
the other input is fed with the signal
or voltage to be monitored. Let’s do
a typical setup with the LM393, as
shown in Fig.1.
BELOW: this photo features all the
parts shown in Fig.1 and Fig.2, except
for the 47µF capacitor. One of the
potentiometers is not used.
Fig.1: this is a basic circuit for a non-inverting comparator.
To turn it into an inverting comparator, swap the inputs,
pins 5 & 6. Pins 2 & 3 on the unused comparator should be
tied high. The 47µF is not used initially.
Because we are wiring this up on
a Protoboard and want to make it as
straightforward as possible, I’ve hook
ed up the second comparator in the
LM393 dual package; ie, involving
pins 5, 6 & 7. But remember that ex
actly the same circuit can be hooked
up with the first comparator, or any
number of variations on the theme.
Since we’re not using the first com
parator, its inputs should be tied high
(+12V) or low (0V). This is done to
prevent it from producing any spuri
ous oscillations which it could do if
its inputs were left to “float”.
Pin 6, the inverting input, is con
nected to the junction of two 10kΩ
resistors connected across the 12V
supply. The voltage at the junction
will be half the supply or +6V (nom
inal) and since this voltage is fixed,
we regard this as the REF (reference)
input. Pin 5, the non-inverting input,
is connected to a variable voltage
obtained from the 50kΩ pot (VR1)
which is connected in series across
the 12V supply. By rotating pot VR1,
we can vary the voltage fed to pin 5
from +12V down to about +2V.
Why not hook up just the 50kΩ pot
and the 10kΩ resistor across the 12V
supply to begin with and check with
your multimeter to see if this voltage
range can be obtained? Check also that
you get 6V (or half the DC plugpack
supply voltage) at the junction of the
two 10kΩ resistors. Now hook up the
rest of the components on the circuit
of Fig.1, as shown in the photo and
in the Protoboard wiring diagram of
Fig.2.
So that we can see what the compar
ator does in response to the variable
signal conditions, I have hooked up
a LED (light emitting diode) in series
with a 1kΩ resistor, between the +12V
supply and the comparator’s output
at pin 7.
Now, if we set VR1 so that +12V is
fed into pin 5, the LED will not light.
If we then wind VR1 back the other
way, reducing the voltage to pin 5,
at some point the LED will light. If
we then measure the voltage at pin
5 we should find that it is just below
the voltage at pin 6. In our case, on
the afternoon I was writing this, the
voltage on pin 6 was +6.18V and as
I wound VR1 to the point where the
LED came on fully, pin 5 was +5.93V
and pin 6 was +5.6V; ie, a smidgin
below pin 5.
This demonstrates a number of
interesting points. The first question
might be, “Why did the voltage at
pin 5 change at all?” but we’ll get to
that later.
No, the main point is that when pin
5, the inverting input, is pulled low,
the output at pin 7 also goes low. And
Fig.2: use this diagram to wire up the circuit of Fig.1. Winding
VR1 back and forth will turn the LED on and off.
December 2000 75
Fig.3: using the simple comparator results in poor
switching behaviour. The upper trace is the input
sinewave at 1kHz while the lower trace is the output
waveform.
when 7 goes low, the LED will light
because it is hooked up to +12V via
the 1kΩ resistor.
So what we have here is a non-in
verting comparator. We can summa
rise its operation by saying that when
the non-inverting input goes above
the inverting input, the output will
go high; when the non-inverting input
goes below the inverting input, the
output will go low.
Inverting comparator
Say we wanted to change the sense
of the comparator? Say, we wanted
the output to go high when the input
goes low – ie, below the reference
input? Easy. Just swap the reference
and signal inputs. Go ahead and do
it: swap the connections to pins 5 &
6. Now what happens? What happens
is that when pin 6 is above pin 5, the
LED is alight. Conversely, when pin 6
is low, the output at pin 7 is high and
so the LED is not alight. So that’s how
you make an inverting comparator.
The thing is, you can tell what
the comparator will do just by look
ing at which input is inverting and
which is non-inverting. If we vary
the non-inverting input, the output
will essentially follow the input; ie,
when it goes above the REF input, the
output will go high as well.
In other words, the output is the
same as the non-inverting input or to
put it another way, the output has not
been inverted (non-inverting, get it?).
Conversely, for an inverting com
parator, the output signal will be
76 Silicon Chip
Fig.4: this is the cleaner switching result when a 47µF
bypass capacitor is connected to pin 6. This stops the
voltage at pin 6 from varying while the switching action
is taking place.
inverted compared to the input.
We can use these basic compara
tor circuits in all sorts of ways. For
example, if we replaced VR1 with
a thermistor we could produce a
temperature-sensitive switch. Or the
potentiometer could be a throttle
switch in a car or any one of a number
of transducers. So comparators do an
important job in sensing all sorts of
circuit conditions and then switching
an output in response.
AC signals
What else can a comparator do? So
far we have only considered the situa
tion where a comparator is monitoring
static or slowly varying signals. What
about rapid signals? To demonstrate,
let’s feed an audio oscillator into the
comparator of Fig.1. We’ll feed the
signal in via a 0.1µF (100nF) capaci
tor to pin 5, set VR1 to give +6.5V at
pin 5 and see what happens. With no
signal from the oscillator, the LED is
off. We apply a 1kHz sinewave signal,
wind up the signal to about 400mV
and the LED lights, although not as
brightly as it was when we manually
varied VR1.
So what is happening? The scope
waveforms of Fig.3 show the results.
The upper trace is the input 1kHz
sinewave and the lower trace is the
voltage at pin 7 and the LED. Some
thing is wrong here because instead of
switching cleanly, the comparator is
obviously dilly-dallying on the output
transition between high and low.
Hmm, what if the reference voltage
at pin 6 was varying up and down
with the switching action? We saw
that this was actually happening on
the static signal test previously. OK.
So let’s hang a 47µF capacitor off pin
6 to the 0V rail. That will stop any
short term signal variations on pin 6
and should clean up the output signal.
The scope waveforms of Fig.4 show
the result and the output waveform
now switches much more cleanly. The
LED also runs a little brighter as well.
So in practice, we would not use
a simple voltage divider for the REF
voltage. We would use a well-filtered
voltage, prob
a bly derived from a
zener diode or a more precise voltage
source.
However, even with a well-filtered
REF source for one of the inputs, the
switching action of a comparator may
not be what we want. Say we were us
ing a thermistor to drive a comparator
in a temperature controller. If we had
the simple circuit of Fig.1 (together
with the 47µF capacitor at pin 5) it
would certainly work but it would
be far too sensitive and the circuit
would hunt back and forth (ie, switch
on and off) continuously with small
temperature variations. This would be
unsatisfactory if you were controlling
a heater or cooling unit.
Adding hysteresis
The answer is to change the points
at which the comparator switches
from low to high and then from high
back to low. To do this, we provide
positive feedback from the output to
Fig.5: to demonstrate hysteresis this inverting comparator
version of the circuit has a 22kΩ positive feedback resistor
connected between pins 5 & 7.
the non-verting input. By positive
feedback we mean applying some of
the output signal back to the input,
so that a portion of the output signal
adds to the input signal. This is the
opposite of negative feedback where
the portion of the signal fed back from
the output subtracts from the input.
The circuit of Fig.5 is similar to
Fig.1 but we have swapped the way
the inputs are connected and we have
added a 22kΩ resistor from pin 7 to
pin 5. This positive feedback resistor
shifts the switching threshold up and
down as the output switches high
and low.
To set up the circuit of Fig.5, dis
connect the oscillator, swap pins 5
& 6, pull out the 47µF capacitor and
then check that the circuit works
as before. As you wind VR1 back
and forth you will find that the LED
Subscribe &
Get this FREE!*
THAT’S RIGHT – buy a 1or 2-year subscription to
SILICON CHIP magazine
and we’ll mail you a
free copy of “Computer
Omnibus”. Includes articles on troubleshooting
your PC, installing and
setting up computer
networks, hard disk
drive upgrades, clean
installing Windows 98,
CPU upgrades, a basic
introduction to Linux
plus much more.
switches on over a very narrow range.
Pin 6 only needs to be raised or low
ered by a small amount near +6V to
turn the LED on or off.
Now connect the 22kΩ resistor
between pin 6 & 7. You will find that
you now have to wind VR1 over a
wider range to turn the LED on and
off. In fact, you will now find that you
have to vary VR1 so that it shifts pin
6 above +7V to turn the LED on and
below +5V to turn it off.
In fact, if you measure pin 5 as the
LED turns on and off, you will find
that it is moving up and down over
a 2V range as the output goes high
and low.
This is a fairly crude way of adding
hysteresis but it demonstrates the
principle.
You might also notice that the LED
does not fully turn off. This is not be
cause the comparator is not switching
correctly but is due to the current
flowing through the 22kΩ resistor.
This small current is enough to keep
the LED glowing feebly.
Well, that’s enough for this month.
Next month we’ll have a further play
with the LM393 and make it work in
SC
a few more circuits.
APOLOGY
ATTENTION KIT CONSTRUCTORS
Some K3130 Temperature Control Switch kits were
supplied with metal end panels, instead of the plastic
panels originally specified. Depending on how the kit was
assembled, this may compromise electrical safety.
Constructors are advised to disconnect the kit from mains
power and check the panels on their kit. If plastic panels
have been supplied, no further action is required. If metal
end panels have been supplied, customers should stop
using the kit and obtain replacement panels.
*Australia only. Offer valid only
while stocks last.
Subscribe now by using the handy order form in this
issue or call (02) 9979 5644, 8.30-5.30 Mon-Fri with
your credit card details.
To obtain replacement panels contact:
Dick Smith Electronic Kit Department
"K-3130 End Panels"
PO Box 321 North Ryde NSW 2113
or Phone: 1800 618 459
or e-mail: kits<at>dse.com.au
Dick Smith apologises for any inconvenience caused
December 2000 77
|