0% found this document useful (0 votes)
244 views

PSpice Coding For Beginners

Using PSpice 9.1 Student Edition

Uploaded by

mrdantownsend
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
244 views

PSpice Coding For Beginners

Using PSpice 9.1 Student Edition

Uploaded by

mrdantownsend
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PSpice Coding for Beginners Using PSpice 9.

1 Student Edition
Daniel Townsend February 26, 2013

Contents
1 PSpice Syntax Quick Reference Guide 1.1 1.2 1.3 1.4 1.5 SI Unit Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Component Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Source Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Voltage Source Control Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Analyses and Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.1 1.5.2 Analysis Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 2 3 4 5 5 5 6 9 9 9 11 13

2 Getting Started: Creating your rst PSpice document 3 From Circuit to Code: Writing your rst PSpice document 3.1 3.2 Breaking down your circuit into a logical nodal structure . . . . . . . . . . . . . . . . . . . . . Start coding your PSpice document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4 Visualizing your Data: How to use the trace tools 5 Adding Custom Components to PSpice

PSpice Syntax Quick Reference Guide

This section is designed to be a quick reference guide for the new PSpice user. Note that this reference guide is not nearly exhaustive, and for a complete list of commands the user should see the PSpice manual.

1.1

SI Unit Syntax

When using components in PSpice, it is convenient to be able to use SI prexes. To do this, put these characters after the value of a PSpice component. SI Prex tera giga mega kilo milli micro nano pico femto Number 1012 109 10 10
6 3 3

PSpice Syntax t g meg k m u n p f

10 10

106
9 12

10 1015

In addition to the SI units, you can also use the letter E to symbolize 10n , as in 100 =1E-4.

1.2

Component Syntax

These basic circuit components are placeable in PSpice by using the command code located next to the component title. The name in each component is designed to be replaced by any name the user desires. Additionally N1 and N2 are supposed to be replaced with numbered nodes, and the ModelName for components which have it are supposed to be replaced with the specic model name for the component being placed. Resistor Rname N1 N2 Value Rname =Value N1 Capacitor Rname N1 N2 Value Cname =Value N1 N2 N2

Inductor

Lname N1 N2 Value Lname =Value N1 N2

Diode Dname N1 N2 ModelName + N1 Dname N2

Bipolar Transistor Qname C B E ModelName C B E MOSFET Mname G S D B ModelName D G S JFET Jname G S D ModelName D B Qname

G S

1.3

Source Syntax

This is the syntax for the sources in PSpice. The three available types are DC, AC, and TRAN. Independent Voltage Source Vname N1 N2 Type Value Vname =Value + N1 N2

Independent Current Source Iname N1 N2 Type Value Iname =Value N1 N2

1.4

Voltage Source Control Syntax

The following commands are only valid for voltage sources and are simply modications on the Independent Voltage Source shown above. Sinusoidal Vname N1 N2 SIN(Voffset Vamplitude Frequency TDelay Theta Phase)

The sinusoidal command is used for creating sinusoidal voltage sources. The oset voltage, amplitude, frequency, delay time, damping factor, and phase angle can be set by the user according to the syntax shown above. Pulse Vname N1 N2 PULSE(V1 V2 TD TR TF PW Period)

The pulse command is used for creating periodic waveforms with a high and low voltage value. The user can customize the delay time, rise time, pulse width, fall time, and period of the pulse function. To create a square wave, set the high and low voltages, the pulse width to half that of the period, and set everything else to zero. V2

V1

TD

PW TR Period

TF

Piecewise Linear Source Vname N1 N2 PWL(T1 V1 T2 V2 T3 V3 T4 V4 ...) This voltage source allows the user to specify time points where the voltage will change and the corresponding voltage level associated with this time. PSpice will always t a line in between both points.

(T3,V3) (T1,V1) ... (T4,V4) (T2,V2)

1.5

Analyses and Control Statements

In order to set an analysis type and to see the results of the simulation, control commands are necessary and are added at the bottom of a PSpice document. Additionally output statements control to what le the simulation data is sent. 1.5.1 Analysis Statements

DC Analysis .DC SRC START STOP STEP The DC analysis will take any existing voltage source and run a DC sweep operation with it, overriding any current parameters that the existing voltage source has. Note that the SRC parameter of this analysis statement is where the existing source name goes, and that the source has to exist for this statement to work. Transient Analysis .TRAN Tstep Tstop Tstart The Transient Analysis will start at time Tstart and run until Tstop in increments of Tstep. Note that Tstart is optional and if no Tstart is specied it is assumed by PSpice to be zero. 1.5.2 Output Statements

When you run a PSpice simulation, several les are created depending on the output statement you use. They will all have the same lename as your .cir le but will have dierent le extensions and contain dierent data. To specify the voltage at a specic node for an output variable, use the command V(nodenumber). Print Statement .PRINT TYPE Output1 Output2 Output3 ... This statement writes the output variables stated into the <filename>.out le. Output les can be opened in PSpice or in a text editor such as notepad. Probe Statement .PROBE Output1 Output2 Output3 ...

This statement allows you to plot the variables you simulated in PSpice. More detail can be found in Section 4 of this guide. If no output variables are given, all variables will be sent into the probe le and will be available for plotting. All data from the .PROBE command is sent to the le <filename>.dat.

Getting Started: Creating your rst PSpice document

