This is only a preview of the March 2024 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
Articles in this series:
Articles in this series:
|
Circuit Surgery
Regular clinic by Ian Bell
LTspice 17.1 and Frequency Response Analysis – Part 1
R
egular readers will know
that Circuit Surgery regularly uses
LTspice simulations to illustrate
circuit operation and behaviour. LTspice
was developed by Linear Technology and
was originally also referred to as ‘SwitcherCAD’ because of its optimisations for
simulating switching regulators and related circuits, which were a key Linear
Technology product line. In 2017, Linear
Technology became part of Analog Devices,
who took over LTspice. The LTspice download is provided with a library of models of
real components. Initially, these were for
LT devices, but of course Analog Devices’
components were added after the merger.
Another merger of Maxim Integrated into
Analog Devices means their devices have
been added too. Models for devices from
other manufacturers (mainly passive components and transistors) are also included.
LTspice updates it model library regularly
and there are also minor software updates,
such as bug fixes, but there have not been
major software updates for some time.
Version 17.0 (written as ‘LTspice XVII’)
dates from 2016. In 2023, Analog Devices
released LTspice 17.1, which it described as
a significant upgrade to LTspice XVII. The
key addition was a new frequency response
analyser component and an associated .fra
spice directive, which we will discuss in
detail later. However, there are a few other
changes that we will mention first.
Download and install
LTspice 17.1 can be downloaded for
free from the Analog Devices website:
https://bit.ly/pe-jan24-ltspice
It is available for Windows 10 64-bit and
forward, and MacOS 10.15 and forward. The
older version is still available too. LTspice
17.1 can be installed alongside LTspice XVII
since both the executables and models for
the two versions are stored in different
locations. You can run both apps at the
same time but must not open the same file
in both versions at the same time.
Visually, the user interfaces look
very similar, although user interface
improvements and bug fixes are listed as
enhancements. The new version is named
simply ‘LTspice’, not ‘LTspice XVII’ in the
52
application title bar and desktop icons.
If you want to use both and would like a
more obvious visual indication, you could
try changing the background image which
appears in the background behind schematic
and waveform windows (Control Panel>
Operation > Background Image).
Downloading and installing LTspice 17.1
is straightforward. During the install it asks
if the installation is just for the current user
or for everyone – this changes the default
install location. On Windows, installed
examples and libraries are always stored
in the current user’s local application data
folder (C:\users\[User]\AppData\Local\
LTspice\) rather than in the documents
folder (C:\Users\[User]\Documents\
LTspiceXVII) that was used by the previous
version. If you have custom libraries or
symbols in the old location then you could
copy them to the new location or use the
control panel (Tools > Control Panel > Sym.
& Lib. Search Paths) to add the location
of your custom folders to the search path
used by LTspice.
Other enhancements
The new version has improved the drawing
speed of the waveform viewer when plotting
large amounts of data. This was definitely a
problem with the previous version, where,
for example, just resizing the waveform
viewer window could result in a lengthy
redraw period (this is just drawing the
waveform, not running the simulation).
This can be observed with some of the
simulations in the recent superhet receivers
Circuit Surgery articles where the data
sets were large because relatively long
simulations were used to obtain enough
data for LTspice to accurately plot the
signal spectra. As a quick test I resized the
full results (all key waveforms shown in
separate plot panes) and the speed-up was
obvious, with one example taking around 20
to 30 seconds to redraw in the old version,
but only 2 to 3 seconds in LTspice 17.1.
Another enhancement is that keyboard
shortcuts can now be saved to and loaded
from text files. Previous LTspice allowed
changes to keyboard shortcuts, but there
was no easy way to export these settings so
that they could be used in another instance
of LTspice (eg, to use on another computer
or share with another user). This is now
straightforward to do via the Control Panel,
with the shortcuts stored in a humanreadable text file.
Finally, Analogue Devices also lists some
improvements to the simulator operation,
specifically: fixed convergence problems,
updated initial conditions behaviour and
reduced multi-threaded CPU loading.
Frequency response analysis
LTspice’s frequency response analysis (FRA)
is aimed at determining the behaviour
of negative-feedback loops. All feedback
systems have the potential to become
unstable and oscillate, which is often
disastrous (unless you are building an
oscillator!). The FRA is aimed at determining
the stability of negative-feedback circuits;
that is, finding out how much margin of
error you have between stable and unstable
operation. If the margin is too low the circuit
may become unstable in use due to changes
in conditions (temperature, supply voltage,
component tolerance, aging and so on).
The LTspice FRA is (currently) optimised
for use with switch mode-powers supplies
(SMPS), but it can be used with other
feedback circuits – however, the set-up and
analysis provided may not be so convenient
for non-SMPS scenarios. A comment on
Analog Devices’ forum indicates that a new
version may improve this situation soon.
To introduce the basic ideas behind and
the use of the FRA, we will look at simple
op amp circuits rather than dealing with
the complexities of a SMPS – the FRA can
certainly be used in this context because
an op-amp-based example is provided
as part of the LTspice 17.1 download. To
appreciate the use of the FRA it is necessary
to understand the principles of negative
feedback and stability. Therefore, before
looking at the LTspice FRA in detail we will
introduce the basics of negative feedback
and stability in the context of standard,
well-known op amp amplifier circuits.
Op amp basics
The output (V O ) of an op amp (see
Fig.1) without any additional external
components is given by: VO = AO(V1 – V2).
Practical Electronics | March | 2024
manner determined by the
Amplifier input signal
Amplifier output signal
Input network
feedback, while keeping the
AO
Vout
voltage
across
the
op
amp’s
Sinp
Sinp
Sai
So
So
–
V2
Ao
1
inputs zero.
+
−
As can be seem from the
Feedback network
Feedback
Circuit
Circuit
examples in Fig.2, the gain
Here, V1 is the voltage on the nonMixing
signal
output
input
network
equations for the amplifier
inverting input, V2 is the voltage on the
signal
signal
So
Sf
β
as a whole only depend on
inverting input and AO is the open-loop
the resistor values. Strictly
voltage gain, which is specified on a device’s
speaking these formulae are
datasheet and is typically in the range 70 to
Fig.3. Example structure of an amplifier with negative
approximations, but if the
150dB (approximately 3000 to 30 million).
feedback. Note: this is specifically the non-inverting op
op amp’s open-loop gain is
For an ‘ideal’ amplifier, open-loop gain
amp amplifier.
much larger than the overall
tends to infinity. An op amp amplifies the
circuit gain the approximation is very good.
voltage difference between its two inputs
We have three different gain values which
The gain of the op amp itself does not change
(V1 – V2), not the voltage with respect to
can be used when discussing the amplifier
when we apply feedback – it is the gain
with feedback. These relate to the three
ground at a single point.
of the whole circuit which is determined
paths in the circuit depicted in Fig.4. First,
Op amps are usually used with negative
by the feedback. In fact, the input-output
the amplifier on its own has an open-loop
feedback – a fraction of the output signal
relationship of the op amp remains exactly
gain of AO = SO/Sai. Second, the whole circuit
is fed back and subtracted from the input
as given in the equation above when the
– it is applied at the inverting input to
(amplifier with feedback) has a closed-loop
feedback is in place. This implies the input
achieve the subtraction. This creates a
gain of AC = SO/Sinp. Finally, the value
voltage difference is actually Vout / AO,
loop from the output back to the input and
−bAO is known as the ‘loop gain’, which is
then to the output again – hence the term
not zero as in the preceding discussion.
the gain around the closed feedback loop.
‘feedback loop’ and why the gain of the
However, as with the representation of
op amp device on its own is referred to as
circuit gain with the resistor formula, the
Gain calculations
‘open-loop gain’ (gain when the feedback
approximation to zero input difference
Referring to Fig.3 we can calculate the
loop is open, or not connected). The gain
is very good for op amps with very high
closed-loop gain in terms of the open-loop
of the whole circuit with feedback is called
open-loop gain.
gain and feedback factor. The feedback
the ‘closed-loop gain’ (AC).
signal is the output multiplied by the
feedback fraction (bSO). Subtracting the
The most basic and commonly used op
Feedback structure
amp amplifier circuits in which negative
feedback signal from the circuit input gives
An abstract diagram of the structure of an
feedback is applied are the inverting or
the amplifier input as:
amplifier with feedback is shown in Fig.3.
non-inverting amplifier configurations, as
This a system structure diagram, not a circuit
shown in Fig.2. In both cases the negative
Sai = Sinp − bSO
schematic. Such diagrams are widely used
feedback is applied via a pair of resistors
by control engineers when developing
which act as a potential divider feeding a
systems (eg, in industrial control) that are
The amplifier (and circuit) output is the
fraction of the output voltage back to the
a lot more complex than an op amp circuit.
amplifier input multiplied by the amplifier
inverting input. The gain of these circuits is
In the context of an amplifier, the signals
open-loop gain:
therefore related to the ratio of the resistor
(labelled S) could be either voltages or
values, which sets the proportion of the
currents. In general, the input signal (Sinp)
SO = AOSai
output fed back by the potential divider.
may pass through an input network, as
The amplifier as a whole is either inverting
shown, which in the simplest case just
Substituting for Sai:
(negative gain) or non-inverting (positive
multiplies the input by one – for example,
gain) depending on whether the input
in the non-inverting op amp amplifier
SO = AOSinp − bAOSO
signal is routed to the inverting or nonthe input goes straight to the op amp.
inverting input.
For the inverting op amp amplifier, the
Collecting the output terms together gives:
In an op amp amplifier, the negative
resistors form a potential divider for the
feedback is regulating/controlling the
input signal, LTspice
so the input
network
is not Response
SO + bA
OSO = A–
OS
inp 1
17.1 and
Frequency
Analysis
Part
differential input voltage to the op amp to
simply unity gain.
be zero. The differential input to the op amp
The input signal then passes to the mixing
And rearranging to find the closed-loop
is a function of the circuit input minus the
network, which subtracts the feedback (Sf)
gain, we get:
17.1is
and
Frequency
Analysis – Part 1
feedback. If the input voltage to the circuit
from the LTspice
input. This
performed
byResponse
the
𝑆𝑆"
𝐴𝐴&
changes the op amp output changes until
𝐴𝐴! =
=
op amp, and in the case of the inverting
𝑆𝑆#$% (1 + 𝛽𝛽𝐴𝐴& )
the subtraction of the feedback reduces
amplifier, the ‘summing junction’ combines
the voltage across the op amp’s inputs to
signals at the inverting input. The amplifier
In a typical op amp amplifier AO is very
𝑆𝑆" and b is
𝐴𝐴&a moderate fraction so bA
zero. Thus, the output voltage will track
block in Fig.3 represents the open-loop𝐴𝐴 =large
O
=
!
(1much
)
+ 𝛽𝛽𝐴𝐴&larger
changes in the circuit’s input voltage in a
gain of the op amp.
is𝑆𝑆usually
than 1 and we can
#$%
𝐴𝐴&(1 + 1
The feedback is obtained
approximate
bAO) to bAO. This means
𝐴𝐴! =
=
Vin
R2
𝛽𝛽𝐴𝐴
𝛽𝛽of AO cancel in the AC
from
the
output
of
the
that
the
instances
+
&
Vout
amplifier by passing it
equation to give:
R1
–
Vin
through the feedback network
𝐴𝐴&
1
–
Vout
R2
𝐴𝐴! =
=
(resistor potential divider in
𝛽𝛽𝐴𝐴& 𝛽𝛽
the op amp amplifiers) which
+
multiplies it by a factor of b,
This leads to the situation discussed above,
R1
so Sf = bAOSai. (b is known
where the op amp amplifier's gain is set by
AC = –R2 / R1
AC = 1 + R2 / R1
the feedback resistors (which determine b),
as the feedback factor and is
independent of the op amp open-loop gain
typically less than or equal
Fig.2. Op amp amplifiers.
(as long as bAO is much large than one).
to one.)
V1
+
Fig.1.
Open-loop
op amp.
Practical Electronics | March | 2024
53
inductor has an extremely high
impedance and effectively
breaks the loop, allowing a
Sinp
Sinp
Sai
So
simulation in which a test
So
Ao
1
+
signal is injected to show the
−
Loop gain
AC characteristics of the loop
Sf
–βAo = S' f / Sf
(ie, the frequency response of
the loop gain). Unfortunately,
Break in loop to
this method does not give very
define loop gain
accurate results.
S' f
β
Another approach was
So
published by R. David
Middlebrook, ‘Measurement
Fig.4. Structure of an amplifier with negative feedback
of Loop Gain in Feedback
showing the open-loop (red), closed-loop (green) and
Systems’, in the International
loop-gain (blue) relationships.
Journal of Electronics in 1975.
This uses test signals injected into the
Loop gain
closed-loop system (in a simulation, voltage
The loop gain is an important parameter
and current sources can be inserted in the
when considering the stability of feedback
loop). This allows (through the theory
systems.. By definition, the start and the end
developed by Middlebrook) to find the
of a loop are the same point, so if we write
voltage and current gains of the loop and
the loop gain simplistically this way, say,
combine these to find the loop gain. If the
SO/SO, we just get 1. We can define loop gain
feedback loop includes a low impedance
by breaking the loop, as shown in Fig.4. This
driving a high impedance at some point,
allows us to obtain two different signals Sf
then the current gain has minimal impact so
and S'f which are really at the same point
just the Middlebrook voltage gain is equal
in the loop giving a gain for the complete
to the loop gain. This ‘voltage only’ version
open-loop path as S'f/Sf, which does not
of the Middlebrook method is used by the
cancel to 1. We trace the entire path of the
new LTspice frequency response analysis.
loop in the system diagram from, and back
to, the break, so it does not matter where
the break is – we get the same expression
Phase shift
for loop gain. For the circuit in Fig.4, the
The output of a circuit does not respond
loop contains three elements: the amplifier
infinitely quickly to changes at its input,
(gain AO), the feedback section (gain b) and
so any signal fed back from the output
to the input will be offset in time with
the negative summation (gain −1), so the
respect to the original input. Phase shift
loop gain for this system is these multiplied
represents the delay of a sinewave signal
together, which is −bAO.
through a circuit at a given frequency. If
We broke the feedback loop to help
the delay is constant then phase shift will
define loop gain, and in theory it may be
increase linearly with frequency, but often
possible to break the loop of a feedback
this is not the case, particularly over wide
circuit for the purposes of simulation or
frequency ranges.
measurement to find loop gain (we cannot
Consider a simple case in which there
measure loop gain directly from the original
is a fixed delay from input to output of
circuit voltages). However, breaking the
the circuit whatever the input signal does
loop and retaining enough ‘normal’ circuit
(things are usually more complicated than
behaviour to make a valid measurement
this). Say, for example, this delay was 0.1μs.
is not straightforward – for example, the
If the input frequency was 100Hz this time
output driving the break may have to be
would be 0.001% of the signal’s cycle
loaded with the same impedance it sees in
time and could probably be considered
the normal circuit, and the DC conditions
insignificant. However, at 2.5MHz the 0.1μs
need careful attention so that the bias levels
delay is a quarter of the signal’s cycle time
in the ‘broken’ circuit match those in normal
of 0.4μs (1/2.5×106 = 4.0×10–7). This would
operation. Often, it isn't possible to obtain
meaningful results using a broken loop.
usually be expressed by saying that the
circuit had a phase shift of 90° at 2.5MHz
(one complete cycle of the waveform is
Measuring loop gain
360°). At 5MHz 0.1μs is half the cycle time
There are a number of approaches to
of the signal. This is a significant point
overcome this. For example, in simulation
because a phase shift of 180° is equivalent
the correct DC levels can be achieved
to multiplying the signal by −1.
by inserting an extremely high-valued
inductor instead of a pure open circuit.
This effectively keeps the loop closed
Instability
for DC (for which the inductor is a short
Consider the total phase shift through the
circuit), preventing any small DC levels
amplifier and feedback network (in Fig.3)
being open-loop amplified to cause the
as we increase the input signal frequency
amplifier output to saturate at the supply
– in line with the above argument, phase
levels. For AC signals this super-sized
shift will tend to increase. Once the shift
Circuit closed-loop gain
AC = So / Sinp
54
Amplifier open-loop gain
AC = So / Sai
reaches 180° we have effectively inverted
our feedback signal – what was negative
feedback has become positive feedback.
Returning to the closed-loop gain equation
from above: AC = AO / (1 + bAO). If the value
of the term (1 + bAO) approaches zero then
the value of AC will tend towards infinity.
That is infinite closed-loop gain – this
results in instability, specifically the circuit
oscillates. The condition for which (1 +
bAO) = 0 is bAO = −1. This condition for
instability specifically concerns the loop
gain, not the closed-loop or open-loop gains.
Phase margin and gain margin
Looking at this in more detail, since A and b
are phasor quantities (they have magnitude
and phase shift), we get oscillation when
the magnitude of bA (loop gain) is at least
one (written |bA| ≥ 1 ) and the phase shift
due to bAO is ±180°. Generally, the gain of
an amplifier will decrease, and the phase
shift will increase, as frequency increases.
The question is – will the above conditions
for instability occur as frequency increases?
We can measure how close a circuit is to
being unstable using the concept of gain
margin and phase margin.
As the loop gain magnitude approaches
1 the phase shift must be less than 180°.
The difference between the phase shift at
this point and 180° is the phase margin.
Second, as the phase shift around the loop
approaches ±180° the magnitude of the gain
must be less than 1 to prevent oscillation.
This difference between the loop gain
when its phase shift reaches 180° and 1
(which is 0dB) is the gain margin (usually
expressed in dB).
Fig.5 shows a frequency response plot
for an amplifier loop gain with the gain and
phase margins indicated. The gain margin
and phase margin are a pair of values for
a feedback amplifier which indicate its
stability. These values are fixed for a given
circuit and do not change with frequency
(unlike phase shift and gain). If we can
obtain a plot of loop gain and phase shift
against frequency then it can be used to
assess circuit stability. This is what LTspice’s
new frequency response analysis provides.
LTspice FRA example
Fig.6 shows an LTspice schematic of an op
amp inverting amplifier configured for use
with the new frequency response analysis
(.fra directive). We will show a quick
Introduction to LTspice
Want to learn the basics of LTspice?
Ian Bell wrote an excellent series of
Circuit Surgery articles to get you up
and running, see PE October 2018
to January 2019, and July/August
2020. All issues are available in
print and PDF from the PE website:
https://bit.ly/pe-backissues
Practical Electronics | March | 2024
Gain (dB)
Phase shift
0
0
Gain
margin
Log frequency
Fig.5. (left) Example variation of gain and phase shift around a
feedback loop (loop gain) with signal frequency, illustrating gain margin
and phase margin.
Fig.6. (above) Example circuit for LTspice frequency response analysis.
–90
Phase
margin
–180
example here and discuss LTspice frequency
response analysis in more detail next
month. The schematic in Fig.6 is based on
an example provided by
LTspice in the download.
The circuit has an input
voltage source added to provide a source
for a standard AC analysis (.ac directive)
to show closed-loop gain for comparison.
Fig.7. AC analysis results for the circuit in Fig.6 – this shows variation of closed-loop
gain magnitude (solid) and phase (dotted) with frequency.
To switch between the FRA and AC
analysis swap the text on the schematic
between comments and SPICE directives.
Frequency response analysis requires
the addition of an FRA component to the
schematic at a suitable point in the feedback
loop, in series with the loop. In Fig.6 it is
inserted between the op amp output and
feedback resistors (between nodes A and
B). The FRA component has initial letter
<at> in the same way that resistor names start
with an ‘R’, capacitors with a ‘C’ etc. In
order to run a frequency response analysis
the .fra directive is used, as seen on the
schematic. The operation of the frequency
response analysis can be configured by
right-clicking the FRA component. This
example used the settings provided in the
download example.
Before looking at the FRA results, Fig.7
shows a standard LTspice AC analysis
for the circuit output at node A. The FRA
component was disabled for this analysis.
AC analysis requires an input source with
an AC amplitude defined, which is V3 in
Fig.6. V3 is a 0V DC source so it has no effect
on the circuit other than for AC analysis.
The results in Fig.7 show the variation of
closed-loop gain with frequency.
The FRA results are shown in Fig.8 –
this shows the variation of loop gain with
frequency and can be used for stability
analysis. LTspice prints the gain and phase
margin values on the response plot. The
results look similar – they are both frequency
responses, but they are calculated in very
different ways. The AC analysis used a
linearised model of the circuit and requires
a source with AC configured, whereas
the FRA used transient simulation with
waveforms at various frequencies and
requires an FRA component – more on
this next month.
Simulation files
Fig.8. FRA results for the circuit in Fig.6 – this shows variation of loop gain magnitude
(solid) and phase (dotted) with frequency.
Practical Electronics | March | 2024
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:
https://bit.ly/pe-downloads
55
|