Circuit Simulation with Spice
Total Page:16
File Type:pdf, Size:1020Kb
CIRCUIT SIMULATION WITH SPICE Eric Prebys P116A - Fall 2018 Introduction to SPICE, E. Prebys 2 Limits of Analytical Calculations • Up until now, we’ve dealt with “ideal” components • Perfect (pure) R, C, L, V, and I • We’ve often made approximations • e.g RLC circuits far from critical damping • The real world is much more complicated • Real components non-ideal properties • Inductors have resistance • Capacitors and inductors have losses • Some very important elements are non-linear • e.g. semiconductors (diodes, transistors, etc) • Devices can have complex frequency and temperature dependence • These things affect not only discrete components, but elements of integrated circuits, which can’t be “breadboarded” beforehand • Numerical simulation is required prior to building complex circuitry. P116A - Fall 2018 Introduction to SPICE, E. Prebys 3 What is SPICE? • SPICE stands for “Simulation Program with Integrated Circuit Emphasis” • which doesn’t really make a lot of sense • The original was written in FORTRAN at UC Berkeley by Laurence Nagel, under the direction of his advisor Donald Pederson. • First official release in 1973 • Based on “models” for individual components and “netlists” defining the interconnections between those components • Input via text “cards” • The capabilities of SPICE have grown over the years, and now there are many versions • It remains the most common simulation engine for circuits, but today it’s often embedded in other programs that shield the user from the details of the text input GUI Netlists and SPICE commands SPICE P116A - Fall 2018 Introduction to SPICE, E. Prebys 4 Types of Simulations in SPICE • SPICE can do many types of simulations, but the three basic classes that we will consider are • “Operating Point” analyses: • SPICE command = .op • Solving Kirchoff’s Equations to get static voltages and currents • “Transient” analyses • SPICE command = .tran • Time domain behavior, in which the circuit response is calculated to particular initial conditions and/or a variety of time-dependent driving waveforms. • “AC” analyses: • SPICE command = .ac • Frequency domain behavior, in which the circuit response is calculated as a function of driving frequency P116A - Fall 2018 Introduction to SPICE, E. Prebys 5 Using command-driven SPICE • A basic SPICE circuit consists of “components” connected by “nets”, so for a simple RC circuit • The type of component is determined by the first letter, and the rest is the name • Nets can have numbers or names, with “0” generally reserved for GND Common to all versions 100Ω 1 testpoint 10V 10µF τ = RC =1000µs=1ms 0 Different for different versions P116A - Fall 2018 Introduction to SPICE, E. Prebys 6 Results Voltage Current P116A - Fall 2018 Introduction to SPICE, E. Prebys 7 Component Models • Like our analytical calculations, the basic components in SPICE are ideal (perfect) • SPICE can incorporate very sophisticated models for the real behavior of components • Non-linear behavior • Frequency dependence • Temperature dependence • Time dependence • etc, etc • Extensive SPICE model libraries exist for all commercial electronic components. P116A - Fall 2018 Introduction to SPICE, E. Prebys 8 Model Example: 2N222A transistor • The 2N222A is a very common transistor, which we will learn about shortly • Here3.2 is the BJT complete SPICE model for this transistorWe can… add a bipolar junction transistor to our stack using the following code. .MODEL 2N2222A npn +IS=3.88184e-14 BF=929.846 NF=1.10496 VAF=16.5003 +IKF=0.019539 ISE=1.0168e-11 NE=1.94752 BR=48.4545 +NR=1.07004 VAR=40.538 IKR=0.19539 ISC=1.0168e-11 +NC=4 RB=0.1 IRB=0.1 RBM=0.1 +RE=0.0001 RC=0.426673 XTB=0.1 XTI=1 +EG=1.05 CJE=2.23677e-11 VJE=0.582701 MJE=0.63466 +TF=4.06711e-10 XTF=3.92912 VTF=17712.6 ITF=0.4334 +CJC=2.23943e-11 VJC=0.576146 MJC=0.632796 XCJC=1 +FC=0.170253 CJS=0 VJS=0.75 MJS=0.5 +TR=1e-07 PTF=0 KF=0 AF=1 • We’ll getNotice, to themodels use of the at + a sign later to append time the new line to the old line. 3.3 MOSFET Next, we will look at how to add a MOSFET to our netlist. MName ND NG NS NB MODELNAME L=VALUE W=VALUE .MODEL MODELNAME NMOS{or PMOS} ([PROPERTY1=VAL1] [PROPERTY2=VAL2] ...) Here, ND is the drain node, NG is the gate node, NS is the source node, and NB is the bulk or substrate node. Providing values for L and W will specifiy the width and length of your MOSFET. I will not include a sample MOSFET model in this tutorial, but we can look at one later on when we need to use it. 3.4 Subcircuits Defining subcircuits will make your life much easier by allowing you to cut, paste, and reuse models you constructed in any circuit. First, lets create the subcircuit by defining it somewhere within our SPICE stack. .SUBCKT SUBNAME N1 N2 N3 ... *Insert the netlist for your *subcircuit within *this area .ENDS SUBNAME Then, lets call it in our main SPICE netlist. XName N1 N2 N3 ... SUBNAME 10 P116A - Fall 2018 Introduction to SPICE, E. Prebys 9 Versions of SPICE • There are now many versions of SPICE. Some of the most common are: • PSPICE ($$) • Industry standard, incorporated as part of ORCAD design package • NGSPICE (free) • GNU open source version. Most generic. Text entry only, but used as the basis for other GUI systems, for example… • EASYEDA (free) • Web-based GUI, based on NGSPICE. Also includes PC board layout. Nice, but they limit the number of simulations you can do, which is frustrating • LTSpice (free) We will use this. Just google “download LTSpice” • Supported by Analog Devices • Available for Mac or Windows • Can install Windows version on Linux using Wine • GUI (schematic) interface, but can also use text-based files P116A - Fall 2018 Introduction to SPICE, E. Prebys 10 Operating Point Example • In Lecture 1, we solved this circuit 5Ω 5Ω I I I I = .17I 6 A 1 2 1 1 2 10Ω I 10 3 Ω 5V I I = 1.116 A 5V 5V 5V 3 2 Loop 1 Loop 2 Loop 1 Loop 2 I3= .94 A 10V 10V 20Ω 20Ω • Set up with SPICE P116A - Fall 2018 Introduction to SPICE, E. Prebys 11 Transient Example: RC Circuit S 100Ω 1 • In the following circuit, there is initially zero charge on the 5V capacitor, and switch S1 is 1µF closed at t=0 τ = RC = 100µs • Set up in SPICE….