5 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 Access to WinSPICE and user guide 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 5.3 SPICE Controls 60 minutes 5.3.1 Interactive Shell Berkeley SPICE release 3 includes a built-in command shell, which is similar to a unix c-shell. Variables and numerical vectors can be manipulated, displayed and stored. It is this shell that is used to manipulate simulation results, so some basic functionality of it will be explained in the following interactive tutorial. Data is organised in plots, which contain sets of text variables and numerical vectors. Performing a simulation creates a new plot and the results of previous simulations remain in memory unless the old plots are erased. All numerical quantities are contained in vectors, even if it is only one number. • Variables can be view and set with the SET command. View currently set variables by typing set and note that there are variables that describe the current plot, curplot and plots. The online TUTORIAL (INTERACTIVE INTERPRETER / VARIABLES) identifies other useful variables that control program operation (e.g. nomoremode, noaskquit) • Vectors are arrays of numerical data that are assigned and created by the let command. Create a new plot to store new vectors with setplot new and then create a vector with 101 elements called x with the vector command: let x=vector(101) Let the values of x range between –1 and +1 with let x=(x/50)-1 Set x to be the default plotting scale: setscale x 1 Check the vectors created by this with the display command. Now plot some functions. plot xˆ2*sin(x*2*pi) plot cos(2*pi*x) plot xˆ2*sin(x*2*pi) cos(2*pi*x) Produce a hardcopy with the file menu or copy to the clipboard with the edit menu. 5.3.2 Scripts SPICE 3 provides a mechanism for performing circuit analysis with user defined functions and scripts. The format of a script file is as follows: The first line is a title or comment line starting with an asterisk. The next line is ‘.control’ (the dot ‘.’ is significant), the last line is ‘.endc’ and intermediate lines are commands as could be typed at the spice prompt. A script file can be executed by typing the name of the file that contains the script. • Example: Prepare a text file with the following text. * example script .control setplot new let x=vector(101) let x=(x/50)-1 setscale x foreach power 1 2 3 4 5 6 echo $power let y$power = xˆ$power end echo plotting plot y1 y2 y3 y4 y5 y6 .endc A simple way to start off, once spice is launched, is to change to the working directory and edit a new file with the following commands: Winspice 1 -> cd h:\working\whatever Winspice 2 -> edit testscript.txt 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 * command line echo .control echo there are $argc arguments echo the first is $argv[1] let count=$argc if (count > 3) echo the fourth is $argv[4] end .endc 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 = xˆn. 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 Ω Again, an easy way to start is to ensure spice is working in the desired directory and then create a new file with the ‘edit’ command: Winspice 1 -> cd I:\working Winspice 2 -> edit dctest.cir Once the netlist is ready, save it and load the circuit by typing its file name (or use the source command): 3 Winspice 3 -> dctest.cir Check that the circuit has been correctly loaded with the listing command. From this point on, the file can be edited by typing edit and each time the file is re-saved, it will be automatically reloaded by spice. 5.4.2 Operating Point Analysis Perform an operating point analysis on the circuit by typing op: Winspice 4 -> op Display the vectors that have been created with the display command. Print the vectors with the command print all. Show the operating condition of each resistor by show r and show all. 5.4.3 DC Analysis The dc command sweeps voltages through a range of values. Use the dc command to sweep the input voltage through the range –10 to +10 Winspice 7 -> dc vi -10 10 0.1 This assumes that the voltage source was called vi in the netlist. Use the display command to check the vectors that have been created. Plot the output with the plot command. .control dc vi -10 10 0.1 plot vo .endc 5.4.4 Non-linear devices Edit the netlist to replace the 15Ω resistor with a diode. It is necessary to add a ‘.model’ line to describe the characteristics of the diode. A suitable line that uses the default settings is .model diode d Repeat the dc command to sweep the input voltage and plot the output. Edit the .model line to add the parameter is=1e-8 and repeat the dc analysis and note any difference in the result. 5.4.5 Plots When the results of two analysis operations need to be plotted on the same graph it is necessary to determine the plot each is in. Use the setplot command to list the plots that are resident in spice. If you have performed the two dc analysis functions above without quitting spice then the last two dc plots will be shown by the setplot command. Current dc4 dctest (DC transfer characteristic) dc3 dctest (DC transfer characteristic) dc2 dctest ... 4 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 Draw the circuit described by the subcircuit, and draw a separate diagram of the test circuit that uses the subcircuit. In the latter, simply draw a block to represent the amplifier. • Use spice to determine the operating-point potentials at the transistor’s terminals and label the diagram accordingly. Perform an ac analysis on the circuit using ac dec 10 1Hz 100Meg Plot the magnitude and phase of the outputs with the following plot statements plot db(out1) db(out3) xlog plot ph(out1)*180/pi ph(out3)*180/pi xlog How does the mid-band gain of the cascade compare to the midband gain of the single amplifier? What is the effect of setting the ac magnitude of vin to 100 volts instead of 1 volt? What is the effect on the gain of the circuit? • Z parameters can be calculated with the following test bed: * inject signal at port1 for z11 and z21 vf port1f 0 dc 0 ac 1 xampf port1f port2f vcc amp * inject signal at port2 * with dc block at port2 vr 1 0 cr 1 port2r rr 0 port1r xampr port1r port2r vcc for z22 and z12 and dc path for port1 dc 0 ac 1 1mF 10e12 amp .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? 6 6 Introduction to SPICE This session demonstrates the operation and use of SPICE transient analysis. 6.1 Equipment 1 SPICE Access to WinSPICE and user guide 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 6.3 Transient Response 45 minutes A full transient analysis of the charging of a capacitor shows the time constant of the circuit. It can be simulated with the following netlist. * capacitor transient vin in 0 dc 0 pwl(0 0 1us 0 2us 5) rl in out 1k co out 0 1uF .end Once this is loaded into SPICE, it is possible to perform various transient simulations to see detail over different time spans and to compare the result with theory. The following commands will simulate the start of the transient and plot the result. The aim here is to check the timing of the step being applied. tran 10n 5u plot in out If the input was an instantaneous step at time=0 then the output should theoretically be 5 × (1 − exp(−t/10−3)) volts. Check this with plot out 5*(1-exp(-time/1ms)) Check and explain why 5 × (1 − exp(−(t − 1.5 × 10− 6)/10−3)) gives a better agreement. Repeat the transient analysis over a longer time interval up to 10 ms and repeat the previous plot. Does the simulation match theory? 6.3.1 Initial conditions Try the following circuit and compare the result with that of a session from a previous week. * transient vin in 0 dc 0 sin (0 5 1kHz) rl in out 1k co out 0 1uF .control tran 1000n 5m plot out .endc 1 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? 6.4 Amplifier Analysis 75 minutes 6.4.1 Netlist Start by creating a netlist for the following microwave amplifier circuit: 100 pF 50 Ω vi 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 amplifier’s 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(xˆ2)) DEFINE dbm(x) db(rms(x))+10 .endc 3 The first calculates the rms value of a vector, which is produced by a transient analysis, and the second converts it to dBm in 50 Ω. For these to work, the transient analysis must produce a few complete cycles of output in a time interval that is after the initial natural response of the circuit. Identify such a region by running a transient analysis a few times an observe the response. Then set the parameters for the transient command to give an output of few cycles that occur after the initial natural response has died down. It is also necessary to ensure that the points in the rms calculation are equally spaced. The ‘linearize’ command produces a such a plot by interpolating the output to regular time steps. Add the transient and linearize commands to the control section and have it print the difference between input and output in dBm. The following is the form required: .control DEFINE rms(x) sqrt(mean(xˆ2)) DEFINE dbm(x) db(rms(x))+10 TRAN 10p ... LINEARIZE print dbm(out)-dbm(in) .endc It is possible at this point to manually change the input level and re-simulate to find the level at which gain starts to drop. Another way is to use the ‘alter’ command to change the level from the command prompt, which avoids having to edit the netlist. 6.4.3 Arbitrary Source The alter command changes the settings of various devices in the circuit, such as the value of a voltage source. To use the ‘alter’ command to change the level of a sinusoid, it is necessary to implement the input with an arbitrary voltage source. This is a source that is defined by an equation involving other voltages and currents. The following can be used to replace the input source, so that amplitude is proportional to the value of voltage source ‘va’. va a 0 dc 0.1 vin s 0 0 ac 1 sin(0 1 1000meg) bin vin 0 v=v(s)*v(a)*2 Make this substitution and add the following line before the tran statement in the control section to set the input amplitude. alter va = 0.01 Now editing this line, rather than the circuit is sufficient to set the amplitude for each simulation. However, a script can be used to sweep the input level. 6.4.4 Scripts The following script sweeps the input level and prints the gain: .control .control DEFINE rms(x) sqrt(mean(xˆ2)) DEFINE dbm(x) db(rms(x))+10 LET n = 10 LET amplitude = 0.01 LET f = (1.5/amplitude)ˆ(1/(n-1)) LET k = 0 4 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(xˆ2)) 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. 6 10 Intermodulation Analysis with SPICE This session demonstrates the principles of intermodulation and the analysis of transient responses to determine intermodulation. 10.1 Equipment 1 SPICE Access to WinSPICE and user guide 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 10.3 Spectrum Function 60 minutes A nonlinear system is described by vo = a1 vi + a2 vi 2 + a3 vi 3 can be analysed with SPICE, but there is some setting up required to produced the required simulation results and to analyse the data. To understand what SPICE produces and how to interpret the results, a simple set of test cases is suggested in the following subsections. 10.3.1 Spectrum Analysis What does the SPEC function do in SPICE? To find out, start with a known spectrum, which is easily produced by an arbitrary voltage source. The following netlist produces a cosine signal that is a function of time. The time value is produced by a piece-wise linear voltage source: * test of spec command vtime t 0 0 pwl 0 0 100 100 bsource s 0 v=cos(2*pi*1e6*v(t)) .control DESTROY all TRAN 100n 2u 0 50n LINEARIZE SPEC 0 5meg 0.5meg s PRINT frequency s .endc The SPEC function applies a hanning window to the signal over the full time period of the transient analysis. It then calculates a discrete fourier transform (DFT) at each frequency from the start, stop, and step frequencies specified by the first three arguments supplied to the function. The result is stored in a new plot with frequency as the default scale. The DFT requires evenly spaced time samples, so a LINEARIZE function is required before the SPEC command. Note that the step frequency must be greater than the reciprocal of the total time interval. Why? Also, the stop frequency must be 1 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 10−10 ). 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)) Decibels Produce a nice spectrum of the previous signal by extending the time interval to 16µs and use a SPEC frequency step of 125 kHz. Change the print line to PLOT db(s) combplot What is the dynamic range of the spectrum analysis? How does this compare with the numerical precision of 15 digits that the computer uses? Add a range limit to the plot and compare the spectral terms with the voltage amplitude of each component. PLOT db(s) combplot ylimit -30 0 It is useful to display the results in dBm relative to 1 mW in 50 Ω. Confirm that the following macro accomplishes this DEFINE dbm(x) db(rms(x))+13 plot dbm(s) pointplot ylimit -15 15 2 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 = 2π1.9 × 106 and ω2 = 2π2.1 × 106 : s = 10(A cos ω1 t + A cos ω2 t) + (A cos ω1 t + A cos ω2 t)2 = +0.1(A cos ω1 t + A cos ω2 t)3 10A cos ω1 t + 10A cos ω2 t +A2 cos2 ω1 t + A2 cos2 ω2 t + 2A2 cos ω1 t cos ω2 t +0.1A3 cos3 ω1 t + 0.1A3 cos3 ω2 t +0.3A3 cos2 ω1 t cos ω2 t + 0.3A3 cos ω1 t cos2 ω2 t = A2 +A2 cos(ω2 − ω2 )t +0.15A3 cos(2ω1 − ω2 )t +(10A + 0.225A3 ) cos ω1 t +(10A + 0.225A3 ) cos ω2 t +0.15A3 cos(2ω2 − ω1 )t +0.5A2 cos 2ω1 t +A2 cos(ω1 + ω2 )t +0.5A2 cos 2ω2 t +0.15A3 cos(2ω1 + ω2 )t +0.025A3 cos 3ω1 t +0.025A3 cos 3ω2 t +0.15A3 cos(2ω2 + ω1 )t then all these components appear in the spectrum. 10.4.1 Intermodulation versus power Of particular interest in most circuits is third-order intermodulation because it produces components near the frequencies of interest, and second-order intermodulation because it usually has a high magnitude. A power sweep of intermodulation can be obtained using a script in SPICE. For this, the amplitude of the signal is controlled by a voltage source and the ALTER function is used to set its value. 3 * 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 amplitude points and reducing the maximum amplitude to only 1 V peak. What are the second and third-order intercept points? What is the gain of the amplifier? What is the 1dB compression of the amplifier? At what power level is there a null of the second-order distortion? 10.5.1 Design Problem A common design goal is to minimise the third-order distortion. One way to do this is to vary the gate bias. Try a gate bias of –0.8 V and one of 0.0 V and observer the difference in intermodulation and gain. To understand these results, try the following investigation from the command line prompt (assuming the circuit is still loaded): • Examine the dc characteristics of the transistor by dc vdd 0 5 0.1 vgg -2 0.5 0.25 plot -vdd#branch This should show that the output conductance is fairly constant. • Examine the transconductance and its derivatives by dc vgg -2 0.5 0.01 let id=-vdd#branch let gm=deriv(id) let gm2=deriv(gm) let gm3=deriv(gm2) plot id gm gm2 gm3 Given that 2 3 vi + gm vi s ∝ gm vi + gm then why is the intermodulation level so high at low gate biases? At what gate bias points is there expected to be a minimum intermodulation? Is this confirmed this by simulation? If not, why not (ask the demonstrator)? 6