ELEC 273 Basic Circuit Analysis
Notes on LTSpice
December 4, 2018
What is Spice?
• SPICE = Simulation Program for Integrated Circuits Emphasis
• Spice is widely used to simulate electrical circuits for many purposes.
• The ENCS computer system supports PSpice by OrCAD Corp. of Cadence
Design Systems and you will use it in courses such as ELEC311 “Electronics”
• OrCAD offers a student edition of PSpice as a free download:
http://www.orcad.com/resources/orcad-downloads
• For ELEC273 Basic Circuit Analysis I prefer LTSpice:
http://www.linear.com/designtools/software
• Why? LTSpice is very simple to learn and use.
What does Spice do?
• You can build a circuit.
• You can solve your circuit with:
• DC sources and dependent sources
• Transient circuits with switches
• AC circuits with a cos(𝜔𝜔𝜔𝜔) generator
• Circuits with transformers and operational amplifiers.
• Much more:
• Circuits with transmission lines
• Accurate models of diodes and transistors
• Transistor amplifiers and other circuits for linear electronics
• Switching circuits for digital design
• Very large and complex integrated circuit designs.
Spice and ELEC273
• You can solve the homework problems with Spice to check your
answers – fun!
• In the lab, you must use SPICE to simulation the circuits and compare
the results with your measurements.
• In class LTSpice is used to solve D.C. circuits and later A.C. circuits.
• In later courses you will use Spice to solve much more complex circuits.
Getting Started with LT Spice
Read the LTspice Getting Started Guide:
http://ecee.colorado.edu/~ecen2270/materials/LTspice/LTspiceGettingStartedGuide.pdf
D.C. Circuit Analysis
Building a Circuit in LTSpice
Start LTSpice to get the main menu.
Choose File>new schematic to start a new circuit
Choose File>save as and give your circuit a name such as “circuit1’, and choose a directory where you will save
your circuit.
Add a Resistor
Left-click on the resistor at the top and drag the resistor down into the circuit schematic.
Note that the reference direction for the current is top to bottom.
Use control-R to rotate the resistor
One “control-R” rotates the resistor clockwise by 90 degrees.
Then the reference direction for the current is right to left.
Use control-R to rotate the resistor
Two “control-Rs ” rotates the resistor by 180 degrees.
Then the reference direction for the current is bottom to top.
Use control-R to rotate the resistor
Three “control-Rs” rotates the resistor clockwise by 270 degrees.
So the reference direction for the current is left to right, which is usually what we want!
Add a voltage generator
components
Click the “components” symbol and type “vo” for “voltage” to get the
voltage generator, then click OK
Add a voltage generator
Drag the voltage generator into place.
Add a ground:
Ground is the reference location or “-” sign
location for all the voltages that Spice
calculates.
Drag the symbol into place.
Add wires to connect the generator, the resistor and the ground:
Next: We need component values and then we can solve the circuit.
Add component values:
Right-click on “V” and a popup lets you type the value of the voltage source.
1 means 1 volt
1m means 1 millivolt
1k means 1000 volts.
You can drag the component value “text box” to a more convenient
location:
Right-click the hand tool, the right click the “1” text box and drag it to be
near the voltage generator.
We are ready to solve the circuit. Click on the “run” tool to get the
simulation menu.
We are expecting the current to be 1 kilohm / 1 volt = 1 milliamp, flowing from left to right.
Choose “DC operating point” as the simulation we want:
Then click OK to run the simulation.
The program pops up a list of all the voltages and currents:
We see that the current in R1, denoted as I(R1), is 0.001 amps or 1 mA as expected.
Note that the current in the voltage source is I(V1)=-0.001 amps.
Click the mouse on a wire to label the wire with its node voltage.
The voltage at the top of the generator relative to ground is 1 volt.
To label the current, click the mouse on a wire near the resistor:
The Spice program produces a text box filled with question marks: ???
Click the mouse on the ???.
Right-click on the question marks and a dialog box pops up letting you
choose the value that you want to display:
Type I(R1) into the dialog box, then OK.
The program labels the current in the resistor as 1 mA.
The reference direction for current flow is NOT shown so we have to know from setting up the circuit, that positive current
is left-to-right for this resistor.
The Netlist:
• R1 is connected from node N001 to “0” or ground and has
value 1k.
• V1 is connected from N001 to ground and has value 1 volt.
For more complicated circuits the Netlist is helpful in identifying
which nodes are associated with each component.
Click “View” then “SPICE Netlist” to get a list that shows how SPICE has built the circuit.
To get a “wmf” file to paste into a lab report:
Click “Tools > write to a wmf file”.
Spice asks for a file name:
You can paste the “wmf” file into a WORD
document or a PowerPoint presentation:
R1
V1 1k
1
• Easy and fast!
• When you have constructed and solved 10 circuits, you will know
every step without thinking.
𝑅𝑅2
Spice Simulation
𝑅𝑅1
+
𝑣𝑣𝑑𝑑
𝑣𝑣𝑠𝑠 − +
𝑣𝑣𝑜𝑜
−
Note the “-” is connected
to ground!
𝑅𝑅1 = 5, 𝑅𝑅2 = 10, 𝑣𝑣𝑠𝑠 = 1
so
𝑅𝑅
𝑣𝑣0 = − 𝑅𝑅2 𝑣𝑣𝑠𝑠 = −2 volts
1
Use the “directive”
.lib opamp.lib
so Spice can find the op amp component.
LTSpice uses A=100,000 to approximate
infinite gain.
Solving Transient Problems
Modelling Transients with Spice
𝑅𝑅 = 1 kilohm
𝑡𝑡 = 0 𝑅𝑅 +
𝐶𝐶 = 1 microfarad
𝑉𝑉𝑠𝑠 𝐶𝐶 𝑣𝑣(𝑡𝑡)
−
• Model the RC Circuit using LTSpice. Time Constant
𝜏𝜏 = 𝑅𝑅𝑅𝑅 = 1000𝑥𝑥𝑥𝑥𝑥𝑥10−6 =10 mS.
• The capacitor is initially uncharged. We expect the transient to last about
• The switch closes at t=0. 5𝜏𝜏 = 50 mS.
• Find 𝑣𝑣𝑐𝑐 (𝑡𝑡) for 𝑡𝑡 > 0
Component Values in LT Spice
From the LTspice Getting Started Guide:
http://ecee.colorado.edu/~ecen2270/materials/LTspice/LTspiceGettingS
tartedGuide.pdf
Create an LTSpice model of the circuit:
To specify that the voltage generator is a step function, click the right mouse button in the V1 circle.
Set up a step function generator:
Then click “advanced”.
Choose PULSE. We will set up a step function by using a pulse that lasts for ever.
Fill in the parameters:
• Set the initial value to 0 volts.
• Set the “on” value to 10 volts.
• Leave all the other parameters blank.
• Since “Ton” is not specified the pulse stays on forever and is a step function.
We have specified the generator as a “pulse” that lasts forever:
• We need to tell Spice that we want to do transient or time-domain analysis. Rc9.asc
• Click RUN and Spice pops up the “simulation” dialog box.
Click the “run” icon to get the “simulation” dialog box:
• Click “Simulate > Edit Simulation Card”
• Choose “Transient”.
• Specify a stop time of 100 milliseconds, because we expect the transient to last about five time
constants or 50 millisec
Click on “O.K.” to close the simulation dialog box and then run the simulation:
• A graph of voltage vs. time appears across the top of the screen, but with no curves!
• Click the mouse on the wire above C1.
We see the capacitor charging in about 50 ms:
• The capacitor charges from 0 volts to 10 volts.
• Since the time constant is 10 millisec, we expect the capacitor to charge in about five time constants or 50 ms.
Format control over the graph:
• Right-click v[n002] at the top of the graph.
• You can change the color of the curve.
• You can delete the curve
You can make the graph full screen:
Full screen makes the curves easier to see.
Note that as the cursor moves on the screen, the position of the cursor is read back and reported in the message area
at the lower left.
You can change the background color and the curve colors:
• Click on the “tools” icon and select Waveforms.
• Choose “Plot data with thick lines”
• Click on “Color scheme”
Set up the color scheme for the background and the curves:
I have chosen “background’ as the color to set and then moved the
color sliders for Red, Green and Blue to the maximum so that the
background is white.
I have also changed the color of V(1) to blue and V(2) to red.
With these settings you get a clean, legible graph:
Export the data to make a good-quality voltage vs. time graph:
• Click the mouse on the voltage vs. time graph
• Click File > Export
• Select the voltages you want to export and click OK
• Spice creates a “txt” file containing the voltage vs. time data.
Graph the data in the “txt” file with your favorite graphing software:
• Use your favorite rectangular-graphing software.
• For example, RPLOT reads the “txt” file called “RC1.txt” and creates an “rplot” file called
“RC1.rpl”
• You can enter axis titles and legend for the curve.
• You can “format” the axes to milliseconds and volts, and choose how the axes are labelled.
• You can get “rplot.exe” from Prof. Trueman’s web site.
Solving A.C. Circuits
Spice with a Sinusoidal Generator
𝐼𝐼𝑖𝑖𝑖𝑖
−𝑗𝑗𝑗 Ω
2Ω
𝑍𝑍𝑖𝑖𝑖𝑖 2Ω 3Ω
j1 Ω 𝑗𝑗𝑗 Ω
We will use this circuit to demonstrate how to solve
a circuit with an A.C. generator. The problem is to
find the input impedance at 60 Hz.
To calculate the input impedance with LTSpice:
• Drive the circuit with a 1 volt generator at 60 Hz
• Find the current flowing into the circuit 𝐼𝐼𝑖𝑖𝑖𝑖 .
• Calculate the input impedance as
1 Construct the circuit.
𝑍𝑍𝑖𝑖𝑖𝑖 =
𝐼𝐼𝑖𝑖𝑖𝑖
• The current flowing into the circuit is the current Put a voltage generator at the input of the circuit.
in the 2 ohm resistor 𝑅𝑅1 .
How do we specify a sinusoidal excitation at 60 Hz?
To specify that the generator is an AC source, right-click on the generator circle to pop up a menu:
Enter AC 1, meaning that the generator is a sinusoidal or “AC” source of amplitude 1 volt.
To tell LTSpice to use AC analysis and to specify the frequency, click on Stimulate and then Edit Stimulation
Card.
Choose AC Analysis:
• Specify the number of points per octave as 1.
• Specify both the starting and the stopping frequency as 60 Hz (we only want one frequency).
We are ready to run the simulation:
run
The system adds the “dot command” .ac oct 1 60 60.
Click on the “run” button to solve the circuit.
Spice calculates the amplitude and phase of the voltages and currents:
The current in R1 is reported as
I(R1)=0.4064 angle -17.8 degrees
Find the input impedance with LTSpice:
−𝑗𝑗𝑗 Ω
2Ω
𝑍𝑍𝑖𝑖𝑖𝑖 2Ω 3Ω
j1 Ω 𝑗𝑗𝑗 Ω
𝐼𝐼𝑖𝑖𝑖𝑖 = 0.4064 angle -17.8 degrees
• Calculate the input impedance as
1
𝑍𝑍𝑖𝑖𝑖𝑖 =
𝐼𝐼𝑖𝑖𝑖𝑖
1 1
𝑍𝑍𝑖𝑖𝑖𝑖 = = = 2.342 + 𝑗𝑗𝑗.7522
𝐼𝐼𝑖𝑖𝑖𝑖 0.4064∠ − 17.8°
Solving a Circuit at 60 Hz
2Ω 5.3 mH 1Ω 10.6 mH
10 cos 𝜔𝜔𝜔𝜔
𝐼𝐼1 2 sin 𝜔𝜔𝜔𝜔
𝐼𝐼2 331.6 μF
The operating frequency is 60 Hz.
The sources are
𝑣𝑣1 𝑡𝑡 = 10 cos 𝜔𝜔𝜔𝜔
𝑣𝑣2 𝑡𝑡 = 2 sin 𝜔𝜔𝜔𝜔
Use LTSpice to show that
𝐼𝐼1 =5.01 amps, angle 40.1 degrees
𝐼𝐼2 =4.03 amps, angle 17.8 degrees
Model the circuit with LTSpice 2Ω 5.3 mH 1Ω 10.6 mH
10 cos 𝜔𝜔𝜔𝜔 2 sin 𝜔𝜔𝜔𝜔 331.6
μF
The operating frequency is 60 Hz.
The sources are
𝑣𝑣1 𝑡𝑡 = 10 cos 𝜔𝜔𝜔𝜔
𝑣𝑣2 𝑡𝑡 = 2 sin 𝜔𝜔𝜔𝜔 = 2 cos(𝜔𝜔𝜔𝜔 − 90°)
LTSpice calculates:
𝐼𝐼1 =I(R2)=5.01 amps, angle 40.1 degrees
𝐼𝐼2 =I(R1)=4.03 amps, angle 17.8 degrees