Professional Documents
Culture Documents
Introduction to SPICE
This session demonstrates the operation and use of SPICE3F. The aspects introduced are the interactive shell, netlists, and basic simulations.
5.1 Equipment
1
SPICE
5.2 Timetable
2:00 pm
2:15
3:15
5:00
4:45
2:15 pm
3:15
4:00
4:45
5:00
Set up
SPICE Controls
DC Analysis
AC Analysis
Wrap up
Execute this file in spice by typing its name at the spice prompt.
User functions:
It is possible to type a file name with extra command line arguments. The arguments are passed to the script in the variable
array argv and the number of arguments is passed as argc. The
following script will display command line arguments passed to it:
2
Prepare this script in a text file and try a few command lines.
Scripts:
Use the previous two files as a basis for preparing a script file
that will implement a user defined command called plotpwr. The
command line
plotpwr xstart xstop n
should prepare a new plot containing a vector x consisting of 101
values ranging from xstart to xstop, and a vector y = xn.
5.4 DC Analysis
45 minutes
The first circuit analysis step is determination of the dc operating
point. Before this can happen, a description of the circuit, called a
netlist, must be created.
5.4.1 Netlist
A NETLIST is a spice description of the circuit with the following format. The first line is a title line, which must be present because spice
ignores it as part of the circuit. The last line is usually .end though
is not required in some versions of spice. The intervening lines contain
device descriptions, which vary according to each type of device. In
Berkeley spice, it is also possible to include a .control/.endc sequence
within the netlist to automate analysis of the circuit.
Study the spice manual to determine how to enter the following
circuit in a text file to be read by spice. (Note: there are only 3 nodes
in this circuit of which one must be 0 (zero).)
22
Vi 5 V
Vo
33
10
15
Plot the output for the two diode models of the previous section by
plotting the output in the current plot and the previous analysis on the
same graph. If the output vector is called vo then use
plot vo dc3.out
Note: If a node number, say 2, is used then it is referenced by dc3.v(2)
5.5 AC Analysis
45 minutes
For ac analysis, spice uses an equivalent small-signal model for
each device. The devices in the circuit are replaced in spice by smallsignal models, so the analysis is only valid for small signals. The following procedures demonstrate ac analysis in spice:
Create a file containing the following netlist and load it into spice.
Notice the ac magnitude of vin is specified by the keyword ac in
the vin line. Also, the .model line for the transistor is continued
onto following lines with a + as the first character.
* Simple amplifier
* input source with two outputs
vin vi
0
dc 0 ac 1
rin1 vi in1
50ohm
rin2 vi in2
50ohm
* single amplifier
xamp1
in1 out1 vcc amp
* cascade amplifier
xamp2
in2 out2 vcc amp
xamp3
out2 out3 vcc amp
* Power
vcc vcc 0 dc 10
* amplifier subcircuit
.subckt amp in out vcc
cin in base
10uF
rbu
base
vcc
22k
rbl
base
0 10k
q1 out base emit
BC547
rc out
vcc
1k
re
emit
0 1k
ce
emit
0 100u
.ends
.model BC547 npn bf=300 is=10e-15 vaf=100
+ br=1 nc=2 ikf=30m rb=120 re=0.3 tf=100p
+ cjc=50p cje=50p xtb=1.5
.end
This netlist uses a subcircuit, which it calls amp. This allows
the amplifer to be repeated in the main circuit - in this case to
implement a cascade amplifier.
5
.control
ac dec 20 100Hz 100k
let z11 = -port1f/vf#branch
let z21 = -port2f/vf#branch
let z12 = -port1r/vr#branch
let z22 = -port2r/vr#branch
plot real(z11) imag(z11)
plot real(z12) imag(z12)
plot real(z21) imag(z21)
plot real(z22) imag(z22)
.endc
Note that this requires the amplifier subcircuit and power supply.
Load this circuit into spice and comment on the plots produced.
Over what band of frequencies can the z parameters be assumed
constant?
Introduction to SPICE
6.1 Equipment
1
SPICE
6.2 Timetable
2:00 pm
2:15
3:00
4:15
4:45
2:15 pm
3:00
4:15
4:45
5:00
Set up
Transient Analysis
Amplifier Analysis
Transient Analysis
Wrap up
Transient analysis performs an operating point analysis (op) to determine the values of the node voltages at time=0. It is possible to
force the circuit to use other values, say to simulate the case where the
capacitor is charged to 10 volts at time=0.
To force an initial potential of 10 volts across capacitor co of the
above netlist, append ic=10 to the co line. Also instruct the transient
analysis to use this initial condition by adding the uic keyword:
tran 10n 5m uic.
Try an initial condition of 0.78 V.
6.3.2 Amplifier
Recall the amplifier used in the previous week:
* Simple amplifier
* input source with two outputs
vin vi
0
dc 0 ac 1
rin1 vi in1
50ohm
rin2 vi in2
50ohm
* single amplifier
xamp1
in1 out1 vcc amp
* cascade amplifier
xamp2
in2 out2 vcc amp
xamp3
out2 out3 vcc amp
* Power
vcc vcc 0 dc 10
* amplifier subcircuit
.subckt amp in out vcc
cin in base
10uF
rbu
base
vcc
22k
rbl
base
0 10k
q1 out base emit
BC547
rc out
vcc
1k
re
emit
0 1k
ce
emit
0 100u
.ends
.model BC547 npn bf=300 is=10e-15 vaf=100
+ br=1 nc=2 ikf=30m rb=120 re=0.3 tf=100p
+ cjc=50p cje=50p xtb=1.5
.end
The ac analysis of this amplifier ignored non-linear effects. A 100 volt
signal was treated as if it was a small-signal. With the transient analysis it is possible to see the true large-signal behaviour. It is first necessary to define the transient behaviour of the input source by modifying
the voltage source. The following gives a sinusoid
vin vi 0 dc 0 ac 1 sin(0 1m 1000)
Simulate the circuit over a time interval of 20ms and plot the outputs:
tran 1m 20m
plot out1 out2 out3
2
Notice that the latter plot is not clean and requires more data points,
so try
tran 10u 20m
At what input level does the cascaded amplifier begin to clip?
The transient at the beginning can be passed over by setting the
start time in the transient command:
tran 10u 20m 10m
Now check the transfer response of the circuit by plotting the output
versus input:
plot out1 vs in1 out2 vs in2
What causes the difference between the two amplifiers?
100 pF
KF04
50 nH
+
50
50 nH
0.4 V
3V
A model for the FET is in the library file fet.lib, which can be included with the line
.lib fet.lib
Note that the FET is defined as a subcircuit, so it is added in the netlist
as an x device, such as:
Xfet drain gate source KF04
Once the netlist is ready, check its operating point and adjust the
gate bias for a drain current of 70 mA. (A dc sweep may help.)
What is the required gate bias?
What is the amplifiers upper and lower 3dB frequency limits?
6.4.2 Large-signal Gain
To assess the large signal gain at 1 GHz, a transient analysis should
be performed. Do this for a 1 GHz sinusoid input amplitude of 10 mV
and 1 V, and note the differences.
A common way to display the reduction in gain with input level is to
plot the output level versus input. This is can be accomplished with a
script, which will now be set up in stages.
First, it is necessary to calculate the amplitude of the output, so
that it can be printed or stored. The following functions can be defined
within a .control section to help with this:
.control
DEFINE rms(x) sqrt(mean(x2))
DEFINE dbm(x) db(rms(x))+10
.endc
3
WHILE k < n
ALTER va = amplitude
TRAN 10p 5n 2n
LINEARIZE
print dbm(out)-dbm(in) dbm(in)
LET k = k + 1
LET amplitude = amplitude*f
END
.endc
Examine this script and explain the function of each of the variables.
Incorporate this script into the netlist and run it. At what level does
the gain drop by 1 dB?
A more elaborate script can be used to produce data that can be
plotted.
.control
DESTROY all
DEFINE rms(x) sqrt(mean(x2))
DEFINE dbm(x) db(rms(x))+10
* New plot to hold end results, note plot name and create vectors
SETPLOT new
SET dataplot = $curplot
SET pts=20
LET in = vector({$pts})
LET out = vector({$pts})
*
New plot to hold while counters
SETPLOT new
LET n = $pts
LET k = 0
LET amplitude = 0.01
LET f = (2/amplitude)(1/(n-1))
WHILE k < n
ALTER va = amplitude
TRAN 10p 5n 2n
LINEARIZE
LET {$dataplot}.in[k] = dbm(in)
LET {$dataplot}.out[k] = dbm(out)
*
Destroy transient and linearize plots
DESTROY $curplot
DESTROY $curplot
LET k = k + 1
LET amplitude = amplitude*f
END
*
Destroy while counters plot
DESTROY $curplot
PLOT out in
.endc
Draw a flow chart that explains the operation of this script. Then
run it to produce a gain versus input level plot
6.5 Distortion
30 minutes
The fourier command can be used to determine the distortion generated by the amplifier. After performing the transient analysis on the
5
amplifier above, a plot of the output for high levels clearly shows that
it is no longer sinusoidal. Check its distortion with
fourier 1000Meg out
compare this with the distortion of the input signal with
fourier 1000Meg in
Note that the natural response of the circuit has a significant influence. Compare
tran 10p 1n
fourier 1000Meg out
with
tran 10p 5n
fourier 1000Meg out
and explain the difference in terms of the shape of the output.
6.5.1 Input Level
Repeat a fourier analysis of the output for a few input levels and confirm that the third harmonic level increase with the cube of the fundamental.
10
10.1 Equipment
1
SPICE
10.2 Timetable
2:00 pm
2:15
3:15
4:15
4:45
2:15 pm
3:15
4:15
4:45
5:00
Set up
Spectrum Function
Intemodulatioin
Amplifier
Wrap up
less than the reciprocal of the time step (first argument to the TRAN
function). Why?
Load this netlist and run it in spice. Type DISPLAY and describe the
format of the data set. Also, type SETPLOT and describe the origin of
the data plots present.
Notice that the window produces artifacts either side of the tone.
What is the magnitude and phase of each significant tone in the spectrum (ignore terms below 1010 ).
The windowing artifacts can be moved by doubling the transient
time interval. Change the 2u parameter to 4u and observe the change.
Have the artifacts gone, or are the just hidden? Change the frequency
step from 0.5meg to 0.25meg and comment on the result.
Spectrums A more complex signal, such as in the following netlist,
has spectral terms at each component frequency. Load this netlist and
confirm that the spectrum is consistent with signal.
* test of spec command
vtime t 0 0 pwl 0 0 100 100
bsource s 0 v=cos(2*pi*1e6*v(t))+0.2*cos(2*pi*2e6*v(t))
+
+0.05*sin(2*pi*3e6*v(t))
.control
DESTROY all
TRAN 100n 4u 0 50n
LINEARIZE
SPEC 0 5meg 1meg s
PRINT frequency s
.endc
For more accuracy, change the TRAN function minimum step size
from 50n to 1n. This gives the LINEARIZE function a finer set of data to
interpolate.
What does it mean to have an imaginary term?
Add a cosine term to the third harmonic and note the change to the
spectrum
+
+0.05*sin(2*pi*3e6*v(t))+0.05*cos(2*pi*3e6*v(t))
10.4 Intermodulation
60 minutes
Distortion and intermodulation produce a variety of frequency components that can be easily calculated with SPICE. Simulate the thirdorder nonlinear system with the following netlist:
vtime t 0 0 pwl 0 0 100 100
bin in 0 v=0.02*cos(2*pi*1.9e6*v(t))+0.02*cos(2*pi*2.1e6*v(t))
bout s 0 v=10*v(in)+(v(in))2+0.1*(v(in))3
.control
DEFINE dbm(x) db(rms(x))+13
DESTROY all
TRAN 50n 40u 0 1n
LINEARIZE
SPEC 0 7meg 0.1meg s
PLOT dbm(s) combplot ylimit -150 0
.endc
Explain the choice of the TRAN and SPEC functions.
Confirm that if for A = 0.02, 1 = 21.9 106 and 2 = 22.1 106 :
s
A2
+A2 cos(2 2 )t
+0.15A3 cos(21 2 )t
+(10A + 0.225A3 ) cos 1 t
+(10A + 0.225A3 ) cos 2 t
+0.15A3 cos(22 1 )t
+0.5A2 cos 21 t
+A2 cos(1 + 2 )t
+0.5A2 cos 22 t
+0.15A3 cos(21 + 2 )t
+0.025A3 cos 31 t
+0.025A3 cos 32 t
+0.15A3 cos(22 + 1 )t
* intermodulation test
vtime t 0 0 pwl 0 0 100 100
vamplitude a 0 1
bin in 0 v=v(a)*(cos(2*pi*1.9e6*v(t))+cos(2*pi*2.1e6*v(t)))
bout s 0 v=10*v(in)+(v(in))2+0.1*(v(in))3
.control
DEFINE dbm(x) db(x)+13
DESTROY all
* New plot to hold end results, note plot name and create vectors
SETPLOT new
SET r = $curplot
SET pts = 10
LET in
= i*vector({$pts})
LET f2
= in
LET f1
= in
LET ip3u = in
LET ip3l = in
LET ip2u = in
*
New plot to hold while counters
SETPLOT new
LET n = $pts
LET k = 0
*
first value of amplitude and increment ratio
LET amp = 0.05
LET ra = (20/amp)(1/(n-1))
WHILE k < n
ALTER vamplitude = amp
TRAN 50n 40u 0 10n
LINEARIZE
SPEC 0 4meg 0.1meg s in
*
kludge because x[k]=y works, but x[k]=y[j] does not!!
LET idx=0*vector(length(frequency))
LET idx[17]=1; LET {$r}.ip3l[k]=sum(s*idx); LET idx[17]=0;
LET idx[19]=1; LET {$r}.f1[k] = sum(s*idx);
LET {$r}.in[k] = sum(in*idx); LET idx[19]=0;
LET idx[21]=1; LET {$r}.f2[k] = sum(s*idx);
LET idx[21]=0;
LET idx[23]=1; LET {$r}.ip3u[k]=sum(s*idx); LET idx[23]=0;
LET idx[40]=1; LET {$r}.ip2u[k]=sum(s*idx); LET idx[40]=0;
*
Destroy transient and linearize plots
DESTROY $curplot
DESTROY $curplot
DESTROY $curplot
LET k = k + 1
LET amp = amp*ra
END
*
Destroy while counters plot
DESTROY $curplot
PLOT dbm(ip3l) dbm(f1) dbm(f2) dbm(ip3u) dbm(ip2u) vs dbm(in)
.endc
How many plots are created during the course of the script, and
what purpose do the each have?
Explain the assignment of the variable ra.
How many frequency points does each spectrum have and what
frequencies are being selected by the indexing procedures?
Run the script and determine, from the graph, the second and third
order intercept levels.
4
10.5 Amplifier
60 minutes
The previous spice script can be used as a template for analysing
a simple microwave amplifier. The following netlist describes such an
amplifier:
rin in vin 50
cin vin gate 800p
vgg gg 0 -0.5V
lgg gg gate 2u
xfet drain gate 0 fet
ldd dd drain 2u
vdd dd 0 3V
cout s drain 800p
rout s 0 50
.model KF1UM njf level=2
+ BETA = 417.3u
VTO = -964.4m
+ DELTA = 76.91
Q = 1.799
+ VST = 57.92m
XI = 319.8m
+ CGD = 0.2794f
CGS = 0.9289f
+ HFGAM = 98.29m TAUD = 100.0u
P = 2.379
LFGAM = 18.48m
Z = 1.163
ACGAM = 128.9m
TAUG = 100.0u
.subckt fet 1 2 3
ld
11
1
50pH
cds
11
3
180fF
jfet
11 22
3 kf1um AREA = 600
rg
21 22
0.8ohm
lg
21
2
50pH
.ends
Replace the bout device in the script example with this netlist and
run it. What is the gain of the amplifier at the frequency of simulation?
Draw the circuit of the amplifier and explain why the gain is low.
Raise the frequency of the tones to 1.9 GHz and 2.1 GHz and repeat the simulation, with appropriate transient and spectrum analysis
arguments.
Transients: Check the simulation by manually performing a transient analysis at the command prompt:
alter vamplitude=0.1
tran 50p 1000p
plot s
To ensure that a transient free time interval of correct length is obtained, it is necessary to set the stop and start times of the TRAN function to give the end portion of a long transient simulation.
Another trick to try, is to change the cosine functions in the bsource
device to sine functions. Do this and repeat the previous manual simulation.
Would the following transient card be appropriate for this investigation of this amplifier?
tran 50p 400p 300p 20p
Simulations: The amplifier clearly overloads when there is more than
10 dBm input. Generate a better result by increasing the number of
5
2
3
vi + gm
vi
s gm vi + gm