Transcription of NGSPICE- Usage and Examples - IIT Bombay
1 ngspice - Usage and ExamplesDebapratim Systems GroupDepartment of Electrical EngineeringIndian Institute of Technology BombayFebruary 2013 Debapratim GhoshDept. of EE, IIT Bombay1/20 IntroductionQ:What is electronic design?A:Given some desiredspecificationsto be achieved, we want to have asystem which can be made by interconnectingknown We want an amplifier with a gain of Elements- This amplifier can be made using a transistor (BJT orMOSFET), or an op-amp, along with some resistors. Known elements arethose whose behaviour can be represented by means of algorithms,equations or specific models.
2 In short, known elements are those whosebehaviour is familiar to we wish to design complex circuits, a circuit simulator isa useful GhoshDept. of EE, IIT Bombay2/20 What is ngspice ? SPICE is an acronym for forSimulationProgram withIntegratedCircuitEmphasis. First developed at UC Berkeley, it is the origin of most modernsimulators. ngspice is an open source mixed-signal circuit simulator. It is the resultof combining existing SPICE features with some extra analyses, modelingmethods and device simulation features. It is freely available for use in Linux and Windows. It is recommended touse Linux for ngspice .
3 ngspice requires you to describe your circuit as anetlist. A netlist isdefined as a set of circuit components and their GhoshDept. of EE, IIT Bombay3/20 ngspice provides you circuit Elements Passive components- resistors, capacitors, inductors, etc. Sources- independent voltage and current sources, controlled sourcesSemiconductor Devices Pre-defined circuit elements such as diodes and transistors Allows you to define or include models of specific devices transistors and op-ampsCircuit Analysis Techniques DC and AC analyses Transient and Steady-state analyses Pole-Zero, Noise analyses and moreDebapratim GhoshDept.
4 Of EE, IIT Bombay4/20 Getting Started with ngspice (Linux) You can use any text editor (say, gedit) to write your circuitnetlist. Thefirst line in an ngspice file isnot executed. It is used to describe theaim of the circuit being simulated. All ngspice comments start with an asterix, * The ngspice file comprises of the circuit netlist followed bythe detailsof the analysis the user wishes to do. ngspice files are usually saved with the extension .cir or .spice . circuit components are identified by their first letter of naming, calledprefix, resistors begin withr, capacitors withc, bipolar transistorswithq, MOSFETs withm, voltage sources withvand so on.
5 All circuit nodes are named/numbered. The netlist requiresone groundnode (zero potential).Debapratim GhoshDept. of EE, IIT Bombay5/20 example I- Transient Analysis of an RC CircuitA simple RC circuit , excited by a user-defined signalVin. We want to find the capacitor voltage (t). Thenetlist is as shown.+ +-10ms 11ms20ms5 V120replacementsVinVinVc(t)1 k 1 FtRC circuit Transient Response*resistor connected between nodes 1 and 2r1 1 2 1k*capacitor connected between nodes 2 and 0c1 2 0 1u*piecewise linear input voltagevin 1 0 pwl (0 0 10ms 0 11ms 5v 20ms 5v)*transient analysis for 20ms, step size 20ms*defining the run-time control *plotting input and output voltagesplot v(1) v(2).
6 GhoshDept. of EE, IIT Bombay6/20 example I- Transient Analysis of an RC circuit (cont d) Once you have typed your netlist, save it with an appropriate name, Open the Linux terminal, and change the working directory to the folder whereyour netlist file is saved. if the file is in theDocumentsfolder, typecd /Documentsin the the command prompt. Run the netlist file using the commandngspice And that s it- your netlist should run! A snapshot is as GhoshDept. of EE, IIT Bombay7/20 Inside the ngspice Shell Once any netlist is run by ngspice , the terminal is hooked to an ngspice shell, with a prompt such asngspice 1 ->.
7 You can exit the ngspice shellanytime by typingexitorquit. It is not always necessary to quit ngspice every time to run a new netlist. Youcan use the commandsource <filename>.cirto simulate a new netlist fileusing the ngspice prompt. The commands specified the netlist file may beused in the ngspice prompt separately. The waveforms may be saved as a postscript file by clicking on thehardcopy iconon the waveform window. However, this saves it as a default filename in the rootdirectory. A better way to save the waveform in the working directorywould be touse the following commands (say for the R-C circuit discussed above)set hcopydevtype=postscripthardcopy v(1) v(2) You can even save the plots using different colours.
8 Read the ngspice manualfor that, and much more!Debapratim GhoshDept. of EE, IIT Bombay8/20 example II- AC Analysis of RC CircuitFor the same R-C circuit discussed in example I, let us do the small-signal ACanalysis, find its frequency running this, you should be ableto see two plot windows- a magnitude (dB) plot and a phase (degrees) circuit Frequency Responser1 1 2 1kc1 2 0 1u*Specifying an AC source with zero dcvin 1 0 dc 0 ac 1*AC analysis for 1 Hz to 1 MHz, 10 points per dec 10 1 *Magnitude dB plot for v(2) on log scaleplot vdb(2) xlog*Phase degrees plot for v(2) on log scaleplot{ *vp(2)} GhoshDept.
9 Of EE, IIT Bombay9/20 example III- DC Analysis of a Shunt ClipperA DC analysis involves varying a voltage or a current source output throughout a rangeof values. Consider the following shunt clipper circuit . We wish to find theVoutv/sVincharacteristic for this circuit , say for -5 V Vin +5 V.+ 1 k 2 VVinVout1230 Shunt Clipper DC analysisr1 1 2 1k*Specifying a default diode p nd1 2 3*Independent DC source of 2 Vvdc 3 0 dc 2*Independent DC source whose voltage is to be variedvin 1 0 dc 0*DC Analysis on source vin, to vary from -5 to + vin -5 5 v(2) vs v(1). GhoshDept. of EE, IIT Bombay10/20 example IV- I-V Characteristics of a Transistor So far, we have only used default models of all circuit componentsprovided by ngspice .
10 However, this is not always the case as we wouldlike to use special devices different kinds of diodes, transistors,amplifiers, etc. for certain circuits. Suppose we wish to measure the I-V characteristics of the base-emitter(B-E) region of a BC547 transistor. Since transistor characteristics varygreatly from device to device, we will require a well defined model ofBC547, rather than the default model provided by ngspice . The model file, if available, should be saved in the same working directoryas your netlist, and can be invoked using To measure current in a branch, keep a DC voltage source of 0 V in thatbranch.