Making your rst PSpice circuit le should be easy and intuitive, but it isnt. This section of the tutorial will guide you through the steps of creating a .cir le and opening it as a simulation. The rst step is opening up PSpice. To do this, nd the PSpice AD Student program on your computer. Once you open PSpice you will see the screen in Fig. 1.

Figure 1: The PSpice program window. To create a circuit le, rst press the File option and create a new text le, shown in Fig. 2.

Figure 2: Creating a new circuit le.

Before making any modications, rst save your text le as a .cir le, show in Fig. 3 and Fig. 4.

Figure 3: Saving your circuit le.

Figure 4: File extension of circuit les.

Once your circuit le is saved, you are still not ready to start coding. Notice how the Run button (which starts the simulation) is still grayed out. Before you continue, you need to open your text le as a simulation. As shown in Fig. 5, you need to rst click on the Open Simulation menu option, then as shown in Fig. 6 you need to change the le type viewed from .sim to .cir. This allows you to see the circuit le you created and open it.

Figure 5: The Open Simulation menu option.

Figure 6: Make sure to view .cir les to open your simulation. Now notice how the Run button is green. This means you can now run your simulation.

From Circuit to Code: Writing your rst PSpice document

Say you are given a circuit diagram and you want to write a PSpice coded document to simulate the circuit under various conditions. How would you go about doing this? To help answer this, the example circuit in Fig. 7 will be coded as a PSpice document step by step, showing the user how to code and analyze the circuit.

3.1

Breaking down your circuit into a logical nodal structure

PSpice works only with text, so if you have a drawing in front of you of a circuit, you can not simply draw it as you would in programs such as Multisim or Orcad capture. What you need to do is break the circuit down into numbered nodes, then use this information to code your circuit in PSpice. Fig. 7 shows a simple RC circuit broken down in this way, color coded to aid in understanding. 1 10k 2

Vin

Figure 7: A simple RC circuit with nodes broken down and numbered for easy input into PSpice. Notice how the ground node is labeled 0. This is the universal ground node for PSpice. You can not place your own ground, rather everything that is grounded needs to be shorted to node 0. Now that you have your circuit nodes labeled, it is time to code your circuit as a PSpice document.

3.2

Start coding your PSpice document

This section of the tutorial will not focus on how components are coded, but rather show you how to place your code in your document. If you need to know the syntax of particular components and analyses, skip to Section 1. To begin PSpice will not run your .cir le if it does not have a title. This just means you need to put an asterisk (*) followed by a name for your document. Note this doesnt have to be the same as the lename of your .cir le. The code describing your components will go next. The code is shown in Fig. 8 and explained line by line below the gure.

+ 0 9

1F

Figure 8: The PSpice code used to model the circuit in Fig. 7. The top of the le has the title, which as stated above is necessary for the le to compile. The rst line of code creates a voltage source with positive end at node 1 and negative end at node 0. The voltage applied is a 5 volt square wave with a period of 0.2 seconds. The second line creates a resistor named R1 with rst terminal at node 1 and second terminal at node 2. The value of this resistor is 10 k. The third line creates a capacitor named C1 with rst terminal at node 2 and second terminal at node 0. The value of the capacitor is 1 F. All of the component code has been explained, so nally there is the control code. The rst line of the control code performs a transient analysis of the circuit with a time step of 100 s and a total time of 2 s. The next line of the control code enables all output variables to be visualized on a plot, which is explained further in Section 4 of this document.

10

Visualizing your Data: How to use the trace tools

To continue with the previous example, once your code is written simply press the Run button in PSpice. If you wrote the code correctly, you should see a screen similar to that in Fig. 9. The only reason this screen comes up is because we used the .PROBE output statement in our PSpice le. Without this you can not visualize your simulations on a plot.

Figure 9: The result after simulating the PSpice example code. Your rst reaction may be to wonder where the data is that you simulated, since the plot shown is painfully blank. No need to fear however, because the probe data is there, you just cant see it. In order to see the data you simulated, you need to go to the trace menu, then click on the Add Trace option as shown in Fig. 10.

Figure 10: The Add Trace option in the trace menu.

11

Since we used the .PROBE command without any arguments, all variables were sent to the trace le as seen in Fig. 11. Once in the dialog box, simply single click on each variable you would like to see on your plot and then press OK.

Figure 11: The Add Trace dialog box. Single click on a variable to add it to the plot. As can be seen in Fig. 12 V1 and V2 were added to this plot. The RC time constant of the circuit as compared to the input can be seen in this simulation.

Figure 12: The trace output of our simulation.

12

Adding Custom Components to PSpice

If you are assigned a prelab or a homework where you need to simulate a certain type of diode or transistor, you either will be given a .MODEL le or you will be told that your library le contains the appropriate part. If you are given a .MODEL le, simply copy and paste it into your PSpice document. This code can be placed anywhere in the document (except before the title). To use the model simply type in the model name in the components ModelName parameter as shown in Section 1. An example is shown below.

Figure 13: An example of using the .MODEL command to import a 6A05 diode into your PSpice document. Note that if you need a .MODEL le and have not been supplied with one, a quick google search for the part number and spice model will usually get you a quick result. If instead you are told that you have a library le, include the command .LIB anywhere in your le to use the library models. Note that if you downloaded your copy of PSpice o of the internet, chances are you do not have any library les so you will need to manually enter every component you need as a .MODEL command.

13

You might also like