LTspice Tutorials




Information on my 'Introduction to SPICE using LTspice' is found HERE.

A beginner's guide to LTspice: I am still writing this book on LTspice (LTspice is FREE, fully functional and powerful spice simulator from Linear Technology). This book is meant for absolute beginners. Hopefully, private college Indian students will find it interesting. This book is an outcome of project done under Prof.M.A.Siddiqi at Aliagrh Muslim University.This book will be available FREE of any cost. Your feedback is highly welcome. I will be uploading new chapters as soon as they are ready, so visit this page regularly.
YOU CAN ALSO DOWNLOAD THEM. THEIR LINKS ARE AT THE END OF EACH CHAPTER.


CHAPTER: 1
INTRODUCTION

Before we start using SPICE, it is essential that we discuss questions such as what SPICE is, where and why it is needed at all, if there is any limitation, etc. To know the history of spice kindly visit the link given in references.
What is SPICE?
SPICE is an acronym for Simulation Program with Integrated Circuit Emphasis. As will be evident very soon, SPICE is a software program which takes circuit description as input (which may be provided either in the form of a text file or a schematic file) and gives the output in the form of text data or graphical plots. Developed at the University of California, Berkeley, SPICE has over the years evolved as an industry standard CAD (Computer Aided Design) tool. Berkeley SPICE was taken by various EDA (Electronic Design Automation) companies; and as a result today we see many commercial versions of the same. Commercial versions added many additional features to the original SPICE (and obviously each of they claim their version to be the best in the market!). The names of the commercial versions still have “SPICE” as suffix or prefix. For example Synopsis calls its version Hspice, OrCAD (of Cadence) named their version as PSPICE, Tanner calls their version T-SPICE, and Linear Technology calls their version LTspice, etc.
In the basic terms, given a circuit and set of inputs, finding its output (for example node voltages and branch currents) is termed as analysis. In contrast, given a set of specifications, finding a suitable circuit implementation is called design (or synthesis). SPICE is intended for circuit analysis, and not (directly) for design. For example, suppose you wish to design a CMOS inverter. You have specification parameters such as delay, chip area, power consumption, etc. If you wish SPICE to directly read these parameters and do some sort of magic, and come up with a circuit implementation, that’s unfortunately not going to happen, sorry!  However indirectly, it does prove highly useful in circuit design. In fact, today’s complex circuits design is not complete without the aid of SPICE. 
Figure 1.1 presents a (very simple) flowchart, showing the role of SPICE in the circuit design. On the basis of specifications, one starts an initial design manually, using simple device models (generally, the ideal models) that describes its behavior. For example a MOSFET in saturation is represented by following expression:
ID= ½ K’n W/L (Vgs- Vt)2



