You are on page 1of 5

EE 671: NGSPICE tutorial

Madhav P. Desai August 26, 2011

NGSPICE

NGSPICE (or SPICE3) is a circuit simulator which allows you to describe a circuit as an interconnected network of circuit elements (resistors, capacitors, controlled sources, voltage and current sources, transistors, etc.) and to perform various types of analyses on this circuit description. Such a simulator is an invaluable tool for circuit designers. This note illustrates the use of NGSPICE using two small examples, one illustrating DC analysis, and the other illustrating transient analysis. For more details, see the following webpage www-ti.informatik.uni-tuebingen.de/~bernauer/lehre/ti-1-0506/spice/ngspice.pdf Before proceeding, please download the SPICE models for the TSMC 180nm technology (these have been put up on the moodle course page).

An example to illustrate DC analysis

In DC analysis, one wishes to study the steady state behaviour of a circuit when all sources (current sources, voltage sources) have DC values. For example, if one wants to study the transfer characteristics of an inverter, one applies a DC voltage to its input, and observes the steady state output voltage of the inverter for this input. If the input is varied from 0 to VDD , one obtains the DC transfer characteristic. We prepare a circuit le in which we describe the circuit to be analysed, as well as the analysis to be performed. CMOS inverter transfer characteristics * the first line is the title, * * comments start with * * * you can include files.. this is the SPICE * model we will be using. .include tsmc_spice_180nm.txt 1

* * the P-transistor * name D G S B model L W mp1 2 1 3 3 cmosp L=0.18u W=3.6u * the N-transistor * name D G S B model L W mn1 2 1 0 0 cmosn L=0.18u W=1.8u * * voltage sources. * vdd 3 0 dc 1.8v vin 1 0 dc 1.8v * * DC analysis specifier: vin will be * swept from 0.0V to 1.8V in steps of 0.1V * At each sweep point, the DC solution of the * circuit is obtained and recorded. .dc vin 0.0 1.8 0.1 * * circuit ends with .end .end Place this circuit description in the le invTransferCharacteristics.cir (the le-name can be arbitrary). Now, type ngspice at the Unix prompt. An NGSPICE shell opens up. You can now use the following sequence to analyze the inverter. 1. Point NGSPICE to the source circuit. source invTransferCharacteristics.cir 2. Now run the simulator and perform the specied analysis (in this case, DC analysis). run 3. You can now view the results of the simulation using the plot command. Node 1 is the input and Node 2 is the output of the inverter. plot v(2) vs v(1)

to view the inverter transfer characteristic. 4. To save a postscript le of the plots, you need to type

set hcopydevtype=postscript You can then generate a postscript le using hardcopy filename.ps v(1) vs v(2) This produces lename.ps, which you can print or view in a postscript viewer such as ghostview (or convert it to pdf etc). 5. Type quit to exit the NGSPICE shell.

An example to illustrate transient analysis

Consider a transient (time-domain) simulation of a simple CMOS inverter in the TSMC 180nm technology. An inverter is driving a load capacitor, and is driven by a pulse input. We wish to observe the input and output waveforms as well as the currents in the sources of the NMOS and PMOS transistors. The circuit is described as a netlist. single inverter driving a capacitive load * * all comments start with * * * include the model file .include tsmc_spice_180nm.txt * * m1,m2 are transistors * * d g s b model L W drain/source dimensions mp1 2 1 6 7 cmosp L=0.18u W=3.6u PS=10.8u PD=10.8u AS=1.62p AD=1.62p mn1 2 1 8 0 cmosn L=0.18u W=1.8u PS=5.4u PD=5.4u AS=0.81p AD=0.81p * * Note: the drain/source periphery/area must be provided if * you want to model the self-loading correctly. * Vdd v1 7 0 dc 1.8v * add 0V voltage-source to monitor supply * current vIdd 7 6 dc 0v * add 0V voltage-source to monitor current * in nmos source vIss 8 0 dc 0v 3

* input source pwl v4 1 0 pwl(0ns 0v 0.4ns 1.8v 1.0ns 1.8v 1.4ns 0.0v 10.0ns 0.0v) * load capacitor of 150ff C1 2 0 150fF * transient analysis, report * in steps of 0.02ns upto 5ns .tran 0.02ns 5ns .end One thing to note about this description: in order to view currents in a branch of the circuit, one needs to place a 0V voltage source in that branch. The SPICE simulation algorithm treats currents in voltage sources as variables. Place this circuit description in the le inv180nm.cir (the le-name can be arbitrary). Now, type ngspice at the Unix prompt. An NGSPICE shell opens up. You can now use the following sequence to analyze the inverter. 1. Point NGSPICE to the source circuit. source inv180nm.cir 2. Now run the simulator and perform the specied analysis (in this case, transient analysis). run 3. You can now view the results of the simulation using the plot command. Use plot v(1) v(2) to view the inverter input and output waveforms as functions of time. To view the currents in named voltage sources, you can use plot vIdd#branch vIss#branch This gives you the currents in the sources of the PMOS and NMOS transistors. 4. To save a postscript le of the plots, you need to type set hcopydevtype=postscript You can then generate a postscript le using

hardcopy filename.ps v(1) v(2) 5. Type quit to exit the NGSPICE shell. This should be enough to get you started. Read the manual for more details.

You might also like