For translation in

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

(URL: http://www.seas.upenn.edu/~jan/spice/spice.guide.html)

This document will explain how to run Spice or HSpice. It does not explain the Spice commands. This can be found earlier in this document under How to Specify the 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:

3.1 Creating an Input File for Spice - Example

We will first explain how to use PSpice without a Schematic Editor (see PSpice Primer for how to use the Schematic Editor).

a. Draw a schematic of the circuit, number the nodes and label all elements. Note that the common node (ground) always has number "0".

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

In addition, we like to step the input voltage between 0 and 20 V in steps of 2V and print 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 be able to measure the current i4.

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 Circuit Topology" 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 the PC labs and sits on the h: drive). Save the file as a textfile (when using a word processor such as MS Word).

Notes: c. Run Spice

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

A window will appear telling you that Spice program is running, or that the simulation has been completed successfully, or that errors were detected. Click on the "OK" button.

PSPICE with Capture


5. HSPICE

5.1 Running HSPICE

You can run HSPICE on Eniac (Sun Sparc), which is basically the same program as PSpice, except for the Schematic editor and Probe. The advantage of using HSpice on Eniac is that you can run it from your room through a modem connection or over ResNet. In addition, it comes with a user-friendly and powerful graphical interface (gsi) provided you have access to an x-terminal.

First, you have to create the input file that contains the data, control and output statements in the same way as is done for PSpice. The format and commands are identical. You can create this input file with any editor. Once you have the input file, you can run HSpice by typing the following command at the unix prompt,

in which inputfile is the name of your input file. The output will be displayed on the screen. You can also store the output of HSPice in an output file, as follows, To view the output file, use your favorite editor. The file can be printed as any other document: Notice that HSpice does not give the DC voltages unless you have 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 specify the .OP option, or the .DC option.

5.2 Special Features of HSPICE

HSpice has many capabilities. If you intend to use HSpice for Integrated Circuits simulation you will need to make use of many of these. Please consult the MetaSoftware manual (available from the DSL, room 100M). Here are a couple of these features.

a .Mathematical expressions in Hspice

HSPICE supports a few mathematical functions which can be used to condition any output variable. The following general format should be used for all expressions:

This instructs HSPICE to print the square root of the voltage "v3" and assign it the variable name varname. The results can be found in the output file as well as gsi under the print'plot field. Apart from square root, other useful functions such as log(), sin() and tan() are supported. Consult the HSPICE manual for a complete listing.

b. Node Names.

Instead of using node numbers, you can use node names in the input file. This makes the files much easier to read. The same names will appear in the output file and the graphical display.

5.3 Graphical Output: gsi

In case you have access to an x-window terminal the output can also be viewed graphically using the gsi program. In order to use the graphical display, you have to include the statement "option post" in the input file. This will create a *.sw# (for .sweep analysis) or a *.tr# file (for transient analysis) which contains the simulation results in a format that can be interpreted by gsi.

To run gsi, type "gsi inputfilename". All node voltages will be saved for later display. In case you have a large circuit and don't need to look at all the nodes, you can reduce the size of the file by specifying which node voltages to save. This is done by the ".option post probe", followed by the ".print nodenames" command. This last command is identical to the one you use to specify what node voltages, or currents you want Spice to save.

Here is an example of the input file, with the .option post command for gsi.

To see the graphical output, type gsi example1 (if on an x-window terminal; if you are not familiar with x-windows consult CETS). The gsi output is shown in the next figure. After typing "gsi", two windows will open.


 

The top one allows you to select what variables to display. After making the selection of the "type" of variables (voltages, current, etc.) and the "curves" to be displayed, click on the "Draw" button. The curves will be shown on the second window (Graph window).


 

You can select the number of panels by going to the "Panels" menu and selecting the number of panels. There are several option and manipulations you can incorporate (see Features of gsi below).

Features of gsi

In the Graph window you have a number of interesting options. The measurement menu allows you to use cursors. To zoom in/out click on the right mouse button and select one of the zoom commands. Then with the left button draw a short line to indicate what you would like to zoom.

To clear a panel, click on the right mouse button and select "Clear".

Printing can be done by going to the "Print" menu. The print command will write the graphical output to a file (labeled as filename.gr#)) which can then be printed later on (using the lpr command).

Mathematical expressions can be plotted as well. In the top window, you will see a small box called expression. You can type mathematical expressions such as additions, multiplications, square, etc. of graphs. As an example lets calculate the power in a resistor (power = i(vmeas)*v(2)). To display the expression, select expression in the "Types" window and "power" in the "Curves" window. Next, click on the "Draw" button.


6. Most common mistakes

  1. Typos in the source file: wrong node numbers, wrong units (ex. the value of a capacitor of 12 picofarad, incorrectly specified as 12, instead of 12p.)
  2. Confuse M for mega instead of MEG: a 5 megaohm resistor should be specified as 5MEG and not 5M. (M or m stands for milli).
  3. Typing the letter O instead for the number 0 (zero as in 10)
  4. Omitting the final carriage return after the .END statement.

7. If Spice does not run.

1. First check that /cad/bin is in your path. If not, you should alter the path to statement in your shell initialization file to include /cad/bin.).

2. To run hspice on eniac from an X-TERMINAL that runs on a computer different from eniac (lets say hobo in the EE domain):


8. REFERENCES

  1. SPICE, A Guide to Circuit Simulation and Analysis Using PSpice, 3rd Ed., P. Tuinenga, Prentice Hall, Upper Saddle River, NJ, 1995. This book comes with a IBM-PC 3.5 disk with the PSpice Student Version.
  2. Schematic Capture with MicroSim PSpice, 3rd Ed., Marc. E. Herniter, Prentice Hall, Upper Saddle River, N.J, 1998. This book comes with a CD that contains an evaluation version of PSpice.
  3. MicroSim PSpice with Circuit Analysis, 2nd Ed., F. Monssen, Prentice Hall, Upper Saddle River, NJ, 1998.
  4. MicroSim PSpice for Windows, Vol. I and II, R. W. Goody, Prentice Hall, Upper Saddle River, NJ, 1998.
  5. Spice for Circuits and Electronics Using PSpice, 2nd ed., M. H. Rashid, Prentice Hall, Englewood Cliffs, NJ, 1995. This book comes with a tear-out card to order a disk with the PSpice Student Version (available for both PC and MAC). The cost for the disk is about $7.50-$15.50
  6. Computer-Aided Circuit Analysis Using PSpice, 2nd Ed., W. Banzhaf, Prentice-Hall, Englewood Cliffs, NJ, 1992
  7. Hands On PSpice,"J.G. Gottling, Houghton Mifflin Co., MA, 1995
  8. The Spice Book, A. Vladimirescu, John Wiley & Sons, New York, NY, 1994
  9. Semiconductor Device Modeling with Spice, 2nd Ed., G. Massobrio and P. Antognetti, McGraw-Hill, NY, 1993
  10. Mosfet Modeling with Spice, D. Foty, Prentice Hall, Upper Saddle River, NJ, 1997.
  11. Macromodeling with Spice, J.A. Connelly/P. Choi, Prentice-Hall, Englewood Cliffs, NJ, 1992
  12. Inside SPICE, Overcoming the Obstacles of Circuit Simulation, R. M. Kielkowski, MacGraw-Hill, Inc., New York, 1994.
  13. SPICE, Practical Device Modeling, R. W. Kielkowski, McGraw-Hill, Inc., New York, 1995.
  14. Introduction to PSpice, A Supplement to Electric Circuits, 4th ed., by J. W. Nilsson and Susan A. Reidel, Addison-Wesley Publ. Company, Reading, MA, 1993
  15. Spice, by G. Roberts and A. Sedra, Oxford University Press, 1997, 2nd Edition.
  16. HSPice Users' Manual, Meta-Software, Inc., Campbell, CA
  17. PSpice Users' Guide, MicroSim Corporation, Irvine, CA
  18. SPICE User's Guide

  19.  

Back to Table of Contents
Jan Van der Spiegel
jan@ee.upenn.edu


Created Sept. 30, 1995; Updated Dec. 3, 2001