UC Berkeley SPICE3 Tutorial



Tien-Cheng Bau

Samiha Mourad

Electrical Engineering Department

Date of last revision: 02/21/2000

Index:

  1. Introduction
  2. Preparation
  3. Editing SPICE source code
  4. Starting SPICE3
  5. Saving the result of analysis
  6. Using the results of a previous analysis
  7. Printing and Plotting


1. Introduction

SPICE is a general-purpose circuit simulation program for nonlinear dc, nonlinear transient, and linear ac analyses. Circuits may contain passive components (resistors, capacitors, inductors), active devices (transistors and diodes), and independent voltage and current source..., etc. In this tutorial, we will illustrate the use of the simulator with a CMOS inverter as shown in Fig.1 below.

In this figure, there are two transistors of the same dimensions, L = 1.2 u and W=3.6U and their gates are connected together at node #2.:

Node #0 is connected to ground, Node #1 is connected to the supply voltage, VCC, Node #2 is connected to the input, in, and node #3, the output and is connected to a load capacitance of 10P farads. This load represents the input capacitance of any other gate that is driven by the inverter and the value is arbitrarily chosen.

Figure 1. CMOS inverter transistors schematic


click here to back to Index:


2. Preparation


click here to back to Index:


3. Editing SPICE source code

  1. Use any text editor to enter the example SPICE source code file listed below for DC Sweep and transient time analysis:
  2. The first line of SPICE source code is the title line and will be ignored by Spice compiler. You may leave it blank , but it is preferable that you use it to identify your circuit.

    Any subsequent line that starts with a black space of a * will be treated as remark line. Be careful !!

    In the third line, M1 is the name given to the pch transitor shown in the Fig. 1. This is followed by the node numbers of the drain, gate, source and substrate of the transistor in this specific order. Thus node #3 refers to the drain, node #2 is the gate and node #1 connects the source and the substrate to the supply voltage VCC. These node numbers are exactly the same as shown in Fig. 1. Then PCH indicates that transistor M1 is of p-channel model defined on later in the files. In a similar fashion, the drain, gate, and source of the nch, M2, are connected respectively to #3, #2 and #0. The latest node is the ground. NCH refers to the model of this transistor. The other entries give the width and length of the channel. The next line describes how the load capacitance, C3, is connected accross the output, node #3 and ground, node #0.

    Next the voltage sources are defined. VCC 1 0 DC=5.0, tell us that a DC source of 5V is applied accross node #1 and ground. Also, a voltage, VIN is applied at the gates of the transistors, node #2. The value of this source is then specified on the next line. VIN takes DC values between 0 and 5V in increments of 0.1V. This specification is for the DC sweep.

    the lines starting with .MODEL define the transistor models, PCH and NCH. The example uses SPICE level 2. You may substitute this level by any other one. Some of the parameter used are the threshold voltage, the process transconductance, etc.

    * CMOS Inverter Voltage Transfer Characteristic

    *

    M1 3 2 1 1 PCH W=3.6U L=1.2

    M2 3 2 0 0 NCH W=3.6U L=1.2U

    C3 3 0 10P

    *

    VCC 1 0 DC=5.0

    * The following two line are for DC analysis

    VIN 2 0

    .DC VIN 0 5 0.1

    *

    .OPTIONS TEMP=25 METHOD=GEAR

    .MODEL NCH NMOS (level=2 LD=0.15U TOX=200.0E-10 NSUB=5.37E+15

    + VTO=0.74 KP=8.0E-05 GAMMA=0.54 PHI=0.6 U0=656 UEXP=0.157 UCRIT=31444

    + DELTA=2.34 VMAX=55261 Xj=0.2U LAMBDA=0.037 NFS=1E+12 NEFF=1.001 NSS=1E+11

    + TPG=1.0 RSH=70.00 + CGDO=4.3E-10 CGSO=4.3E-10 Cj=0.0003 Mj=0.66

    + CJSW=8.0E-10 MJSW=0.24 PB=0.58

    .MODEL PCH PMOS(level=2 LD=0.15U TOX=200.0E-10 NSUB=4.33E+15

    + VTO=-0.74 KP=2.70E-05 GAMMA=0.58 PHI=0.6 U0=262 UEXP=0.324 UCRIT=65720

    + DELTA=1.79 VMAX=25694 Xj=0.25U LAMBDA=0.061 NFS=1E+12 NEFF=1.001 NSS=1E+11

    + TPG=1.0 RSH=121.00 + CGDO=4.3E-10 CGSO=4.3E-10 Cj=0.0005 Mj=0.51

    + CJSW=1.35E-10 MJSW=0.24 PB=0.64

    .END

    Frr transient analysis , substitute the 'VIN 2 0' and '.DC VIN 0 5 0.1' with the following two statements where PWL stands for piecewise linear signal and

    Vin 2 0 PWL(0 0 4N 0 4.1N 3 8N 3 8.1N 0)

    .TRAN 0.1N 12N

  3. Save this example SPICE source code as "example.cir"


click here to back to Index:


4. Starting SPICE3

  1. To start the program and loading SPICE source code, type spice3 filename at the prompt sign $.
  2. For example, type

    $spice3 example.cir

    to start SPICE3 and load that example you have edited.

  3. On the screen you will see:
  4. Spice 1 ->

    which indicate that you are inside the SPICE interactive environment.

  5. Type listing to see the SPICE source code you have loaded.
  6. Type run to simulate that circuit described in that SPICE source code.
  7. If there is any error, type edit to invoke TEXT EDITOR to edit that SPICE source code. After you correct all the errors, don't forget to save it. Then exit the TEXT EDITOR, the message displayed:
  8. running circuit ? --respond with y or n.

  9. Type plot v(node1) vs v(node2) for DC analysis plot.
  10. In this example, type:

    plot v(3) vs v(2)

    will get the graph as shown in Fig. 2.

    Figure 2. Plot for DC analysis

  11. For current vs. input voltage diagram, type :
  12. plot i(VCC) vs v(2)

    you will get the graph as shown in Fig 2a.

    Figure 2a. IV curve for inverter

  13. For time transient analysis, type plot v(node1),v(node2)... to plot node voltage versus time diagram.
  14. In this example, type:

    plot v(3)

    will plot the Voltage versus Time diagram of node 3 on the screen as shown below.

    Figure 3. Plot for time transient analysis while type :

    plot v(3),v(2)

    will plot the Voltage versus Time diagram of node 3 and 2 on the same graph window as shown below.

    Figure 4. command using plot v(3),v(2)

  15. For power analysis, type:
  16. plot v(3)*abs(i(vcc))

    Figure 4a. Power analysis


click here to back to Index:


5. Saving the results of analysis

  • Once you have performed your analysis, you will want to save all or some of the results to a file, so that you can print or plot them, or to perform some new analysis. There are two data types can be saved, one is numerical data, another is plot data.
    1. To save the numerical data, you have to set the output data format first by typing :
    2. set filetype=ascii

      Thereafter, all the numerical data will be save in ASCII format. Then type:

      write filename expression

      to save the numerical data. (DO NOT USE THE SAME NAME AS THE SPICE SOURCE CODE FILE, OR IT WILL BE OVERWRITTEN). The expression define the variable you want to be saved. If you omit it, all variable will be saved.

      For example, if you want to save the analysis of node 3 to a file named node3.result, type:

      write node3.result v(3)

      If you want to save all the analysis of all the node to node_all.result , type:

      write node_all.result

    3. To save the plot graph data, you have to check your printer's type first (or later the printer won't be able to print the graph out), you should set first the output file format to postscript (for HP laser jet printer):
    4. set hcopydevtype=postscript

      then save the graph :

      hardcopy filename

      hardcopy filename

      after this you will get the message:

      which variable ?

      type the variable you want the plot to be saved.(e.g.v(3),vdb(3),vp(1)).

      For more variables on the same graph, say v(3) and v(2), type:

      hardcopy all.plot v(3) v(2)

      The plots of v(3) and v(2) will be saved in a file called all.plot.


    click here to back to Index:


    6. Using the results of a previous analysis

  • To use the result of the previous analysis, all you have to do is to load the file which contain the saved results:
  • load filename

    For example, if you want to load the results saved in file node3.result, type:

    load node3.result

    the reuslt will be loaded. You may use plot v(3) to see the graph.


    click here to back to Index:


    7. Printing and Plotting

  • For printing or plotting your results, you can use the Design Center printing facilities which include dot matrix printers (queues dm1 and dm2) which you should use for your numerical results and laser jet printer (queues laser ) for the plots.
  • Printing is performed through the Open Spool facility. You have to exit SPICE using the quit command, and return to the UNIX environment to print and plot. (DO NOT FORGET TO SAVE YOUR RESULTS PRIOR TO THIS, OR YOU WILL NOT BE ABLE TO PRINT/PLOT THEM)

    1. For printing your numerical results from the file where they were saved, you have to make sure first that file is in ASCII format, (or the print out will be a totally messy. Refer to 5.Saving the results of analysis to see how to save it in ASCII format) ,and then type the following:
    2. lp -d laser filename

      lp -d laser filename

      In this example, you may type as following to print out your numerical results.

      np -q dm1 node3.result

      or

      lp -d laser node3.result

    3. For plotting the previously saved graphs, you should first make sure your graphic file is in postscript format, or the printer won't be able to print it out, (refer to 5.Saving the results of analysis to see how to save it in postscript format) ,and then type:
    4. lp -d laser filename

      In this example, you may type :

      lp -q laser node3.plot

      For any further question or problems you can refer to the SPICE Manual that is available in the Design Center.


      click here to back to Index:


      Click here to go to 'VLSI Design Flow Using Mentor-Graphics Tools'

      Click here to go to the main Helpme menu.