Spice 1

download Spice 1

of 27

Transcript of Spice 1

  • 8/6/2019 Spice 1

    1/27

    UNIVERSITY of PENNSYLVANIADEPARTMENT OF ELECTRICAL and SYSTEMS ENGINEERING

    SPICE - A Brief Overview

    1. INTRODUCTION.......................................................................................................... 22. HOW TO SPECIFY THE CIRCUIT TOPOLOGY AND ANALYSIS?........................... 3

    2.1 Data Statements to Specify the Circuit Components and Topology ............................ 4

    a. Independent DC Sources ............................................................................................ 4b. Dependent Sources ..................................................................................................... 5

    c. Resistors...................................................................................................................... 6

    d.Capacitors (C) and Inductors (L)................................................................................. 6

    e. Mutual Inductors......................................................................................................... 6f. Ideal Transformer........................................................................................................ 7

    g. Sinusoidal sources ...................................................................................................... 7

    h. Piecewise linear source (PWL)................................................................................... 8i. Pulse ............................................................................................................................ 8

    j. Voltage- and Current-controlled Switches .................................................................. 9k. Operational Amplifiers, and other elements............................................................. 10

    l. Subcircuits ................................................................................................................. 10

    m. Semiconductor Devices........................................................................................... 112.2 Commands or Control Statements to Specify the Type of Analysis.......................... 14

    a. .OP Statement ........................................................................................................... 14

    b. .DC Statement........................................................................................................... 15c. .TF Statement............................................................................................................ 15

    d. .SENS Statement ...................................................................................................... 16

    e. .TRAN Statement ..................................................................................................... 16

    f. .IC Statement............................................................................................................. 16g. .AC Statement........................................................................................................... 17

    2.3 Output Statements ...................................................................................................... 17

    3. HOW TO GET STARTED WITH SPICE? (for beginners)............................................. 183.1 Creating an Input File for Spice - Example................................................................ 18

    a. Draw a schematic of the circuit ................................................................................ 18

    b. Create the input file (source file) for PSpice. ........................................................... 19c. Run Spice.................................................................................................................. 19

    4. Most common mistakes .................................................................................................... 20

    5. Examples .......................................................................................................................... 20

    5.1 Thevenin Equivalent Circuit....................................................................................... 205.2 Mutual Inductor.......................................................................................................... 21

    5.3 Ideal Transformer ....................................................................................................... 22

    5.4 Filter Circuit (.AC Analysis) ...................................................................................... 235.5 Rectifier Circuit (with diodes).................................................................................... 24

    5.6 Transistor Circuit (NPN) ............................................................................................ 25

  • 8/6/2019 Spice 1

    2/27

    1. INTRODUCTION

    SPICE is a powerful general purpose analog circuit simulator that is used to verify

    circuit designs and to predict the circuit behavior. This is of particular importancefor integrated circuits. It was for this reason that SPICE was originally developed atthe Electronics Research Laboratory of the University of California, Berkeley(1975), as its name implies:

    Simulation Program forIntegrated Circuits Emphasis.

    PSpice is a PC version of SPICE (MicroSim Corp.).

    SPICE can do several types of circuit analyses. Here are the most important ones:

    Non-linear DC analysis: calculates the DC transfer curve. Non-linear transient analysis: calculates the voltage and current as a

    function of time when a large signal is applied.

    Linear AC Analysis: calculates the output as a function of frequency. A bodeplot is generated.

    Noise analysis

    Sensitivity analysis

    Distortion analysis

    Fourier analysis: calculates and plots the frequency spectrum.

    Monte Carlo Analysis

    In addition, PSpice has analog and digital libraries of standard components (suchas NAND, NOR, flip-flops, and other digital gates, op amps, etc). This makes it auseful tool for a wide range of analog and digital applications.

    All analyses can be done at different temperatures. The default temperature is300K.

    The circuit can contain the following components:

    Independent and dependent voltage and current sources

    Resistors

    Capacitors

    Inductors

    Mutual inductors

    Transmission lines

    Operational amplifiers

    Switches

    Diodes

  • 8/6/2019 Spice 1

    3/27

  • 8/6/2019 Spice 1

    4/27

    Both upper and lower case letters are allowed in PSpice and Hspice (SPICE usesonly uppercase characters). As an example, one can specify a capacitor of 225picofarad in the following ways:

    225P, 225p, 225pF; 225pFarad; 225E-12; 0.225N, etc.

    2.1 Data Statements to Specify the Circuit Components andTopology

    a. Independent DC Sources

    Voltage source: Vname N1 N2 Type Value

    Current source: Iname N1 N2 Type Value

    Where:

    N1 is the positive terminal nodeN2 is the negative terminal nodeType can be DC, AC or TRAN, depending on the type of analysis (see ControlStatements)Value gives the value of the sourceThe name of a voltage and current source must start with V and I, respectively.

    Examples:

    Vin 2 0 DC 10

    Is 3 4 DC 1.5

    The positive current direction through the current or voltage source is from thepositive (N1) node to the negative (N2) node:

    Voltage and Current Conventions:

    1. Spice always assigns a positive reference mark to the 1st node and uses thepassive sign convention to assign the current reference.

    2. Spice uses the node-voltage analysis. It solves for the unknown node voltagesand also the unknown currents through independent voltage sources. Thisgives us a way to find currents flowing in elements: one has to ask for thecurrent through a voltage source. Thus one can insert an independent voltage

  • 8/6/2019 Spice 1

    5/27

    source of zero value in series with the element in which one wants to know thecurrent, as shown in the example below:

    The value of the current will be positive if it flows from the positive to the negativeterminal through the source, as in the above example. Some versions of PSpiceallow you to ask for a current through a resistor without using a voltage source (EX:I(R1) gives the current in the resistor R1).

    b. Dependent Sources

    Voltage controlled voltage source:Ename N1 N2 NC1 NC2 Value

    Voltage controlled current source:Gname N1 N2 NC1 NC2 Value

    Current controlled voltage source:Hname N1 N2 Vcontrol Value

    Current controlled current source:Fname N1 N2 Vcontrol Value

    Where:

    N1 and N2 are the positive and negative terminals of the dependent source,respectively.NC1 and NC2 are the positive and negative terminals of the controlling voltagesource, respectively.Vcontrol is the zero value voltage source used to measure the controlling current(the positive current flows into the positive terminal of the controlling voltagesource!).

    Examples:

    F1 0 3 Vmeas 0.5Vmeas 4 0 DC 0

  • 8/6/2019 Spice 1

    6/27

    c. Resistors

    Rname N1 N2 Value

    d.Capacitors (C) and Inductors (L)

    Cname N1 N2 Value Lname N1 N2 Value

    Where:

    N1 is the positive node.N2 is the negative node.IC is the initial condition (DC voltage or current).The symbol < > means that the field is optional. If not specified, it is assumed to bezero. In case of an inductor, the current flows from N1 to N2.

    Example:

    Cap5 3 4 35E-12 5L12 7 3 6.25E-3 1m

    e. Mutual Inductors

    A mutual inductance in SPICE is defined by specifying the coupling coefficient Kbetween the two inductors. The syntax is as follows:

    Kname Inductor1 Inductor2 value_of_K

    The value of K must be larger than 0 but smaller than 1. Spice does not supportperfect coupling (k=1). The above statement must always be together with thestatements for the two inductors. An example is given in the figure below. Thecoupling coefficient K can be calculated as K=M/sqrt(L1xL2)=0.81.

  • 8/6/2019 Spice 1

    7/27

    The SPICE statements to define the above coupled coils are as follows.

    L1 3 5 10M

    L2 4 7 3M

    K L1 L2 0.81

    The DOTS are always associated with the first node of the inductances (i.e. nodeno. 3 of L1 and no. 4 of L2). Also SPICE will assign the positive node voltage to thefirst node of the inductance (i.e. the DOT) and use the passive sign convention forthe current direction as indicated in the figure above. For an example circuit see

    under the section Examples.

    f. Ideal Transformer

    SPICE has no model for an ideal transformer. An ideal tranformer is simulatedusing mutual inductances such that the transformer ratio N1/N2 = sqrt(L1/L2).Make the coupling factor K close to one (ex. K=0.99999) and choose L such thatwL >> the resistance seen be the inductor. The secondary circuit needs a DCconnection to ground. This can be accomplished by adding a large resistor toground or giving the primary and secondary circuits a common node

    g. Sinusoidal sources

    Vname N1 N2 SIN(VO VA FREQ TD THETA PHASE)

    which is a damped sinusoidal voltage source:

    Vname = VO + VA exp-THETA.(t - TD) sin[2f (t - TD) + (Phase/360)]

    Where:

    VO - offset voltage in volt.VA - amplitude in volt.f = FREQ - the frequency in herz.TD - delay in secondsTHETA - damping factor per secondPhase - phase in degrees

  • 8/6/2019 Spice 1

    8/27

    If TD, THETA and PHASE are not specified, it is assumed to be zero.

    Example:

    VG 1 2 SIN(5 10 50 0.2 0.1)

    VG2 3 4 SIN(0 10 50)

    The last example is an undamped, undelayed sinusoid with an amplitude of 10Vand frequency of 50 Hz.

    To generate a cosine function, you can make use of the phase relationshipbetween the sinusoid and cosine. Here is an example of an undelayed cosine withan amplitude of 5V and frequency of 50 Hz.

    Vcos 1 2 SIN(0 5 50 0 0 45)

    h. Piecewise linear source (PWL)

    Vname N1 N2 PWL(T1 V1 T2 V2 T3 V3 ...)

    in which (Ti Vi) specifies the value Vi of the source at time Ti

    Example:

    Vgpwl 1 2 PWL(0 0 10U 5 100U 5 110U 0)

    i. Pulse

    Vname N1 N2 PULSE(V1 V2 TD Tr Tf PW Period)

    V1 - initial voltage; V2 - peak voltage; TD - initial delay time; Tr - rise time; Tf - falltime; pwf - pulse-wise; and Period - period.

  • 8/6/2019 Spice 1

    9/27

    Other sources such as polynominal controlled source, exponential source, FM-modulated source, etc. can be specified. For information on these components,check the SPICE manual.

    j. Voltage- and Current-controlled Switches

    Voltage Controlled:Sname N1 N2 C1 C2 Mname

    Current Controlled:Wname N1 N2 Vname Mname

    Where:N1 and N2 are the terminals of the switch.C1 and C2 are the controlling terminals.Vname is the zero-value voltage source whose current controls the switch.Mname refers to the switch model that is defined in another statement (see ModelStatement below).

    The .MODEL statement allows you to specify the parameters of a variety ofdevices used in SPICE, such as switches, diodes, transistors. In case of a switch,we have:

    .MODEL Mname Dname(Pvalues)

    Where:

    Mname refers to the Mname in the data statement of the switch.Dname is the device name: Vswitch or Iswitch.Pvalues are the values of the switch parameters, such as RON (on - resistance),ROFF (off-resistance), VON (the control voltage for ON; default = 1V), VOFF(control voltage for OFF; default = 0V), etc.

    Example:

    S15 3 5 8 9 SMOD

    .MODEL SMOD VSWITCH(RON = 10, VON = 0, ROFF = 100MEG)

  • 8/6/2019 Spice 1

    10/27

    k. Operational Amplifiers, and other elements

    An operational amplifier can be simulated in different ways. The first method is tomodel the amplifier by resistors, capacitors and dependent sources. As anexample an ideal opamp is easily simulated using a voltage dependent voltage

    source. The second option uses actual transistors to model the opamp. The devicelibrary contains nonlinear models of the most common op amps. The studentversion of PSpice has macromodels for the linear amplifiers LM324 and uA741which are included in the EVAL.LIB file. The professional version comes withlibrary files of many commercial amplifiers and devices.

    An example of the first approach (linear AC model) is given below for the uA741opamp. We defined a subcircuit for the opamp.

    SPICE code for the 741 opamp (ref: Macromodeling with Spice, by J.A.Connelly/P. Choi)

    * Subcircuit for 741 opamp

    .subckt opamp741 1 2 3

    * +in (=1) -in (=2) out (=3)

    rin 1 2 2meg

    rout 6 3 75

    e 4 0 1 2 100k

    rbw 4 5 0.5meg

    cbw 5 0 31.85nf

    eout 6 0 5 0 1

    .ends opamp741

    l. Subcircuits

    A subcircuit allows you to define a collection of elements as a subcircuit (e.g. anoperational amplifier) and to insert this description into the overall circui (as youwould do for any other element).

    Defining a subcircuit

    A subcircuit is defined bu a .SUBCKT control statement, followed by the circuit

    description as follows:

    .SUBCKT SUBNAME N1 N2 N3 ...

    Element statements

    .

    .

    .

    .ENDS SUBNAME

  • 8/6/2019 Spice 1

    11/27

    in which SUBNAME is the subcircuit name and N1, N2, N3 are the external nodesof the subcircuit. The external nodes cannot be 0. The node numbers used insidethe subcircuit are stricktly local, except for node 0 which is always global. For anexample, see Operational Amplifier above.

    Using a subcircuit

    The element statement for a subcircuit is similar to any other element. The formatis as follows:

    Xname N1 N2 N3 ... SUBNAME

    in which Xname refers to the element (subcircuit) being used; N1, N2, N3 are thenodes to which the external nodes of the subcircuit are being connected, andSUBNAME is the name of the subcircuit being used.

    An example of an inverting opamp circuit using the subcircuit of the the uA741 (seeoperational amplifiers above) is given below. The subcircuit is called x1.

    vs 1 0 dc 5

    r1 1 2 200

    rf 2 3 1k

    x1 0 2 3 opamp741

    .dc vs 0 10 1

    .plot dc v(3)

    .end

    m. Semiconductor Devices

    Most of the elements that have been described above require only a fewparameters to specify its electrical characteristics. However, the models forsemiconductor devices require many parameter values. A set of device modelparameters is defined in a separate .MODEL statement and assigned a uniquename. This method alliaviates the need to specify all of the model parameters oneach device element card. Thus a semiconductor device is specified by twocommand lines: an element and model statement.The syntax for the model statement is:

    .MODEL MODName Type (parameter values)

    MODName is the name of the model for the device. The Type refers to the type ofdevice and can be any of the following:

    D: Diode

    NPN: npn bipolar transistor

    PNP: pnp bipolar transistor

  • 8/6/2019 Spice 1

    12/27

  • 8/6/2019 Spice 1

    13/27

    .model Q2N2222A NPN (IS=14.34F XTI=3 EG=1.11 VAF= 74.03

    BF=255.9 NE=1.307 ISE=14.34F IKF=.2847 XTB=1.5 BR=6.092

    NC=2 ISC=0 IKR=0 RC=1 CJC=7.306P MJC=.3416 VJC=.75 FC=.5

    CJE=22.01P MJE=.377 VJE=.75 TR=46.91N TF=411.1P ITF=.6

    VTF=1.7 XTF=3 RB=10)

    m3. MOSFETS

    Element:Mname ND NG NS &ltNB> ModName L= W=

    The MOS transistor name (Mname) has to start with a M; ND, NG, NS and NB arethe node numbers of the Drain, Gate, Source and Bulk terminals, respectively.ModName is the name of the transistor model (see further). L and W is the length

    and width of the gate (in m).

    The above paramters are usually sufficient when specifying discrete transistors.However, for integrated circuit simulations one need to specify several otherparameter values related to the transistor geomtry. These are optional.

    Mname ND NG NS NB ModName &ltL=VAL> &ltW=VAL> &ltAD=VAL>

    &ltAS=VAL> &ltPD=VAL> &ltPS=VAL> &ltNRD=VAL> &ltOFF>

    &ltIC=VDS.VGS.VBS>

    in which

    AD and AS are the area of source and drain diffusion (in sq. m).PD and PS are the value (in m) of the perimeter of the source and drain.NRD is the number of squares of the drain diffusion for resistance calculations.OFF sets the starting condition to OFF.The initial condition specification using IC=VDS, VGS, VBS is intended for use withthe UIC option on the .TRAN card, when a transient analysis is desired startingfrom other than the quiescent operating point. See the .IC card for a better andmore convenient way to specify transient initial conditions.

    Model statement:

    .MODEL ModName NMOS (KP= VT0= lambda= gamma=)

    in which KP=uCox and VTO is the threshold voltage. The default values areKP=20uA/V2; and the rest is equal to 0. There are several other transistorparameters that can be specified, in particular when doing simulations of integratedcircuits. The general form of the .MODEL statement is as follows:

    .MODEL ModName NMOS (&ltLEVEL=val> &ltkeyname=val> ... )

  • 8/6/2019 Spice 1

    14/27

    .MODEL ModName PMOS (&ltLEVEL=val> &ltkeyname=val> ... )

    LEVEL refers to the MOSFET model that describes the terminal I-V characteristicsof the transistors. LEVEL 1 is the simplest Mosfet model and is in general sufficientfor describing discrete transistors as is done in the EE216 and EE319 courses.

    However to simulate integrated circuit transistors, one need to use a moresophisticated models. LEVEL 2 includes extensive second-order models, whileLEVEL 3 is a semi-empirical model that is better suited for short-channeltransistors. Another model that is especially suited to model short-channel effectsis called the BSIM model (LEVEL 13 in HSpice).

    m4. JFETS

    Element line:Jname ND NG NS ModName

    ND, NG, and NS are the node numbers of the Drain, Gate, and Source terminals,respectively. ModName is the name of the transistor model

    Model statement:.MODEL ModName NJF (parameter= ).MODEL ModName PJF (parameter= )

    for the N-JFET and P-JFET respectively. A partial list of the parameters that can bespecified is: VT0 (threshold voltage, -2V default for N_JFET), BETA(transconductance coefficient, 1E-4 A/V2), LAMBDA (channel length modulation, 0/V), IS (gate p-n saturation current, 1E-14A), CGD and CGS (drain and source

    zero-bias junction capacitances, 0pf), RD and RS (drain and source ohmicresistances, 0 Ohm).

    2.2 Commands or Control Statements to Specify the Type ofAnalysis

    a. .OP Statement

    This statement instructs Spice to compute the DC operating points:

    voltage at the nodes

    current in each voltage source

    operating point for each element

    In PSpice it is usually not necessary to specify .OP as it gives you automaticallythe DC node voltages. However, HSpice does not give the DC voltages unless youhave specified a certain analysis type, such as for instance .TRAN, or .AC analysis(Spice automatically does a DC analysis before doing a transient or AC analysis).Thus, if you are only interested in the DC voltages in HSpice, you should specifythe .OP option, or the .DC option (see further).

  • 8/6/2019 Spice 1

    15/27

    b. .DC Statement

    This statement allows you to increment (sweep) an independent source over acertain range with a specified step. The format is as follows:

    .DC SRCname START STOP STEP

    in which SRC name is the name of the source you want to vary; START and STOPare the starting and ending value, respectively; and STEP is the size of theincrement.

    Example:.DC V1 0 20 2

    When the Start and Stop values are identical (and the Step is non-zero), the .DCcommand produces only one value. This may be usefull in HSpice when you do

    not want all the DC voltages and currents to be printed (with the .OP option), butare interested in a limited number of DC voltages and currents. In the .PRINTstatement (see further) you would then also specify the node voltages you like toknow (ex. .DC Vs 3 3 1 and .PRINT DC V(2), V(3), I(Vmeas) ).

    You can nest the DC sweep command which is often used to plot transistorcharacteristics, such as the Drain current ids versus the Drain-source voltage Vdsfor different gate voltages Vgs. This can be done as follows:

    .DC SRCname1 START STOP STEP SRCname2 START STOP STEP

    Example:.DC Vds 0 5 0.5 Vgs 0 5 1

    In the example above, the voltage Vds will be swept from 0 to 5V in steps of 1V forevery value of Vgs.

    c. .TF Statement

    The .TF statement instructs PSpice to calculate the following small signalcharacteristics:

    the ratio of output variable to input variable (gain or tranfer gain) the resistance with respect to the input source

    the resistance with respect to the output terminals

    .TF OUTVAR INSRC

    in which OUTVAR is the name of the output variable and INSRC is the inputsource.

  • 8/6/2019 Spice 1

    16/27

    Example:.TF V(3,0) VIN

    The .TF statement can be used to find the Thevenin small signal equivalentresistance. (The Thevenin voltage is given by the node voltage at the open circuitterminal, as a result of the .OP statement). See also Output Statements later on.

    d. .SENS Statement

    This instructs PSpice to calculate the DC small-signal sensitivities of each specifiedoutput variable with respect to every circuit parameter.

    .SENS VARIABLE

    Example:.SENS V(3,0)

    e. .TRAN Statement

    This statement specifies the time interval over which the transient analysis takesplace, and the time increments. The format is as follows:

    .TRAN TSTEP TSTOP

    TSTEP is the printing increment.TSTOP is the final timeTSTART is the starting time (if omitted, TSTART is assumed to be zero)TMAX is the maximum step size.UIC stands for Use Initial Condition and instructs PSpice not to do the quiescentoperating point before beginning the transient analysis. If UIC is specified, PSpicewill use the initial conditions specified in the element statements (see datastatement) IC = value.See also Output Statements later on.

    f. .IC Statement

    This statement provides an alternative way to specify initial conditions of nodes(and thus over capacitors).

    .IC Vnode1 = value Vnode2 = value etc.

  • 8/6/2019 Spice 1

    17/27

    g. .AC Statement

    This statement is used to specify the frequency (AC) analysis. The format is asfollows:

    .AC LIN NP FSTART FSTOP

    .AC DEC ND FSTART FSTOP

    .AC OCT NO FSTART FSTOP

    in which LIN stands for a linear frequency variation, DEC and OCT for a decadeand octave variation respectively. NP stands for the number of points and ND andNO for the number of frequency points per decade and octave. FSTART andFSTOP are the start and stopping frequencies in Herz

    Example:

    .AC DEC 10 1000 1E6

    See also Output Statements later on.

    2.3 Output Statements

    These statements will instruct PSpice what output to generate. If you do not specifyan output statement, PSpice will always calculate the DC operating points. The twotypes of outputs are the prints and plots. A print is a table of data points and a plotis a graphical representation. The format is as follows:

    .PRINT TYPE OV1 OV2 OV3 ...

    .PLOT TYPE OV1 OV2 OV3 ...

    in which TYPE specifies the type of analysis to be printed or plotted and can be:

    DC

    TRAN

    AC

    The output variables are OV1, OV2 and can be voltage or currents in voltagesources. Node voltages and device currents can be specified as magnitude (M),

    phase (P), real (R) or imaginary (I) parts by adding the suffix to V or I as follows:

    M: MagnitudeDB: Magnitude in dB (deciBells)P: PhaseR: Real partI: Imaginary part

  • 8/6/2019 Spice 1

    18/27

    Examples:

    .PLOT DC V(1,2) V(3) I(Vmeas)

    .PRINT TRAN V(3,1) I(Vmeas)

    .PLOT AC VM(3,0) VDB(4,2) VM(2,1) VP(3,1) IR(V2)

    3. HOW TO GET STARTED WITH SPICE? (for beginners)

    This document will explain how to run Spice or HSpice. It does not explain theSpice commands. This can be found earlier in this document under How to Specifythe Circuit Topology?, in your textbook, or the Spice User's Guide.

    In order to run Spice, you will have to go through the following steps:

    Draw a schematic of the circuit (can be skipped)

    Create an input fileRun the programLook at the output file and print the results

    3.1 Creating an Input File for Spice - Example

    a. Draw a schematic of the circuit,:

    number the nodes and label all elements. Note that the common node (ground)always has number "0".

    A sample circuit is given below.

    We are interested in the voltages v12, v2 and the current i4 when the input voltagevin is equal to 10V. We also want to find the Thevenin equivalent voltage andresistance seen by the terminals ab.

    In addition, we like to step the input voltage between 0 and 20 V in steps of 2V andprint and plot v12, vo, v2 and i4 as a function of vin.

    Note that we inserted a DC voltage source, VMEAS, of zero value, in order to beable to measure the current i4.

  • 8/6/2019 Spice 1

    19/27

    b. Create the input file (source file) for PSpice.

    The source file needs the extension (usually ".cir") in its name. For a description of

    the data, control and output statement, refer to "How to Specify the CircuitTopology" earlier in this document, the Spice manual or the textbook.

    Create the input file with any editor, such as Emacs, Microsoft editor, Word perfect,NotePad under windows, etc. Save it on the c: drive or on your disk on the a: drive.In case you store it on the c: drive, put it in a subdirectory (ex. c:\users\filename.cir;the subdirectory is required for the PSpice version that runs on the network in thePC labs and sits on the h: drive). Save the file as a textfile (when using a wordprocessor such as MS Word).

    EXAMPLE PSpice

    VIN 1 0 DC 10F1 0 3 VMEAS 0.5

    VMEAS 4 0 DC 0

    R1 1 2 1K

    R2 2 3 10K

    R3 1 3 15K

    R4 2 4 40K

    R5 3 0 50K

    .OP

    .TF V(3,0) VIN

    .DC VIN 0 20 2

    .PRINT DC V(1,2) V(2,4) I(VMEAS)

    .PLOT DC V(1,2) V(2,4)

    .PLOT DC I(VMEAS)

    .END

    Notes:

    1. The first line is a title line and can be anything. It cannot be omitted.2. The last line must be the .END statement.3. You can insert comment lines. Anytime a line starts with an "*", PSpice

    ignores the whole line. Using an "*" is also handy to block out a commandline.

    4. You can use upper or lower case letters.5. Don't forget to add a carriage return after the .END statement.

    c. Run Spice

    Once you are in PSpice, pull down the File menu at the top of the screen andselect "Open ". The system prompts you for the name of the file. Type in the filename of the circuit you have created before. As an example: c:\users\example1.cir

  • 8/6/2019 Spice 1

    20/27

  • 8/6/2019 Spice 1

    21/27

    * the voltages v12, v2, vo and the current i4.

    * ------------------------------------------------------

    VIN 1 0 DC 10

    F1 0 3 VMEAS 0.5

    VMEAS 4 0 DC 0

    *VMEAS is a 0V source to measure i4

    R1 1 2 1K

    R2 2 3 10K

    R3 1 3 15K

    R4 2 4 40K

    R5 3 0 50K

    .OP

    * --------------------------------------------------

    * The operating point .OP command will tell Spice

    * print all DC node voltages, currents through voltage

    * sources and voltages over current sources.

    * --------------------------------------------------

    .TF V(3,0) VIN* --------------------------------------------------

    * The .TF statement tells Spice to calcuate the ratio of

    * Vout/Vin and the resistance seen at the terminals of

    * Vout=V(0,3) and Vin (corresponding to the output and

    * input resistances). This statement is used to

    calculate

    * the Thevenin equivalent circuit.

    * --------------------------------------------------

    .DC VIN 0 20 2

    * --------------------------------------------------

    * The .DC statement instructs Spice to sweep the voltagesource

    * Vin from 0 to 20 V in steps of 2V.

    * --------------------------------------------------

    .PLOT DC V(1,2) V(2,4)

    .PLOT DC I(VMEAS)

    * --------------------------------------------------

    * The above Plot statement instruct Spice to plot the

    * node voltages and current in the Vmeas voltage source,

    * obtained as a results of the DC sweep.

    * --------------------------------------------------

    .END

    5.2 Mutual Inductor

    The syntax for a mutual inductance is as follows:

    Kname Inductor1 Inductor2 value_of_K

  • 8/6/2019 Spice 1

    22/27

    In which K is the value of the coupling coefficient that determine the mutalinductance: M=K.sqrt(L1xL2). An example of a complete SPICE file for the circuitgiven below follows.

    (K=M/sqrt(L1xL2)=0.80)

    Example MInductor

    Vin 1 0 sin(0 5 159.15 0 0)

    Rs 1 3 100

    Rl 4 0 500

    L1 3 0 10M

    L2 4 0 2MK L1 L2 0.80

    .TRAN 0.1M 10M

    .PRINT TRAN V(3) V(4)

    .PLOT TRAN V(3) V(4)

    .END

    Remarks:

    1. SPICE always needs a reference node numbered 0. One can never leaveany node floating. For that reason we have connected the two coils together

    to node 0 (or put a large resistor between it). As there is no current flowingthrough this section, the circuit will not change by connecting these nodes.

    2. SPICE does not allow to connect a voltage source in parallel with aninductor, as it thinks that the voltage source is short circuited. You can placea small resistor (ex. 0.001 Ohm) in series with the voltage source toovercome this problem.

    5.3 Ideal Transformer

    An ideal transformer can be simulated using mutually coupled inductors. An idealtransformer has a coupling coefficient k=1 and very large inductances. However,

    Spice does not allow a coupling coefficient of k=1. The ideal transformer can besimulated in Spice by making k close to one, and the inductors L1 and L2 verylarge, such that wL1 and wL2 is much larger than the resistors in series with theinductors. The secondary circuit needs a DC connection to ground. This can beaccomplished by adding a large resistor to ground or giving the primary andsecondary circuits a common node.

    The following example illustrates how to simulate a transformer.

  • 8/6/2019 Spice 1

    23/27

    For the above example, lets make wL2 >> 500 Ohm or L2> 500/(60*2pi) ; letsmake L2 at least 10 times larger, ex. L2=20H. L1 can than be found from the turnratio: L1/L2 = (N1/N2)^2. For a turn ratio of 10 this makes L1=L2x100=2000H. Wemake K close to 1 lets say 0.99999.

    A Spice input listing is given below for the following circuit.

    Example transformer

    VIN 2 0 SIN(0 170 60 0 0)

    * This defines a sinusoid of 170 V amplitude and 60 Hz.

    RS 2 1 10

    L1 1 0 2000

    L2 3 0 20

    K L1 L2 0.99999

    RL 3 0 500

    .TRAN 0.2M 25M

    .PLOT TRAN V(2)

    .PLOT TRAN V(3)

    .END

    5.4 Filter Circuit (.AC Analysis)

    This is an example of a first order filter and the use of the AC analysis to find thefrequency response of the magnitude and phase of a transfer function.

  • 8/6/2019 Spice 1

    24/27

    The Spice input file is given below. The opamp has been modeled as a voltagecontrolled voltage source (gain of 1E8), infinite input resistance and zero outputresistance (ideal opamp). The input voltage V1 has a value of 1V so that the ACplot of the output voltage v(3) corresponds to the transfer function T(jw)=Vo/V1

    Example AC Analysis

    v1 1 0 ac 1

    r1 1 2 10k

    r2 2 3 100k

    c 2 3 10n

    e1 3 0 0 2 1e8

    .ac dec 10 1 1e4

    .plot ac vdb(3)

    .plot ac vp(3)

    .end

    5.5 Rectifier Circuit (with diodes)

    A diode is specified by using two command lines. The first line defines the diodeelement line and the second one is the diode model.

    Element line:

    Dname N+ N- MODName

    The element name start with D to indicate that the element is a diode, N+ and N-are the two node numbers and MODName is the name of the model of the diodewhich is specified in the model line.

    Model line: .

    MODEL MODName D (IS=value N=value)

    MODName is the same name as in the element line. D indidate the the model is adiode (as opposed to a transistor), and IS is the saturation current IS and N is theideality factor.

    Lets simulate the following rectifier circuit to illustrate this. The diodes have aIS=0.01pA and n=1.

  • 8/6/2019 Spice 1

    25/27

    rectifier example

    vin 2 0 sin(0 170 60 0 0)

    rl 5 0 500

    rs 2 1 10

    L1 1 0 2000

    L2 3 0 20

    K1 L1 L2 0.99999

    D1 3 5 mod1

    .model mod1 D (IS=1e-14, n=1)

    .tran 0.2m 20m

    .plot tran v(3), v(5)

    .end

    5.6 Transistor Circuit (NPN)

    All semiconductor devices are specified by using two command lines. The firststatement defines the elementand the second one is the modelstatement.

    The syntax for the model statement is:

    .MODEL MODName Type (parameter values)

    MODName is the name of the model for the device.. The Type refers to the type ofdevice and can be any of the following:

    NPN: npn bipolar transistorPNP: pnp bipolar transistorNMOS: nmos transistorPMOS: pmos transistor

    The parameter values specify the device characteristics as explained below.

    Bipolar transistors

    Element:

    Qname C B E BJT_modelName

  • 8/6/2019 Spice 1

    26/27

    The bipolar transistor's name has to start with a Q

    Model statement:

    .MODEL BJT_modName NPN (BF=val IS=val VAF=val)

    in which BF is the , IS is the saturation current and VAF is the Early voltage. If novalues are specified, the default values are assumed (=100; IS=1e-16A, andVAF=infinite).

    MOSFETS

    Element:

    Mname D G S B ModName L= W=

    The MOS transistor's name has to start with a M

    Model statement:

    .MODEL ModName NMOS (KP= VT0= lambda= gamma=)

    in which KP=uCox. The default values are KP=20uA/V2; and the rest is equal to 0.

    Example of a NPN Transistor Amplifier

    Consider the circuit of the figure below. We are interested in finding the DC

    voltages and current, as well as the voltage gain and the input resistance seen bythe input source.

    Example of a NPN transistor

    vin 1 0 ac 1

    rs 1 2 1

    c1 2 3 100uf

    rb 5 3 465k

    rc 5 4 3k

    vcc 5 0 dc 10

    q1 4 3 0 npn-trans

  • 8/6/2019 Spice 1

    27/27

    .model npn-trans npn (is=2e-15 bf=100 vaf=200)

    *calculation of the operating point and small signal

    parameters

    .op

    *calculation of the small signal gain

    .ac dec 10 100 10k

    .plot ac vm(4)

    * cacluations of the small signal input conductance

    (i/v)

    .plot ac im(vin)

    .end