This is only a preview of the May 2023 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Circuit Surgery
Regular clinic by Ian Bell
Op amps as comparators
A
n EEWeb forum post by user
Maddan417 describes problems
with a voltage comparator circuit
using the LM741 op amp (see Fig.1),
which does not operate as hoped. The
circuit needs to switch at 1.2V for inputs
ranging from 1V to 3.5V, but switches at
2.5V. Maddan417 is attempting to do this
using an LM741 op amp, L7805 voltage
regulators, a voltage divider, and a transistor. The 741 is supplied from a single
5V rail from the regulator, with the power
source being an automotive alternator.
Maddan417’s problems also included the
op amp output not being 0V when the circuit has switched to a ‘low’ output state.
Another contributor pointed out that
the incorrect switching voltage is at least
partly due to swapped or incorrectly
calculated values for the resistors used
to set the switching point. The values
shown set the comparator threshold to
5 × 1kΩ/(1kΩ + 330Ω) = 3.76V, swapped
they give 5 × 330Ω/(1kΩ + 330Ω) = 1.24V.
The design used two regulators for the
supply and potential divider, which is
not necessary.
The more fundamental problems are
related to the use of the 741 – it is an op
amp, not a comparator, its performance
is poor, and it is used outside its
recommended operating conditions in
Maddan417’s circuit. In this article we
will discuss use of the 741, and op amps
in general, as comparators.
The 741
Op amp evolution: (top) GAP/R K2-W: a
vacuum-tube op amp from 1953; (below)
uA741 IC op amp, first produced in 1967.
(Images: Wikipedia)
Practical Electronics | May | 2023
The 741 is a very old op amp – the uA741
was designed by Dave Fullagar of Fairchild
in 1968. At the time, there were very few
other op amps on the market. The 741
was preceded by the uA702 in 1963 and
uA709 in 1965, also both from Fairchild.
The uA702 was the first monolithic (single
chip) IC op amp, previously op amps
were modular solid-state devices using
discrete transistors, or hybrid circuits
using chip transistors, or combination
of ICs and discrete components. Before
that there were valve / vacuum tube op
amps. If you would like a long, detailed
read on op amp history try Chapter H:
Op Amp History by Walt Jung from the
+5V
+5V
R1
330Ω
VIn
–
U1
LM741
+
VOut
R2
1kΩ
Fig.1. Maddan417’s circuit.
Op Amp Applications Handbook, 2005 –
see: https://bit.ly/pe-may23-op1
Robert Widlar, the designer of the
uA702 and uA709, moved to National
Semiconductor and produced the LM101,
which, like the LM741 is still in production.
Dave Fullagar improved on the LM101 to
produce the uA741, which quickly became
very popular. As part of IEEE Spectrum’s
‘Chip Hall of Fame’ series of articles –
https://bit.ly/pe-may23-op2 – you can
see a letter from Fairchild’s marketing
department in 1968 which concludes,
‘We’ve got a winner’. The various
versions of the 741 have sold in hundreds
of millions.
The 741 deserves its place as an iconic
electronic component, but its popularity
and ubiquitousness in textbooks and
online tutorials can lead to problems when
inexperienced designers assume that it
will be suitable in circuits where it isn’t. A
common example of this is use at relatively
low supply voltage circuits – the 741
datasheet (Texas Instruments, Rev D, 2015)
specifies a recommended minimum supply
voltage of ±10V. Maddan417’s circuit
runs on 5V, so the 741 is well outside its
recommended operating conditions in
this application.
Of course, the 741 will be OK in plenty
of circuits where high performance and
relatively low supply voltages are not
required, and it is still likely to be found in
commercial designs, many of which may
have been around for a long time. On the
other hand, the performance of the 741 is
poor compared to more modern devices,
55
The maximum output voltage
range (or output voltage swing)
of an op amp is often specified
relative to the supplies (under
Differential
–
input voltage
specific conditions). For
VOut
example, ‘within 1V of the
VIn
+
Output voltage
supplies’ would mean, on a
Common-mode
range: –9 to +9V
input voltage
±10V supply, the output range
range: –7 to +7V
–10V
would be ±9V (see Fig.2), on
–VSupply
a single 20V supply it would
be +1 to +19V (see Fig.3). The
Fig.2. Example op amp voltage ranges for split
LM741’s specified output range
supply. For this circuit, for normal linear operation, the
is ±12V to ±14V on ±15V supply
common-mode input voltage is equal to Vin.
(ie, within 1 or 2V of the supply)
but is worse for loads below 10kΩ.
so there is relatively little to justify using
An op amp does not experience any
it in a new design, and many designers
fundamental difference operating on a
today would never consider it. However,
split supply or a single supply of equal
its relatively high maximum supply voltage
magnitude (eg, ±10V split or single 20V).
(44V/±22V), combined with low cost and
An AC signal can have an offset applied
well-understood behaviour are sometimes
to it so that it varies around the mid-point
cited as a reasons for using it. There are,
of a single supply. Thus, to the op amp,
however, plenty of other op amps which
the conditions are the same for a ±5V
operate at this, and higher voltages, so this
output on a ±10V split supply, or a 5V to
is not in itself a unique property.
15V output centred on 10V with a single
20V supply. However, there is often a
Voltage ranges
requirement to handle signals specifically
There are a few voltage ranges to consider
at, or close to 0V, which means that a
when designing op amp circuits, and these
single-supply circuit requires the op amp
op amp specifications must be compatible
to output signals at or close to the supply,
with the operating requirements of the
whereas a split supply does not. This is a
circuit. We have already mentioned that
problem for Maddan417’s single-supply
the supply voltage range is a problem in
circuit where there is a requirement to
Maddan417’s circuit. The other voltage
output 0V when the comparator output is
range parameters are the output voltage
low – the 741 is not able to achieve this.
and input voltage ranges.
Over the last two or three decades supply
Op amps are often operated on split
voltages have tended to reduce due to
supplies – usually equal positive and
the effects of advances in semiconductor
negative supplies (see Fig.2). This enables
technology. For example, op amps are
the op amp circuit to easily handle AC
often required in circuits together with
signals (that have both positive and
digital devices, such as microcontrollers,
negative voltage excursions). A signal
which require low supply voltages. It is
varying around 0V is conveniently in the
convenient to operate op amps on the
middle of the supply range, which tends
same voltage, where possible, so there is
be where it is easiest to design op amp
demand for lower voltage op amps. If an
circuits to work effectively. As signals
op amp can only handle signals to within
get closer to (or even beyond) the supply
1V of the supply this is much more likely
voltage range, op amp circuit design
to be a problem with a 3.3V supply than
becomes more challenging. For example,
a 20V one. This, and the convenience of
transistors may turn off, or potentially
single-supply operation with outputs able
damaging polarity reversals may occur,
to go 0V, have led to the development of
preventing correct operation. Many op
op amps with ‘rail-to-rail’ outputs.
amps, particularly earlier devices such
Typically, for BJT op amps, rail-to-rail
as the 741, are not designed to handle
outputs can go to within a collectorsignals close to the supply.
emitter saturation voltage
(VCEsat) of the supply. VCEsat is
+VSupply
+20V
dependent on the transistor’s
collector current and hence
the op amp’s output current.
Differential
–
input voltage
For moderate currents (in the
VOut
mA range) VCEsat is typically
VIn
+
Output voltage
Common-mode
100 to 300mV. Some op amp
range: +1V to +19V
input voltage
designs take things further
range: +3V to +17V
and have internal circuits to
generate voltages above and
below the applied supply
Fig.3. Example op amp voltage ranges for single
supply. For this circuit, for normal linear operation, the voltage to facilitate full railto-rail signal ranges.
common-mode input voltage is equal to Vin.
+VSupply
56
+10V
Input voltages
Op amps have two inputs, so there are
input voltage specifications relating to
individual, differential and common-mode
signals. Individual inputs have an absolute
maximum voltage specification. For the
741 this is either the supply voltage or
±15V, whichever is lower. The differential
voltage is the voltage between the inputs,
again there is an absolute maximum rating
for this, which is ±30V for the 741.
In most op amp applications, the op amp
is used as an amplifier with feedback. This
keeps the inputs at more or less the same
voltage, so differential input limitations
are not an issue for normal operation.
However, if used as a comparator, or if a
linear amplifier is pushed into saturation
by a large input signal, then larger
differential inputs can occur.
The common-mode input voltage is the
average of the voltage on the two inputs.
For non-inverting amplifiers and similar
configurations (see Fig.3) the commonmode input is equal to the input voltage
(remember the two inputs are at about
the same voltage). Common-mode input
range may also be specified relative to
the supplies – for example, within 3V of
the supplies, as shown in Fig.3. As with
output ranges, some op amps have rail-torail common-mode input capability. The
common-mode input range figure is not
always quoted for the 741, but the Harris
CA741 datasheet (1993) states ±12V for
±15V supplies, indicating within 3V of
the supplies.
Op amps as comparators
Op amps can be used as comparators,
but there are dedicated comparator
chips which perform this function much
better. In general, a dedicated comparator
should always be used, but in some
cases, for example where the comparator
requirements are not demanding and/or
a spare op amp is available on a multiop-amp package then they can be used.
The following discussion will highlight
the differences between op amps
and comparators.
A comparator’s output will typically
switch between the positive and negative
supply voltages (or ground and supply in
single-supply circuits), going rail-to-rail, or
sufficiently close to be easily interpreted
as a logic 0 or 1, or to switch a transistor
or other load effectively. For similar
behaviour from an op amp, a rail-to-rail
output device must be used, otherwise
the problems observed with Maddan417’s
circuit will occur. Comparators have no
need to output intermediate voltages;
however, the output may switch (or it may
be possible to arrange for it to switch) to a
different voltage from the main comparator
supply to facilitate interfacing to logic
circuits, or for switching loads on different
Practical Electronics | May | 2023
Input
Overdrive
VRef
tpd
Output
VOH
90%
50%
VOL
10%
tr
Time
Fig.4. Comparator propagation delay.
supplies. This is more difficult to achieve
with op amps.
Often, comparator output circuits are
designed to be easy to interface with
specific types of logic. Comparators are
therefore available with a variety of output
configurations including push-pull, open
drain, open collector and LVDS (lowvoltage differential signalling). Open drain
and open collector require an external
(pull-up) resistor connected from the
output to the positive (digital) supply.
Op amps are designed to be used with
negative feedback – a ‘closed-loop’ system.
All amplifiers have some delay from input
to output, which results in increasing
phase shift as signal frequency increases.
At some point the phase shift reaches
180°, at which point the negative feedback
network is actually delivering positive
feedback. If the gain of the amplifier and
feedback network together is greater than
one at this frequency then oscillation
will occur. The gain of most op amps
is deliberately rolled off as frequency
increases to prevent this instability – this
is called compensation. Comparators are
either used in ‘open-loop’ mode, or with
positive feedback, so compensation is not
required, leading to significant differences
between the two types of devices.
Op amps are high-gain, linear, differential
amplifiers; so, as already noted, in normal
operation the voltage difference between
an op amp’s inputs is very small (typically
microvolts to millivolts). Comparators
often have much larger input differences.
Not all op amps can tolerate large input
voltage differences and they perform very
poorly under such conditions. Op amp
input impedance may drop significantly for
large input differences due to conduction
of protection diodes – this could upset
circuits driving an op amp used as a
comparator. Comparators are commonly
used to compare voltages which are not
close to half the supply range. For an
op amp, this is a large common-mode
input voltage. Again, not all op amps
perform well under such conditions. If the
common-mode input range is exceeded
correct operation may not occur.
Gain and offset are characteristics shared
by op amps and comparators, however, the
Practical Electronics | May | 2023
Fig.5. Configuring opamp2 to use the lm741 subcircuit.
switching behaviour of comparators means
that they have characteristics related to
switching which are not relevant to the
standard analogue amplifier usage of op
amps. The switching characteristics are
illustrated in Fig.4.
Speed of switching
When the comparator input voltage crosses
the reference voltage the comparator
output will switch. This will not happen
instantaneously – the time taken for
the comparator output to reach 50%
of the resulting voltage change is the
propagation delay (tpd). The time taken for
the comparator output voltage to rise from
10% to 90% of its range is the rise time
(tr). The amount of voltage applied to the
comparator’s input beyond the switching
threshold (reference voltage) is known as
the overdrive. Propagation delay and rise
time are usually sensitive to overdrive,
with increasing overdrive resulting in
faster switching times. Comparator speed is
also usually dependent on supply voltage.
The maximum rate of change of output
voltage an op amp or comparator can
deliver is the slew rate. Slew rate is
important for op amps because it indicates
how well the output voltage will track fastchanging analogue waveforms; failure to do
so causes distortion. Slew rate also directly
determines the maximum frequency at
which an op amp can produce a pure
sinewave at full output swing (the full
power bandwidth), however, sinewave
output is of no relevance to comparators.
For any circuit used as a comparator,
either the slew rate or the bandwidth may
be the dominant factor in determining the
propagation delay. Because comparators
are just required to switch their outputs
quickly the slew rate itself is not usually
very important as a specification, it is the
propagation delay and rise time which
are quoted. The compensation applied to
op amps tends to reduce their slew rate,
making them relatively slow when used
as comparators.
Op amps are designed for applications
where the output voltage does not go hard
to the supply rails – this would normally
imply clipping of the waveform and hence
distortion. When op amp outputs are driven
hard into saturation they tend to be slow
to recover. Like compensation, this makes
op amps poor comparators where fast
switching is required. The internal circuitry
of comparators is different, allowing them
to recover very quickly. A further subtlety
to this is that op amp saturation recovery
time is likely to vary between individual
devices, making the propagation delay
somewhat unpredictable.
Simulating the 741
We can simulate a 741 comparator
circuit and compare it with a dedicated
comparator using LTspice. However,
this takes some effort as there is no 741
model provided as part of the LTspice
download. If you search online for ‘741
SPICE model’ you will find a link on
the Texas Instruments site for a ‘LM741
PSPICE Model’ (note Pspice, not LTspice):
https://bit.ly/pe-may23-741
The download provides an lm741.lib
file, which is a SPICE subcircuit definition.
This code can be used, together with an
appropriate associated symbol file to allow
the model to be included in an LTspice
schematic. Do be aware that although
Fig.6. Entering
the .lib directive.
57
Fig.9. New folder in the component selector.
Fig.7. Symbol Attribute Editor for a component in the library.
MyComponents). Copy (not move!) the opamp2.asy symbol
file from the Opamps subfolder of the existing sym folder
to your new subfolder and rename the new file lm741.asy.
Also create another new folder for the model file – a
subfolder of …\Documents\LTspiceXVII is appropriate,
with a name like MySub (the folder with the original LTspice
model files is called Sub). Put the downloaded lm741.lib
file in your new folder.
Go to you your symbol folder and double-click
the lm741.asy file to open it in the LTspice symbol
editor. Alternatively, open LTspice and do File >
Open. In the file open dialog change the file type
to Symbols (*.asy) and open the lm741.asy file.
Then, in LTspice open the symbol attribute editor
from the menu using:
Edit > Attributes > Edit Attributes
Fig.8. Configuring the LM741 symbol attributes.
SPICE is a de facto standard, and hence models are often compatible,
sometimes it is necessary to edit models created for a different SPICE
tool. Fortunately, in this case, the model works with LTspice. The
741 model can be used as a one-off, or added to the LTspice library
so that it can be used like other components.
For one-off use, place the downloaded lm741.lib file in the folder
to be used for the circuit simulation files. Create a new schematic in
the same folder, using the opamp2 component (from the Opamps part
of the component selector) where you need a 741. Right click on the
symbol and change the Value attribute to lm741 (see Fig.5). Then click
on the SPICE Directive (.op) button and enter the .lib command
with the full path to the lm741.lib file (see Fig.6), for example:
Referring to Fig.7, in the Symbol Attribute Editor
change the Value attribute to LM741 and insert
the full path to the lm741.lib file as the Modelfile
attribute value. You can also add a description if you
want (see Fig.8). Save the symbol and close LTspice.
Open LTspice and create a new schematic. When
you add a component, the new folder in the symbol
library should be listed (See Fig.9). In this folder
you will find the LM741 (see Fig.10), which can
be added to the schematic in the usual way. Note
that the Description attribute is displayed in the component
selector along with the symbol.
LT1018 vs LM741 simulation
Fig.11 shows an LTspice schematic for comparing the 741
with a comparator. The comparator is an LT1018, which is
.lib D:\LTSpice\Comparator741\lm741.lib
(Do remember to use the path to the file on your computer.) Click
to place the directive text on the schematic.
Adding components to the LTspice library
It is possible to create a new folder in the LTSpice library that will
appear on the list of components when editing schematics. Placing
symbol files in this folder and associating these with .lib SPICE
model files downloaded from manufacturers will make those
components available for use in any simulation. The following
instructions describe what to do for the 741, but other models can
be added using this procedure.
Find the location of the LTspice symbols library (sym folder) on your
computer (eg, C:\Users\username\Documents\LTspiceXVII\lib\
sym) and create a new subfolder here with a name of your choice (eg,
58
Fig.10. LM741 in the component selector.
Practical Electronics | May | 2023
Top to bottom:
Fig.11. LTspice simulator schematic for
comparison of an LT1018 comparator
with an LM741 op amp when it is used
as a comparator.
Fig.12. Results from simulation circuit
shown in Fig.11.
Fig.13. Results from simulation circuit shown
in Fig.11 (zoom in on output switching). Input
threshold is crossed at 6ms.
available in the LTspice library. The output
stage of the LT1018 includes a pull-up
current source, eliminating the need for
an external resistor, which is commonly
needed with similar comparators like the
LM393. The simulation uses both devices
in a basic comparator configuration on a
single supply, which is 20V to correspond
with the LM741 recommended minimum.
The comparator reference is at the centre of
the supply range. This provides conditions
which should not take the 741 out of its
recommended operating conditions. This
doesn’t match Maddan417’s circuit, but we
can’t be confident that the 741 model works
well outside the recommended conditions.
The results of the simulation are shown
in Fig.12, and Fig.13 shows a zoom in on
the output switching. These shows that the
output of the LM741 only gets to within
about ±1V of the supplies – as described
by Maddan417 and discussed above. The
LT1018’s output goes to values very close
to the supplies. This again highlights the
fact that interfacing an op amp output
to logic or load switching is often more
difficult than with a comparator device.
The simulation (Fig.13) also shows
the LM741 op amp responds much more
slowly than the LT1018 comparator, as
discussed above. Finally, Fig.12 show
the current into the non-inverting inputs
of the two devices. The current into the
LT1018 is orders of magnitude lower
than for the 741. In general, old op amp
designs have much higher input currents
than modern devices. This may be very
significant in some applications. Op
amps can be used as comparators, but not
without difficulties, and only in relatively
slow-speed applications – the op amp’s
datasheet should be consulted to make
sure that it is suitable for the application to
avoid problems such as those experienced
by Maddan417.
Simulation files
Most, but not every month, LTSpice
is used to support descriptions and
analysis in Circuit Surgery.
The examples and files are available
for download from the PE website.
Practical Electronics | May | 2023
59
|