Figure 1.1: (simplified) IC design flow chart
Where, ID is the drain to source current, K’n is the trans-conductance parameter, W/L is the aspect ratio of the MOSFET, Vgs is the gate to source voltage, and Vt is the threshold voltage. This mathematical equation is a model for MOSFET. This model is very simple. Today’s model like BSIM (Berkley Short Channel IGFET Model) is much more complex, having more than hundreds of parameters and naturally not fit for manual calculations. Apart from mathematical form, a model can take other forms too, for example circuit representation (studied hybrid-pi model of MOSFET?).
The initial design is then tested using SPICE where one can easily use more complex device models (like BSIM). Actually, we can’t work with complex device models when doing pencil-paper based design. This is one of the major advantages of SPICE, that a complex device model which may reflect real-life situation more closely can be used. If the simulated result doesn’t match with the requirements, one needs to modify the design. The loop continues until we end up with a suitable design. We again remind our readers that a very simple design flow has been presented. Design flow has been discussed in much more detail in many excellent IC design books, for example in [1]. Also as the name indicates, although emphasis is on the integrated circuit analysis and design (both analog as well as digital); SPICE is also used for discrete circuits.
WHY SPICE?
Although, the power of SPICE will impress you more and more as you learn it and continue to move further, few points are in order. One of the reasons has been already mentioned in the previous paragraph: initial design begins with very simple device models unfortunately, which totally fail in real-life! At the same time, a more elaborate model (that you will use in a hope to predict better the real-life) tends to be complex and hence very difficult to work with manually. And hence, a design flow such as shown in the figure 1.1 appears reasonable. If you don’t simulate your design prior to fabrication, you will spoil considerable revenue and time. Neither testing a prototype on a Breadboard is always possible; nor does it resemble with the final chip, when fabricated.
If you want to check some new idea, use SPICE which is simple and cheaper.
In ICs, many currents and voltages are “hidden” and “inaccessible”, where SPICE can be of great help.
The ideal devices that you start your design with ,are not available in real-life. SPICE can provide you with such devices. For example, a resistor in your lab has associated tolerance; SPICE allows a tolerance free resistor. SPICE also lets it users do a “what if” sort of thing more easily, enough means for which may not be available in your laboratory (particularly true, if your college is resource-hit!). For example, you may wish to explore, “Hey, if my circuit will work at 400K in a desirable fashion, given that I initially designed it at 300K”. Values of components/parameters can easily be swept.
Actually, you can always do more than a typical laboratory yours lets you do (any reason why would you want that?)! After all, software is good because of its flexibility.
Limitations
We say that the output of a simulator is as good as the model being used. A model that represents a device truly, under all conditions is like a day dream.
Numerical Convergence is yet another problem with simulations. The circuit description that you have given to the simulator may not get simulated at all due to convergence problem. More on this later.
Since SPICE has to solve equations numerically (for example using Newton’s method which you studied in engineering mathematics), there is always possibility of getting small errors associated with the SPICE results.
Why This Book?
This book teaches you SPICE using examples- you will find a fairly large number of examples that are  complete in themselves and well tested so that user can practice them. Examples have been selected not only from circuit analysis or Microelectronic circuit courses, but also from research papers. Most important feature of this book is its friendly writing style. We have used   LTspice for the simulations although, a general concept of SPICE has been discussed and one can use any software package they wish.
. Reasons to use LTspice are as follows:
-          It is available FREE from Linear Technology. A large number of colleges in India- especially the private colleges don’t have enough resource to buy a commercial version of SPICE software. LTspice is fully functional freeware SPICE. Also, even if your college has it, what if you need to check a design (out of excitation!) at 2 am in the night and your college lab is closed!
-          It is very easy to learn. It is very fast. It doesn’t have component limitations. Some companies, other than Linear Technology may provide you a demo version of their SPICE package, but they are just demo- with either component limitation (for example, you can use not more than one Opamp) or time limitation (license may expire after a month). Their demo version may only work on WINDOWS OS. LTspice run on Linux too, using wine emulator.
-          LTspice comes up with a great number of example-circuits. If you wish to know how to simulate an oscillator circuit, you can find enough help from many examples of the same, available in the example folder of LTspice. This book also tells you how to get such information.
-          LTspice has a very big and helping user group (http://tech.groups.yahoo.com/group/LTspice/) whose mentor is Helmut Sennewald. It is a very active and dynamic user group that can give you support any time you get stuck. I strongly recommend you to join this group. Mike E –the creator of LTspice can be contacted at ltspice@linear.com.
(Note: If you see plenty of mails coming to you from the user group and you are getting annoyed, consider changing mail settings to ‘Daily Digest’. See the next two images). 

Audiences
Well, during my stay at HCST, Mathura, India, I saw students from rural areas that never used computer. Some of they even had, but might not have used for simulating a circuit. (Some of they were lucky for they had parents who sold their lands and ornaments so that their sons/daughters could study engineering). They need tutorials/books to teach them things in a very simple and illustrative manner with as many as examples as possible.
It is good that whatever useful knowledge Allah has given you, you share it with others. Even more better, if you do it for FREE.
This book is for absolute beginners, especially for students of “resource hit” private colleges in my country. Advance audiences (with prior experience with SPICE/LTspice) may find it boring, and I recommend them to join LTyahoo user group (Especially if they are looking for undocumented features of LTspice).
Yahoo User group settings for daily digest mails:
(1)   Login into yahoo and go to group home page. Click on “Edit Membership”.

(2)   In step two, select “Daily Digest”.

Finally, click on Save Changes and that’s it!

Happy Learning!

ACKNOWLEDGEMENT:
Thanks are due to Ms. Prem Pyari, assistant professor at HCST, Mathura for going through the first version of this tutorial book and giving many great suggestions and improving the contents, especially its English.
REFERENCES:


[1] R.J.Baker, CMOS Circuit Design, Layout, and Simulation, 2nd edition, India, Wiley-India.
[2] G.W. Roberts, A. S. Sedra, Spice, 2nd edition, India, Oxford University Press.
[3] M.H.Rashid, Introduction to Pspice® using Orcad® for Circuits and Electronics, 3rd edition, India, PHI.
[4] Spice tutorials/links: www.maktoomi.blogspot.com



CHAPTER: 2
GETTING STARTED!

It was mentioned in the previous chapter that given a circuit we can input its description into SPICE software in two ways: either by schematic or directly using text. See figure 2.1(a). Here; Software editor let us draw the circuit as we would draw in our notebook. We have all kinds of circuit element symbols, and we have to just drag & drop them into the workspace and connect them through wire (Don’t worry if you don’t see any transistor symbol there, I don’t see them, either! However, I promise that I will help you see them soon!).  The file which contains this drawing is schematic file.


Figure 2.1(a) Schematic entry
A second option is to use a text-editor (like Microsoft Notepad or gedit in linux) to tell the simulator about the circuit-the elements it contains, their values and how these various elements are connected to each other (as if you talk over phone with your friend describing him the circuit, “a resistor of 3K is connected with another resistor that goes to ground …”  bla-bla. This text file where you have written your circuit description is called netlist, circuit file or spice deck. See fig 21.1(b).
The question which one is better (schematic or text) is mostly a matter of choice. Generally it is seen that people prefer the way the first time they started doing SPICE. Netlist has an advantage over the schematic as simulator ultimately converts schematic into a netlist. Also, knowing how to write netlist is a lot helpful in debugging. You will appreciate these points later. If our circuit is large writing netlist directly may be a way boring (yes!) because in that case the circuit contains a lot of nodes and numbering/naming each of them is time-consuming. I personally believe that starting with learning netlist is better. Apart from being helpful in debugging, most of the syntax is simulator independent (i.e. if you write a circuit file, hopefully it will run in all spice simulators, with minor modifications). For schematic capture, you will have to learn how to enter the circuit into various spice versions as the procedure is different for each of them. Hence, we will start with netlist based entry.
Understanding Netlist: DC operating point Analysis
As you might have guessed, every element in the netlist will have a unique representation. For example, the name of a resistor starts with letter ‘r’ and that of a voltage source with letter ‘v’. Next we describe how to represent various circuit elements in SPICE.


Figure 2.1(b) Spice Netlist: Text based circuit description

Figure 2.2 Example Circuit

A voltage divider circuit is shown in fig 2.2. We are interested in various branch currents and nodal voltages. Next, we describe how to write spice netlist for this voltage divider.
How to write netlist:
1. Open a Notepad(start >All programs >Accessories >Notepad)

2. Go to File menu of untitled Notepad and click save As (File > Save As…)

3. Give a name to your netlist file.
*Name should be relevant. For example, this circuit is a voltage divider so volt_div sounds a good name! (How do you think of a name 'ayat_for_you'? Some people have bad habit of putting their name as netlist name!)
*Extension acceptable by LTspice is cir, sp . Even it can accept .txt. But if extension is other than txt (e.g. sp or cir), you must set “Save as type “ to All Files.
*Also note that I am saving the file, in folder SPICE. One must remember the directory they are saving their file into.
*click save

3. Once your file is saved, volt_div will appear as Notepad title. Now we can start typing the circuit file.



* The first line is ALWAYS a comment line. Comment should be relevant.

*Also, first we should number the various nodes. See in the voltage divider (Fig 2.2), one terminal of R2 and the negative terminal of V1 are (i.e. all the ground terminals in the circuit are same). By default, ground is numbered as ‘0’ [Caution: Don’t use letter ‘o’ or ‘O’ for ground!]. We can’t assign ground any other name/number, and 0 cannot be assigned to any node except ground. Then, the other node is the intersection of V1 and R1.Let us call this node ‘1’.Finally, the interconnection of R1 and R2, call this node ‘2’. Please note that this numbering need not be sequential and nodes could also have names from English alphabet. So , 1 and 2 could have been named as a and b. Or much better as ‘in’ and ‘out’ !
How to represent a resistor in spice? 
RESISTOR: Name of a resistor starts with letter ‘r’. It is described as follows:
Rname N1 N2 value

Rname is the name of resistor. It could be ‘ra’, ‘rbase’ or ‘r1’ etc. In the figure 2.2, a resistor r1 (look, the name starts with letter ‘r’) is connected between the nodes 1 and 2 and its value is 3K. It will appear in the netlist as follows:
r1 1 2 3K

*Almost all present SPICE softwares are case insensitive; hence r1 and R1 are equivalent.

*If we want to include unit, we could include ‘ohm’( i.e. default unit is ohm): R1 1 2 3kohm
*Rname , N1 ,N2 and value are each separated by one space, more than one space is allowed (however, there isn’t any need to do that !). Similar statement for other elements, like voltage and current source etc holds true.
R2 is connected between node2 and ground. 
R2 2 0 1K
How do we represent a dc voltage source?
Voltage Source: Syntax for a voltage source is as follows:
Vname Np Nn DC value
*Name start with letter ‘V’. It could be anything like vs, vsource, v1 etc.
* Np is the positive terminal of the source and Nn is the negative terminal.
*Writing 'DC' is optional. Again, unit could be specified by V(for volts) but not mandatory (i.e. default unit is Volt)
So in the figure 2.2, 
V1 1 0 dc 10v 
Or simply,
V1 1 0 10
Once we are done telling the simulator how various elements are interconnected, what next?
Well, I need to tell what to do now (analysis request, we usually call it)! 
For example here we are interested in various branch currents and nodal voltages. And if your circuit contains only DC sources, then to find these quantities we perform DC operating point analysis. Syntax is for performing DC operating point analysis is
.op
Finally, Spice netlist always end with ‘.end’ syntax (however, if you are using LTspice ‘.end’ is not necessary). 
After discussing this far, I hope you understand the meaning of each line in the following netlist:
*voltage divider Circuit
V1 1 0 10
R1 1 2 3k
R2 2 0 1k
.op
.end

Once you have typed all these line in the notepad, go to File menu of notepad, click save. Close this notepad (by clicking the cross).
Open LTspice. You can do it by double-clicking the LTspice short-cut icon at your desktop.



And in LTspice window do: File>open
That is, go to File menu and Click open.


Browse to the folder where you saved your circuit file (in our case it was SPICE folder).Change type of File to Netlists (*.cir,*.net,*.sp) - see the following Figure.




Then you will be able to see the circuit file (see the arrow in the above figure). Double click that file (volt_div) [or single click then click open].
This will open up the circuit file in the LTspice window.

Click the running man icon (or click Ctrl+R or go to Simulate and click run). Once you do it, a window will popup, and you will see the simulation results.

One can compare the result from manual analysis with that obtained from LTspice.
Well, it matches with manual analysis result.
V(2)=10*1/(1+3)=2.5V
And loop current=10/4K=2.5mA=0.0025A
Wait a moment; Why is the current through v1 i.e. I(V1) is negative? 
Well, spice gives you current from first node towards the second. Because, we defined ‘V1 1 0 10’ that means spice says a current of -0.0025A flows from node 1 to ground. This means, a current of 0.0025A flows from ground to node1. This is what should be the result.

EXERCISE:
(1) Modify the above circuit file such that r1 is defined as follows:
R1 2 1 3k
Perform “.op” analysis and observe the value of i(r1). Does the negative value of i(r1) make sense?

EXAMPLE: Given the following netlist, draw schematic diagram of the corresponding circuit.
Va 1 0 1
R1 1 2 1k
R2 2 0 2k
R3 2 3 3k
Vb 0 3 2
.op
.end
Solution: We observe in the netlist that there are three different nodes other than ground (0). They are 1, 2 and 3. We mark them as shown below. Then first line says there is voltage source Va of value 1V whose positive terminal is 1 and negative is ground (0). See the figure; we have connected that voltage source. The Resistor R1 of value 1K is connected between 1 and 2. Similarly, resistors R2 and R3 are between 2 and 0, 2 and 3, respectively. Then there is a voltage source Vb of value 2V whose positive node is 0 and negative is 3. Mind it; first node in the voltage source declaration is always the positive and second one is negative (Make sure you understand this point).

           


No comments:

Post a Comment