P Spice Primer
P Spice Primer
A brief primer
Contents
1. Introduction
2. Use of PSpice with OrCAD Capture
2.1 Step 1: Creating the circuit in Capture
2.2 Step 2: Specifying the type of analysis and simulation
BIAS or DC analysis
DC Sweep simulation
2.3 Step 3: Displaying the simulation Results
2.4 Other types of Analysis:
2.4.1 Transient Analysis
2.4.2 AC Sweep Analysis
3. Additional Circuit Examples with PSpice
3.1Transformer circuit
3.2AC Sweep of Filter with Ideal Op-amp (Filter circuit)
3.3AC Sweep of Filter with Real Op-amp (Filter Circuit)
3.4 Rectifier Circuit (peak detector) and the use of a parametric sweep.
Peak Detector simulation
Parametric Sweep
3.5 AM Modulated Signal
3.6 Center Tap Transformer
4. Adding and Creating Libraries: Model and Part Symbol files
4.1 Using and Adding Vendor Libraries
4.2 Creating PSpice Symbols from an existing PSpice Model file
4.3 Creating your own PSpice Model file and Symbol Parts
References
1. INTRODUCTION
SPICE is a powerful general purpose analog and mixed-mode circuit simulator that is used to
verify circuit designs and to predict the circuit behavior. This is of particular importance for
integrated circuits. It was for this reason that SPICE was originally developed at the
Electronics Research Laboratory of the University of California, Berkeley (1975), as its name
implies:
In addition, PSpice has analog and digital libraries of standard components (such as NAND,
NOR, flip-flops, MUXes, FPGA, PLDs and many more digital components, ). This makes it
a useful tool for a wide range of analog and digital applications.
All analyses can be done at different temperatures. The default temperature is 300K.
The circuit can contain the following components:
The following figure summarizes the different steps involved in simulating a circuit with
Capture and PSpice. We'll describe each of these briefly through a couple of examples.
U or Micro (= E-6);
N or Nano (= E-9);
P or Pico (= E-12)
F of Femto (= E-15)
Both upper and lower case letters are allowed in PSpice and HSpice. As an example, one can
specify a capacitor of 225 picofarad in the following ways:
225P, 225p, 225pF; 225pFarad; 225E-12; 0.225N
3
Notice that Mega is written as MEG, e.g. a 15 megaOhm resistor can be specified as
15MEG, 15MEGohm, 15meg, or 15E6. Be careful not to use M for Mega! When you write
15Mohm or 15M, Spice will read this as 15 milliOhm!
We'll illustrate the different types of simulations for the following circuit:
A new page will open in the Project Design Manager as shown below.
Figure 3: Design manager with schematic window and toolbars (OrCAD screen capture)
2.1.2. Place the components and connect the parts
1. Click on the Schematic window in Capture.
2. To Place a part go to PLACE/PART menu or click on the Place Part Icon. This will open
a dialog box shown below.
4. Place the resistors, capacitor (from the Analog library), and the DC voltage and current
source. You can place the part by the left mouse click. You can rotate the components by
clicking on the R key. To place another instance of the same part, click the left mouse
button again. Hit the ESC key when done with a particular element. You can add initial
conditions to the capacitor. Double-click on the part; this will open the Property window
that looks like a spreadsheet. Under the column, labeled IC, enter the value of the initial
condition, e.g. 2V. For our example we assume that IC was 0V (this is the default value).
5. After placing all part, you need to place the Ground terminal by clicking on the GND
icon (on the left side toolbar). When the Place Ground window opens, select
GND/CAPSYM and give it the name 0 (i.e. zero). Do not forget to change the name to
0, otherwise PSpice will give an error or "Floating Node". The reason is that SPICE
needs a ground terminal as the reference node that has the node number or name 0 (zero).
Figure 5: Place the ground terminal box; the ground terminal should have the name 0
6. Now connect the elements using the Place Wire command from the menu
(PLACE/WIRE) or by clicking on the Place Wire icon.
7. You can assign names to nets or nodes using the Place Net Alias command (PLACE/NET
ALIAS menu). We will do this for the output node and input node. Name these Out and
In, as shown in Figure 2.
2.1.4. Netlist
The netlist gives the list of all elements using the simple format:
R_name node1 node2 value
C_name nodex nodey value, etc.
1. You can generate the netlist by going to the PSPICE/CREATE NETLIST menu.
2. Look at the netlist by double clicking on the Output/name.net file in the Project Manager
Window (in the left side File window).
Note on Current Directions in elements:
The positive current direction in an element such as a resistor is from node 1 to node 2. Node
1 is either the left pine or the top pin for an horizontal or vertical positioned element (.e.g a
resistor). By rotating the element 180 degrees one can switch the pin numbers. To verify the
node numbers you can look at the netlist:
e.g.
e.g.
R_R2
R_R2
Since we are interested in the current direction from the OUT node to the ground, we need to
rotate the resistor R2 twice so that the node numbers are interchanged:
R_R2
OUT
10k
The check the direction of the current, you need to look at the netlist: the current is
positive flowing from node1 to node1 (see note on Current Direction above).
We will be using the same circuit but will evaluate the effect of sweeping the voltage source
between 0 and 20V. We'll keep the current source constant at 1mA.
1. Create a new New Simulation Profile (from the PSpice Menu); We'll call it DC Sweep
2. For analysis select DC Sweep; enter the name of the voltage source to be swept: V1. The
start and end values and the step need to be specified: 0, 20 and 0.1V, respectively (see
Fig. below).
2. You can also add traces using the "Voltage Markers" in the schematic. From the PSPICE
menu select MARKERS/VOLTAGE LEVELS. Place the makers on the Out and In node.
When done, right click and select End Mode.
Figure 10: Using Voltage Markers to show the simulation result of V(out) and V(in)
3. Go to back to PSpice. You will notice that the waveforms will appear.
4. You can add a second Y Axis and use this to display e.g. the current in Resistor R2, as
shown below. Go to PLOT/Add Y Axis. Next, add the trace for I(R2).
5. You can also use the cursors on the graphs for Vout and Vin to display the actual values
at certain points. Go to TRACE/CURSORS/DISPLAY
6. The cursors will be associated with the first trace, as indicated by the small small
rectangle around the legend for V(out) at the bottom of the window. Left click on the first
trace. The value of the x and y axes are displayed in the Probe window. When you right
click on V(out) the value of the second cursor will be given together with the difference
between the first and second cursor.
7. To place the second cursor on the second trace (for V(in)), right click the legend for
V(in). You'll notice the outline around V(in) at the bottom of the window. When you
right click the second trace the cursor will snap to it. The values of the first and second
cursor will be shown in Probe window.
8. You can chance the X and Y axes by double clicking on them.
9. When adding traces you can perform mathematical calculations on the traces, as
indicated in the Add Trace Window to the right of Figure 9.
10
Figure 11: Result of the DC sweep, showing Vout, Vin and the current through
resistor R2. Cursors were used for V(out) and V(in).
2.4 Other types of Analysis
2.4.1 Transient Analysis
We'll be using the same circuit as for the DC sweep, except that we'll apply the voltage and
current sources by closing a switch, as shown in Figure 12.
cursor gave a corresponding time of 30ms which gives a time constant of 30-5=25ms (5
ms is subtracted because the switch closed at 5ms).
12
13
8.
9.
14
Figure 3.1.2: Circuit with ideal transformer as entered in PSpice Capture (the transformer TX
is modeled by the part XFRM_LINEAR of the Analog Library).
15
16
Figure 3.2.2: Results of the AC sweep of the Active Filter Circuit of the figure above.
3.3 AC Sweep of Filter with Real Op-amp (Filter circuit)
The circuit with a real op-amp is shown below. We selected the U741 op-amp to build the
filter. The simulation results are shown in Figure 3.3.2. As one would expect the differences
between the filter with the real and ideal op-amps are minimal in this frequency range.
17
Figure 3.3.2: Results of the AC sweep of the Active Filter Circuit with real Op-amp (U741)
of the figure above.
3.4 Rectifier Circuit (peak detector) and the use of a parametric sweep.
3.4.1: Peak Detector simulation
Figure 3.4.1: Rectifier circuit with the D1N4148 diode and a load resistor of 500 Ohm.
The results of the simulation are given in Fig. 3.4.2. The ripple has a peak-to-peak value of
777mV as indicated by the cursors. The maximum output voltage is 13.997V which is one
volt below the input of 15V.
18
Figure 3.4.3: Circuit used for the parametric sweep of the load resistor.
a. Adding the Parameter Part
a. Double click on the value (500 Ohms) of the load resistor R1 to {Rval}. Use curly
brackets. PSpice interprets the text between curly brackets as an expression that it
evaluate to a numerical expression. Click OK when done.
b. Add the PARAM part to the circuit. You'll find this part in the SPECIAL library.
c. Double click on the PARAM part. This will open a spreadsheet like window
showing the PARAM definition. You will need to add a new column to this
spread sheet. Click on NEW COLUMN and enter for Property Name, Rlval
(without the curly brackets).
d. You will notice that the new column Rlval has been created. Below the Rlval
enter the initial value for the resistor: lets make it 500, as shown in Figure 3.4.4
below.
19
Figure 3.4.4: Property Editor window for the PARAM part, showing the newly created Rlval
column.
e. While the cell in which you entered the value 500 still selected click the
DISPLAY button. You can now specify what to display: select Name and Value.
Click OK.
f. Click the APPLY button before closing the Property editor.
g. Save the design.
b. Create the Simulation Profile for the Parametric Analysis
a. Select PSPICE/NEW_SIMULATION_PROFILE
b. Type in the name of the profile, e.g. Parametric
c. In the Simulation Setting window, select Analysis Tab if the window does not
open.
d. For the Analysis type select Transient (or the type of analysis you intend to
perform; in this example we'll do a transient analysis)
e. Under Option, slect Parametric sweep as shown in Figure 3.4.5.
f. For the Sweep Variable, select Global Parameter and enter the Parameter name:
Rlval. Under sweep type give the start, end and increment for the parameter. We'll
used 250, 1kOhm and 250, respectively (see Figure 3.4.5).
g. Click OK
20
Figure 3.4.5: Window for the Simulation Settings of the Parametric Sweep.
c. Run Spice and Display the waveforms.
a. Run PSpice
b. When the simulation is finished the Probe window will open and display a pop up
box with the Available Selection. Select ALL and OK.
c. The multiple traces will show, as given in Figure 3.4.6.
d. You can use the cursors to determined specific valueson the traces; you can also
adjust the axis by double-clicking on the Y and X axes.
21
Figure 3.4.6: Results of the parametric sweep of the load resistor, varying from 250 to 1000
Ohm in steps of 250 Ohm.
22
The result of a transient simulation is shown in the figure below. One can also look at the
Fourier of the simulated output signal. In the Probe window click on the FFT icon, located on
the top toolbar, or go to the PSPICE/FOURIER menu. The Fourier spectrum of the displayed
trace will be shown. You can change the X axis by double-clicking on it. Figure 3.5.3 gives
the Fourier spectrum with the main peak corresponding to the carrier frequency of 5kHz and
two side peaks at 4.5 and 5.5 kHz, indicating that the modulating frequency is 500Hz. You
can use the cursors to get accurate readings.
Figure 3.5.2: Simulated waveform (transient analysis) of the circuit above, with (A=1V,
fm=500 Hz, fc=5kHz and m=0.5)
23
Figure 3.6.1: Circuit with Center Tap Transformer with a ratio of 10:1.
After placing the element on the schematic give each element its value. Use of the input
voltage a sinoid with amplitude of 100 V and frequency 60 Hz. Notice that we added a small
resistor R1 in series with the voltage source and the inductor. This was needed to prevent a
short circuit in DC (Spice would give en error without this resistor). We have kept it small
equal to 1 Ohm. Assume that we want to have a step-down transformer with a ratio of 10:1
to each secondary output. The ratios of the inductors L2/L1 and L3/L1 must then be equal to
1/102 (or =sqrt(L2/L1)=0.1). We made L1=1000 and L2-L3=10H.
Double-click on the K-Linear element and type under the column headings for L1, L2, L3,
the values LP, Ls1, Ls2. When done, click the APPLY button and close the properties
window.
Go to PSpice/CREATE_NETLIST to generate the netlist. To see the list, go to the Project
Manager and double-click on OUTPUTs: name.net file. The netlist looks as follows:
* source CENTERTAPTRANSFOR2
Kn_K1
L_Lp L_Ls1 L_Ls2
L_Lp
0 N00241 1000
L_Ls1
0 VO1 10
L_Ls2
VO2 0 10
V_V1
N00203 0
+SIN 0V 100V 60 0 0 0
R_R1
N00203 N00241 1k
R_R2
0 VO1 1k
R_R3
VO2 0 1k
Create a new Simulation Profile (Transient) with " Time to run = 50ms". The result is shown
in Figure 3.6.2. Notice that the max output is 10V as one would expect from a transformer
ratio of 10:1 with an input voltage of 100Vmax.. The two outputs are 180 degrees out of
phase.
24
25
26
Figure 4.2.1 Create Parts for Library window. In this example we created a Model
Library called ESE216LIB.lib and Parts ESE216LIB.olb
e. Click the OK button. A window will open, giving the status of the library creation.
This should give you no errors.
f. Click OK in the Status window.
The next step is to edit the Part Symbols that you just created.
4.4.2. Editing the Part Symbol
a. Open OrCad Capture.
b. Go to the FILE/OPEN/LIBRARY menu. Browse for the location of the newly created
file (e.g. ESE216LIB.OLB). Click OK. This will open the PCB window fpr the
library, as shown below. In our example, our library contains two devices (NMOS
and PMOS devices). In practical cases the library can contain many different devices
and subcircuits. An example is the sedra_lib.lib and sedra_lib.olb that comes with the
textbook [10], shown in Figure 4.2.3.
27
Figure 4.2.3 Library sedra_lib.lib showing the various devices in the library file. The left window
pane list all the devices and subcircuits. The right pane shows the model of the NMOS5PO
(highlighted on the left).
c. To edit the symbol of any of the devices double click on it in the Library Editor
window. Lets select e.g. the NMOS5PO device. This will open the Part Symbol
window, as shown in Figure 4.2.4. OrCad Capture is smart enough to know when
a model corresponds to a transistor and will create a transistor model, as shown in
Figure 4.2.4. However for subcircuits is will usually give you a generic box. You
can than modify this box using the editing tools of Capture.
Figure 4.2.4 Part Symbol Window allowing you to edit the part. The example shown
here is a NMOS symbol without a separate bulk contact. In that case the source and
bulk are automatically shorted together.
28
d. The red line on the Parts symbol correspond to pins. These can be added by
clicking on the "Place Pin" icon on the right side menu bar (or PLACE/PIN
menu). This will open the Place Pin window shown below.
e. You can edit the pins by first selecting it and then right clicking and selecting Edit
Properties. The pin name and type are important. In general you should not
change the pin names since these relate back to the Spice model. The pin type is
usually "Input" or "Output." If you make a pin a "Power" type, it will be invisible
in the part symbol. For shape you can select "Line" or "Short" which corresponds
to a short line. Check out the other options. In case you create a symbol for a
subcircuit you can give the pin numbers that correspond to those of the datasheet.
f. When the part symbol is finished, save the library. You are now ready to use your
newly created library and symbols. Before doing a simulation you need to add the
library to the library path, in both the schematic and the simulator setting. See
section on "Adding Vendor Libraries" above.
References
1. OrCAD website for PSpice (http://www.orcad.com/pspicead.aspx), has application notes,
download, examples and interesting links.
2. OrCAD website for CAPTURE. (http://www.orcad.com/orcadcapture.aspx)
3. PSpice Users manual, OrCAD Corp. (Cadence Design Systems, Inc.)
4. PSpice Reference Guide, OrCAD Corp. (Cadence Design Systems, Inc.)
5. PSpice Library Guide, OrCAD Capture User's Guide, (Cadence Design Systems, Inc.)
6. OrCAD Capture Users Guide, OrCAD Corp., (Cadence Design Systems, Inc.)
7. SPICE Tutorial
8. A. Vladimirescu, The Spice Book, J. Wiley & Sons, New York, 1994.
9. B. Carter, "Using Texas Instruments Spice Models in PSpice, Application Report,
SLOA070, Texas Instruments, Dallas, TX, September 2001.
29
10. A. Sedra and K. C. Smith, "Microelectronic Circuits," Oxford University Press, 2004,
with accompanying Rom CD containing Spice Circuit Examples.
30