TSPICE Tutorial
TSPICE Tutorial
Tutorial on T-Spice
This is specified using an input file, also called a netlist, which is a simple text file
created using the text editor integrated with T-Spice. This file has device statements and
simulation commands drawn from the SPICE circuit description language, the details of
which are presented in the following sections.
• T-Spice is not case sensitive. This means that names such as Vbus, VBUS, vbus
and even vBuS are equivalent in the program.
• All element names must be unique. Therefore, you can't have two resistors that
are both named "Rbias", for example.
• The first line in the data file is used as a title. It is printed at the top of each page
of output. You should use this line to store your name, the assignment, the class
and any other information appropriate for a title page. T-Spice will ignore this
line as circuit data. Do not place any actual circuit information in the first line.
• There must be a node designated "0." (Zero) This is the reference node against
which all voltages are calculated.
• Each node must have at least two elements attached to it.
• T-Spice accepts ordinary text for node designations. If you want to declare a
node as "Pbus," you can. The only restriction seems to be that you can't embed
spaces in a node name. Use the underscore ("_") character to simulate spaces.
• The last line in any data file must be ".END" (a period followed by the word
"end.")
• All lines that are not blank (except for the title line) must have a character in
column 1, the leftmost position on the line.
o Use "*" (an asterisk) in column 1 in order to create a comment line.
Cornell University
Page 1 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
o Use "+" (plus sign) in column 1 in order to continue the previous line (for
better readability of very long lines).
o Use "." (period) in column 1 followed by the rest of the "dot command" to
pass special instructions to the program.
o Use the designated letter for a part in column 1 followed by the rest of the
name for that part (no spaces in the part name).
• Use "whitespace" (spaces or tabs) to separate data fields on a line.
• Use ";" (semicolon) to terminate data on a line if you wish to add commentary
information on that same line.
An alternative to this type of notation, which is in fact, the default for T-Spice output
data, is "textual scientific notation." This notation is written by typing an "E" followed
by a signed or unsigned integer indicating the power of ten. Some examples of this
notation are shown below:
• 656,000 = 6.56E5
• -0.0000135 = -1.35E-5
• 8,460,000 = 8.46E6
Here, we present the simplest circuit elements. Knowing how to model these ideal, linear
circuit elements is an essential start to modeling more complex circuits. In each case, we
Cornell University
Page 2 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
will only present the most fundamental version of the part at this time. Later we will
show you more sophisticated uses of the part models.
Resistors
Syntax
Examples:
The next passive element we add to our parts list is the linear inductor. This part name
begins with the letter, L, in column 1 of the source listing. The inductor stores energy in
its magnetic field. This makes it necessary to be able to specify its initial current in a
simulation. Although we can include inductors in DC circuit simulations, there is usually
little advantage in doing so because the inductor behaves as a short circuit under steady-
state DC excitation. In steady-state AC simulations the inductor behaves as an imaginary
impedance. We do not specify initial current in an inductor in either of those steady-state
conditions. However, when simulating transient operations, we often need to specify
this initial current.
Cornell University
Page 3 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
The figure shown above shows the circuit symbol for an inductor with node designations
of "1" and "2," an initial current of 2.5 A, and a value of 50 mH. An appropriate code
listing for entering this element into a PSpice circuit file is:
Note that the initial current is assumed to flow from the first node in the node list through
the inductor towards the second node in the node list. If there is a need to change the
direction of this initial current, either reverse the order of the nodes in the node list or
place a minus sign in front of the value of the initial current. For better readability, the
above line could be written as:
The "H" for henrys and the "A" for amps will be ignored by PSpice.
The capacitor is the second energy storing circuit component we add to our parts list.
We will assume that the capacitor is ideal in the sense of being linear and lossless. Since
it can store energy, PSpice provides a method for specifying the initial voltage across the
capacitor. This is useful for simulations of transient behavior of circuits with capacitors.
The figure shown below illustrates a capacitor with node designations and an initial
voltage of 20 from node 4 to node 5. The part name for a capacitor must start with the
letter, C.
Cornell University
Page 4 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
The capacitance of the above element is 50µF. This can be represented as "50u" in
PSpice. Note that the polarity of the initial voltage (as shown) is such that the positive
side is the first node in the list with the negative side on the second node in the list. To
reverse the polarity of the initial voltage for the simulation, either reverse the order of the
nodes in the node list or place a minus sign in front of the value in the "IC=" phrase. For
better clarity, the above capacitor could be coded as:
PSpice would ignore the "F" for farads and the "V" for volts.
We begin with the DC version of the ideal independent voltage source. This is the
default form of this class of part. The beginning letter of the part name for all versions of
the ideal independent voltage source is "V." This is the character that must be placed in
column 1 of the line in the text file that is used to enter this part. The name is followed
by the positive node designation, then the negative node designation, then an optional
tag: "DC" followed by the value of the voltage. The tag "DC" (or "dc" if you prefer) is
optional because it is the default. Later, when we begin modeling AC circuits and
voltage sources that produce pulses and other interesting waveforms, we will be required
to designate the type of source or it will default back to DC.
One of the interesting uses of ideal independent voltage sources is that of an ammeter.
We can take advantage of the fact that T-Spice saves and reports the value of current
entering the positive terminal of an independent voltage source. If we do not actually
require a voltage source to be in the branch where we want to measure the current, we
simply set the voltage source to a zero value. It still calculates the current in the branch.
In fact, we require an independent voltage source in a branch where that branch's current
is the controlling current for a current-controlled dependent source.
Examples:
The name of an ideal independent current source begins with the letter "I" in column 1 of
the data file. As with the independent voltage source, we begin by introducing only the
DC form of this part, but several other forms exist. Since the current source, is an active
element, it matters greatly how it is connected. Designated current flows into the node
Cornell University
Page 5 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
written on the left, through the current source, out the node written on the right. As with
the independent voltage source, the default type is DC. Remember that the so-called
+node on a current source may have a negative voltage with respect to the so-called -
node. This is due to the fact that the circuit external to the current source determines its
voltage.
Examples:
The .op command can be used for printing the operating point voltages for the circuit.
The voltage sare printed out in the .out file, which is generated when the .sp file is
simulated, and stored in the same directory.
One of the many "dot commands" in T-Spice is the .PRINT command. It has many uses,
but we will concentrate here on using it for printing DC voltages and currents. The
.PRINT command can be repeated as often as necessary in an analysis. You can list as
many items on a line as you wish.
However, we must keep in mind that the .PRINT command was designed to work with a
DC or an AC sweep. This is a method of varying a parameter over a range of values so
that we get a batch of cases solved all at once. Often, we do not actually want to run a
sweep over many values of a parameter. We can circumvent the sweep by setting its
range so that it can only run one value. Usually, a DC sweep is made by changing the
values of a source; although we will later learn to sweep over other circuit parameters.
For now, let's look at the syntax for a DC sweep command with the default linear type
range.
For our example problem, we choose the voltage source and set the sweep variable range
so that it cannot run more than one value:
Since the starting value equals the stopping value, the analysis will only run for one case,
i.e., for Vs at 20 volts. Remember that the only reason we are running the DC sweep
statement is to enable the .PRINT command. The .PRINT command will not work
Cornell University
Page 6 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
unless there is a sweep going on. Note: What you enter in the .DC statement overrides
any voltage value you may have placed in the part listing for the source.
Printing DC Voltages
In addition to printing the node voltages in which you type the letter "V" with the node
number in parentheses, you can print the voltage between any pair of nodes; ergo, V(m,n)
prints the voltage from node "m" to node "n."
Printing DC Currents
To print currents, you type the letter "I" with the element name in parentheses. Note that
the reported current is that which flows into the element from the node listed on the left
in the *.CIR file, through the element, and out the node listed on the right in the *.CIR
file. If you want to change the sign of the reported current in a resistor, then swap the
two nodes for that resistor.
We now discuss frequency sweeps over a range of frequencies. The purpose of this type
of analysis is to study the frequency response of different kinds of circuits.
Up to now, all our voltage and current sources were DC. We learned the syntax of the
DC source. The syntax for an AC source is very similar. The AC source is assumed to
be a cosine waveform at a specified phase angle. Its frequency must be defined in a
separate ".AC" command that defines the frequency for all the sources in the circuit. The
unique information for the individual source is: the name, which must start with "V" or
"I," the node numbers, the magnitude of the source, and its phase angle. Some examples
follow.
Cornell University
Page 7 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
Notice that the type, AC, must be specified, because the default is DC. If the phase angle
is not specified it will be assumed as zero degrees. The units of the phase angle will be in
degrees. As before, the "V" after the voltage value is optional, as is the "A" after the
current value in a current source. The polarity of the AC voltage source is determined as
if the voltage were a cosine function of ωt at t = 0. Then the node on the left is the
positive node and the node on the right is the negative node. Similarly, the polarity of the
AC current source is determined as if the current were a cosine function of ωt at t = 0.
Then positive current flows into the source from the node on the left, passes through the
source, and leaves the source from the node on the right.
To specify the frequency range we need the .AC command. The LIN, OCT and DEC
types of frequency ranges are discussed below.
The LIN range type is linear. It divides up the range between the minimum and maximum
user-specified frequencies into evenly spaced intervals. This is best used to view details
over a narrow bandwidth. The first parameter after the keyword LIN is the number of
points to calculate. This is followed by the lowest frequency value in Hz, then the highest
frequency value in Hz. As with all the range types, the unit "Hz" is optional.
The OCT range is logarithmic to the base two. Thus each octave has the same number of
points calculated. This is somewhat useful for designing electronic equipment for musical
applications. However, the resulting graphs are very similar in appearance to sweeps
made with the DEC range. The first parameter after the keyword OCT is the number of
points per octave to calculate. This is followed by the lowest frequency value in Hz, then
the highest frequency value in Hz.
Cornell University
Page 8 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
The DEC range is logarithmic to the base ten. Thus each decade has the same number of
points calculated. This is the most commonly used range for making Bode plots of a
frequency response. The first parameter after the keyword DEC is the number of points
per decade to calculate. This is followed by the lowest frequency value in Hz, then the
highest frequency value in Hz.
One of the most interesting aspects of circuit analysis is the study of natural and step
responses of circuits and the responses of circuits to time-varying sources. To perform
these analyses we introduce another group of "dot" commands.
This is the command that passes the user's parameters for performing the transient
analysis on a circuit to the T-Spice program. There are four time parameters and an
instruction to use the initial condition rather than calculated bias point values for starting
conditions. First, we show a sample .TRAN statement and then we will describe its
parameters.
In the above statement, the "20us" value labeled "prt_stp" (print step) is the frequency
with which data is saved. In this case, the system variables are stored each 20µs of
simulation time. The actual time steps used by T-Spice may be different from this. The
second parameter, "20ms," labeled as "t_max" (final time) is the value of time at which
the simulation will be ended. Since T-Spice starts at t = 0, there will be a total of 20ms
time span of simulation for the circuit. The third parameter, "8ms," labeled as "prt_dly"
(print delay) is the print delay time. In some cases, we do not want to store the data for
the entire time span of the simulation. In our sample statement shown above, we ignore
the data from the first 8ms of simulation and then store the data for the last 12ms. Most
of the time, this parameter is set to zero or not used. The fourth parameter, "10us,"
labeled as "max_stp" (max step) is the maximum time step size T-Spice is allowed to take
during the simulation. Since T-Spice automatically adjusts its time step size during the
simulation, it may increase the step size to a value greater than desirable for displaying
the data. When the variables are changing rapidly, T-Spice shortens the step size, and
when the variables change more slowly, it increases the step size. Use of this parameter
is optional. The last parameter in our list is "UIC." It is an acronym for "Use Initial
Conditions." Unless you include this parameter, T-Spice will ignore the initial conditions
you set for your inductors and capacitors and will use its own calculated bias point
information instead. Note that the use of the letter "s" after the numbers in the .TRAN
statement is optional. T-Spice assumes these values are seconds and actually ignores the
Cornell University
Page 9 Duggirala, Apsel, Lal
ECE 315 Tutorial on T-Spice Fall 2003
"s." However, it is recommended that you use units until you are extremely familiar with
all of these commands and definitions.
In the above example, T-Spice will save data at each 10ns interval of the simulation
starting at t = 0 until the final time of 500µs. I.e., there is no print delay and the user has
given full control of the calculation step size to T-Spice. In addition, T-Spice will
calculate its own initial conditions for any inductors and capacitors, ignoring any initial
conditions set by the user.
In the above statement, T-Spice collects the data at each 50ms time interval starting from
zero up to 2.5s. A zero was required as as a placeholder for the print delay parameter
since the maximum step size of 10ms was specified. T-Spice will use the designated
initial conditions of capacitor voltage and inductor current. Notice that the units were left
off the numbers in this statement. Only the prefixes which size the values are needed.
Following is an example illustrating the use of the pulse source, which can be used to
simulate a unit step function.
Cornell University
Page 10 Duggirala, Apsel, Lal