NGSPICE- Usage and Examples

Similar documents
The Bipolar Junction Transistor- Small Signal Characteristics

Experiment 2 Introduction to PSpice

ECE 310L : LAB 9. Fall 2012 (Hay)

The default account setup for the class should allow you to run HSPICE without any further configuration. To verify this, type:

EE 330 Laboratory 8 Discrete Semiconductor Amplifiers

EECE 488: Short HSPICE Tutorial. Last updated by: Mohammad Beikahmadi January 2013

Xcircuit and Spice. February 26, 2007

EE 230 Lab Lab 9. Prior to Lab

EE 330 Laboratory 8 Discrete Semiconductor Amplifiers

Q.1: Power factor of a linear circuit is defined as the:

MICROELECTRONIC CIRCUIT DESIGN Third Edition

Course Number Section. Electronics I ELEC 311 BB Examination Date Time # of pages. Final August 12, 2005 Three hours 3 Instructor

EECE 488: Short HSPICE. Tutorial. Last updated by: Mohammad Beikahmadi January Original presentation by: Jack Shiah

Lab 2: Discrete BJT Op-Amps (Part I)

Homework Assignment 07

Experiment 4 Op-Amp Resonant Bandpass Filter

PSpice Simulation. The target of computer-aided analysis is to determine the circuit currents and voltages everywhere in the circuit.

ECE4902 C Lab 5 MOSFET Common Source Amplifier with Active Load Bandwidth of MOSFET Common Source Amplifier: Resistive Load / Active Load

Tsung-Chu Huang. Department of Electronic Engineering National Changhua University of Education /10/4-5 TCH NCUE

EE 2274 RC and Op Amp Circuit Completed Prior to Coming to Lab. Prelab Part I: RC Circuit

Homework Assignment 11

Experiment No. 9 DESIGN AND CHARACTERISTICS OF COMMON BASE AND COMMON COLLECTOR AMPLIFIERS

Chapter 8. Chapter 9. Chapter 6. Chapter 10. Chapter 11. Chapter 7

The Miller Approximation. CE Frequency Response. The exact analysis is worked out on pp of H&S.

Experiments #6. Differential Amplifier

Introduction to SwitcherCAD

Experiment 9- Single Stage Amplifiers with Passive Loads - MOS

ECE 442 Solid State Devices & Circuits. 15. Differential Amplifiers

MICROELECTRONIC CIRCUIT DESIGN Fifth Edition

Homework Assignment 07

Microelectronics Exercises of Topic 5 ICT Systems Engineering EPSEM - UPC

Chapter 12: Electronic Circuit Simulation and Layout Software

BJT Amplifier. Superposition principle (linear amplifier)

Subject Code: Model Answer Page No: / N

Circuit Simulation with SPICE OPUS

I1 19u 5V R11 1MEG IDC Q7 Q2N3904 Q2N3904. Figure 3.1 A scaled down 741 op amp used in this lab

Experiment 8 Frequency Response

Lab 6: MOSFET AMPLIFIER

Lab 1 - Revisited. Oscilloscope demo IAP Lecture 2 1

Dev Bhoomi Institute Of Technology Department of Electronics and Communication Engineering PRACTICAL INSTRUCTION SHEET

PURPOSE: NOTE: Be sure to record ALL results in your laboratory notebook.

OBJECTIVE TYPE QUESTIONS

Shankersinh Vaghela Bapu Institute of Technology INDEX

Experiment 10 Current Sources and Voltage Sources

Figure 1. Main window (Common Interface Window), CIW opens and from the pull down menus you can start your design. Figure 2.

University of Michigan EECS 311: Electronic Circuits Fall 2008 LAB 4 SINGLE STAGE AMPLIFIER

6.002 Circuits and Electronics Final Exam Practice Set 1

EE4902 C Lab 5 MOSFET Common Source Amplifier with Active Load Bandwidth of MOSFET Common Source Amplifier: Resistive Load / Active Load

Improving Amplifier Voltage Gain

ENEE 307 Laboratory#2 (n-mosfet, p-mosfet, and a single n-mosfet amplifier in the common source configuration)

An Introductory Guide to Circuit Simulation using NI Multisim 12

4.2.2 Metal Oxide Semiconductor Field Effect Transistor (MOSFET)

Integrated Circuit Amplifiers. Comparison of MOSFETs and BJTs

In a cascade configuration, the overall voltage and current gains are given by:

Metal-Oxide-Silicon (MOS) devices PMOS. n-type

EE 320 L LABORATORY 9: MOSFET TRANSISTOR CHARACTERIZATIONS. by Ming Zhu UNIVERSITY OF NEVADA, LAS VEGAS 1. OBJECTIVE 2. COMPONENTS & EQUIPMENT

Document Name: Electronic Circuits Lab. Facebook: Twitter:

UMAINE ECE Morse Code ROM and Transmitter at ISM Band Frequency

EE320L Electronics I. Laboratory. Laboratory Exercise #2. Basic Op-Amp Circuits. Angsuman Roy. Department of Electrical and Computer Engineering

Amplifier Frequency Response, Feedback, Oscillations; Op-Amp Block Diagram and Gain-Bandwidth Product

(b) 25% (b) increases

Mentor Analog Simulators

Phy 335, Unit 4 Transistors and transistor circuits (part one)

Introduction to PSpice

A Short SPICE Tutorial

Final Exam: Electronics 323 December 14, 2010

Simulation Using WinSPICE

Well we know that the battery Vcc must be 9V, so that is taken care of.

55:041 Electronic Circuits

MOSFET: Mxxx nd ng ns nb modelname W=value L=value Ad As Pd Ps

SAMPLE FINAL EXAMINATION FALL TERM

Field Effect Transistors

ENGR4300 Test 3A Fall 2002

ECE 3274 MOSFET CD Amplifier Project

The Common Source JFET Amplifier

Common-Source Amplifiers

ECE 201 LAB 6 INTRODUCTION TO SPICE/PSPICE

Experiment 5 Single-Stage MOS Amplifiers

EJERCICIOS DE COMPONENTES ELECTRÓNICOS. 1 er cuatrimestre

Facility of Engineering. Biomedical Engineering Department. Medical Electronic Lab BME (317) Post-lab Forms

NOVEMBER 29, 2017 COURSE PROJECT: CMOS TRANSIMPEDANCE AMPLIFIER ECG 720 ADVANCED ANALOG IC DESIGN ERIC MONAHAN

EE 368 Electronics Lab. Experiment 10 Operational Amplifier Applications (2)

Linear electronic. Lecture No. 1

LINEAR IC APPLICATIONS

Short Channel Bandgap Voltage Reference

Reading. Lecture 17: MOS transistors digital. Context. Digital techniques:

SPICE FOR POWER ELECTRONICS AND ELECTRIC POWER

Paper-1 (Circuit Analysis) UNIT-I

Analog Circuits Prof. Jayanta Mukherjee Department of Electrical Engineering Indian Institute of Technology - Bombay

EXPT NO: 1.A. COMMON EMITTER AMPLIFIER (Software) PRELAB:

ENGR 201 Homework, Fall 2018

INTRODUCTION TO CIRCUIT SIMULATION USING SPICE

THE SPICE BOOK. Andrei Vladimirescu. John Wiley & Sons, Inc. New York Chichester Brisbane Toronto Singapore

Electronics I ELEC 311/1 BB. Final August 14, hours 6

UNIT I Introduction to DC & AC circuits

Chapter 13 Oscillators and Data Converters

A Brief Handout for Introduction to

EE 2274 MOSFET BASICS

EE 105 MICROELECTRONIC DEVICES & CIRCUITS FALL 2018 C. Nguyen. Laboratory 2: Characterization of the 741 Op Amp Preliminary Exercises

4 Transistors. 4.1 IV Relations

Transcription:

NGSPICE- Usage and Examples Debapratim Ghosh deba21pratim@gmail.com Electronic Systems Group Department of Electrical Engineering Indian Institute of Technology Bombay February 2013 Debapratim Ghosh Dept. of EE, IIT Bombay 1/20

Introduction Q: What is electronic design? A: Given some desired specifications to be achieved, we want to have a system which can be made by interconnecting known elements. Specifications- We want an amplifier with a gain of 100. Known Elements- This amplifier can be made using a transistor (BJT or MOSFET), or an op-amp, along with some resistors. Known elements are those whose behaviour can be represented by means of algorithms, equations or specific models. In short, known elements are those whose behaviour is familiar to us. If we wish to design complex circuits, a circuit simulator is a useful tool. Debapratim Ghosh Dept. of EE, IIT Bombay 2/20

What is NGSPICE? SPICE is an acronym for for Simulation Program with Integrated Circuit Emphasis. First developed at UC Berkeley, it is the origin of most modern simulators. NGSPICE is an open source mixed-signal circuit simulator. It is the result of combining existing SPICE features with some extra analyses, modeling methods and device simulation features. It is freely available for use in Linux and Windows. It is recommended to use Linux for NGSPICE. NGSPICE requires you to describe your circuit as a netlist. A netlist is defined as a set of circuit components and their interconnections. Debapratim Ghosh Dept. of EE, IIT Bombay 3/20

NGSPICE provides you with... Basic Circuit Elements Passive components- resistors, capacitors, inductors, etc. Sources- independent voltage and current sources, controlled sources Semiconductor Devices Pre-defined circuit elements such as diodes and transistors Allows you to define or include models of specific devices e.g. specialized transistors and op-amps Circuit Analysis Techniques DC and AC analyses Transient and Steady-state analyses Pole-Zero, Noise analyses and more Debapratim Ghosh Dept. of EE, IIT Bombay 4/20

Getting Started with NGSPICE (Linux) You can use any text editor (say, gedit) to write your circuit netlist. The first line in an NGSPICE file is not executed. It is used to describe the aim of the circuit being simulated. All NGSPICE comments start with an asterix, i.e. * The NGSPICE file comprises of the circuit netlist followed by the details of 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, called prefix, i.e. resistors begin with r, capacitors with c, bipolar transistors with q, MOSFETs with m, voltage sources with v and so on. All circuit nodes are named/numbered. The netlist requires one ground node (zero potential). Debapratim Ghosh Dept. of EE, IIT Bombay 5/20

Example I- Transient Analysis of an RC Circuit A simple RC circuit, excited by a user-defined signal V in. We want to find the capacitor voltage i.e. V c(t). The netlist is as shown. V in 1 1 kω 2 + 5 V V in + 1 µf Vc(t) 10ms 11ms 20ms t 0 - RC Circuit Transient Response *resistor connected between nodes 1 and 2 r1 1 2 1k *capacitor connected between nodes 2 and 0 c1 2 0 1u *piecewise linear input voltage vin 1 0 pwl (0 0 10ms 0 11ms 5v 20ms 5v) *transient analysis for 20ms, step size 0.02ms.tran 0.02ms 20ms *defining the run-time control functions.control run *plotting input and output voltages plot v(1) v(2).endc.end Debapratim Ghosh Dept. of EE, IIT Bombay 6/20

Example I- Transient Analysis of an RC Circuit (cont d) Once you have typed your netlist, save it with an appropriate name, say rcckt.cir. Open the Linux terminal, and change the working directory to the folder where your netlist file is saved. e.g. if the file is in the Documents folder, type cd /Documents in the the command prompt. Run the netlist file using the command ngspice rcckt.cir And that s it- your netlist should run! A snapshot is as shown. Debapratim Ghosh Dept. of EE, IIT Bombay 7/20

Inside the NGSPICE Shell Once any netlist is run by NGSPICE, the terminal is hooked to an NGSPICE shell, with a prompt such as ngspice 1 ->. You can exit the NGSPICE shell anytime by typing exit or quit. It is not always necessary to quit NGSPICE every time to run a new netlist. You can use the command source <filename>.cir to simulate a new netlist file using the NGSPICE prompt. The commands specified between.control and.endc in the netlist file may be used in the NGSPICE prompt separately. The waveforms may be saved as a postscript file by clicking on the hardcopy icon on the waveform window. However, this saves it as a default filename in the root directory. A better way to save the waveform in the working directory would be to use the following commands (say for the R-C circuit discussed above) set hcopydevtype=postscript hardcopy rcplot.ps v(1) v(2) You can even save the plots using different colours. Read the NGSPICE manual for that, and much more! Debapratim Ghosh Dept. of EE, IIT Bombay 8/20

Example II- AC Analysis of RC Circuit For the same R-C circuit discussed in Example I, let us do the small-signal AC analysis, i.e. find its frequency response.after running this, you should be able to see two plot windows- a magnitude (db) plot and a phase (degrees) plot. RC Circuit Frequency Response r1 1 2 1k c1 2 0 1u *Specifying an AC source with zero dc vin 1 0 dc 0 ac 1 *AC analysis for 1 Hz to 1MHz, 10 points per decade.ac dec 10 1 1Meg.control run *Magnitude db plot for v(2) on log scale plot vdb(2) xlog *Phase degrees plot for v(2) on log scale plot {57.29*vp(2)} xlog.endc.end Debapratim Ghosh Dept. of EE, IIT Bombay 9/20

Example III- DC Analysis of a Shunt Clipper A DC analysis involves varying a voltage or a current source output throughout a range of values. Consider the following shunt clipper circuit. We wish to find the V out v/s V in characteristic for this circuit, say for -5 V V in +5 V. 1 1 kω 2 V in + 0 3 2 V V out Shunt Clipper DC analysis r1 1 2 1k *Specifying a default diode p n d1 2 3 *Independent DC source of 2V vdc 3 0 dc 2 *Independent DC source whose voltage is to be varied vin 1 0 dc 0 *DC Analysis on source vin, to vary from -5 to +5V.dc vin -5 5 0.01.control run plot v(2) vs v(1).endc.end Debapratim Ghosh Dept. of EE, IIT Bombay 10/20

Example IV- I-V Characteristics of a Transistor So far, we have only used default models of all circuit components provided by NGSPICE. However, this is not always the case as we would like to use special devices e.g. 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 vary greatly from device to device, we will require a well defined model of BC547, rather than the default model provided by NGSPICE. The model file, if available, should be saved in the same working directory as your netlist, and can be invoked using the.include command. To measure current in a branch, keep a DC voltage source of 0 V in that branch. If this source is named v1, the current in the branch is represented by v1#branch. Debapratim Ghosh Dept. of EE, IIT Bombay 11/20

Example IV- I-V Characteristics of a Transistor (cont d) We can use this simple circuit, using the B-E junction of the transistor like a diode, keeping the collector open. 1 470 Ω 2 0 V + 3 4 V in + 0 I-V Characteristics of BC547 *Including the BC547 model file.include bc547.txt vin 1 0 dc 5v r1 1 2 470 *Voltage source of 0 V to measure current vib 2 3 dc 0v *Specifying BJTs in this manner- *name collector base emitter modelname as in model file q1 4 3 0 bc547a *Vin for DC analysis.dc vin -3 3 0.01.control run plot vib#branch vs v(3).endc.end Debapratim Ghosh Dept. of EE, IIT Bombay 12/20

Example V- I-V Characteristics of a MOSFET Let us now characterize the the output I D v/s V DS characteristics of an NMOS transistor. Like the BJT, we will use a specific MOSFET model- a CD4007. The I D v/s V DS characteristics can easily be studied by fixing V GS at 3.5 V and varying V DS from 0 to 5 V. We use the following circuit 0 V 4 5 + V GG 1 680 Ω 2 3 + + + - V GS - 0 100 Ω + V DS I D V DD Debapratim Ghosh Dept. of EE, IIT Bombay 13/20

Example V- I-V Characteristics of a MOSFET (cont d) I-V Characteristics of CD4007 *Including the CD4007 model file.include cd4007.txt *Fixing gate bias at 3.5V vgg 1 0 dc 3.5v rg 1 2 680 *Specifying NMOS in this manner- *name drain gate source body modelname as in model file m1 3 2 0 0 NMOS4007 rd 3 4 100 *DC source of 0v to measure current vid 5 4 dc 0v vdd 5 0 dc 0v *DC analysis to sweep vds from 0 to 5V.dc vdd 0 5 0.01.control run plot vid#branch vs v(3).endc.end Debapratim Ghosh Dept. of EE, IIT Bombay 14/20

Use of Subcircuits We have seen how to use electronic devices to build a circuit and test it using NGSPICE. Various electronic devices have their own existing model files that represent the electrical behaviour of that device, which we can use in a netlist. What if we now have an existing circuit, and want to use it to build bigger circuits? A typical example is using an op-amp (operational amplifier) to design a simple amplifier or a filter. Note that, an op-amp is a pre-existing circuit and not a device. It is made of many transistors. NGSPICE allows us to define an op-amp as a subcircuit. A subcircuit is much like an IC- we know its pins to interface with the outside world, but we need not be familiar with the inside circuit! A subcircuit is a collection of devices familiar to SPICE. A subcircuit is identified by the prefix x. The usage is very similar to that of a model file. Debapratim Ghosh Dept. of EE, IIT Bombay 15/20

Example- Integrator using op-amp (741) 1 MΩ 5 1 kω 0.1 µf V in 0 1 0 2 + 3 + 15 V - 15 V 4 V out Differentiator using op-amp 741 *Including the predefined op-amp subcircuit file.include ua741.txt *Connections as mentioned in subcircuit file x1 0 1 2 3 4 UA741 r1 5 1 1k c1 4 1 0.1u rf 4 1 1Meg vcc 2 0 dc 15v vee 3 0 dc -15v *Giving a sinusoidal input vin 5 0 sin (0 1v 1k 0 0).tran 0.02ms 6ms.control run plot v(5) v(4).endc.end Debapratim Ghosh Dept. of EE, IIT Bombay 16/20

Exercises Consider the shunt clipper shown in Example III. Change (a) the diode connections (b) the 2 V battery polarity and simulate to observe V out v/s V in variation. For each case, give a 1 khz sinusoidal input and observe the output waveform (six cycles). Write an NGSPICE netlist for a diode-based bridge rectifier and simulate it to observe the rectified voltage across a load resistor, by giving a 12V, 50Hz input. Also, observe the V out v/s V in transfer characteristics. Simulate a CMOS inverter using MOSFETs from CD4007 library. Provide a piecewise-linear input with the following (V, t) coordinates- (0,0) (0,10 ns) (5 V,15 ns) (5 V,50 ns) (0 V,55 ns) (0 V, 60 ns). Observe the drain current of the PMOS transistor as a function of time. Study the CD4007 model file provided to you. How many parameters can you identify? Debapratim Ghosh Dept. of EE, IIT Bombay 17/20

NGSPICE Application- Study of Elmore Delay After a change in input voltage, the time taken by the output to reach to its final value is called delay. This is a critical issue in integrated circuit (IC) design. Consider the source-load interconnection as shown. metallic interconnect Source + Load The metal lines have some resistance R, and the gap between them lead to some capacitance C. But are R and C lumped or disrtibuted? R R/2 R/2 R/n R/n R/n + + C + C/2 C/2 C/n C/n C/n Lumped Distrinuted 2-stage Distributed n-stage Debapratim Ghosh Dept. of EE, IIT Bombay 18/20

NGSPICE Application- Study of Elmore Delay (cont d) The delay can be approximated as the effective R-C time constant of the circuit. For a lumped (single stage) approximation, the delay is T = RC. For a two stage approximation, the delay is T = 0.75RC. For an n stage approximation, the delay can be shown to be T = n+1 2n RC. Thus, for a very large n (distributed effect), the delay is then given by T = lim 2n n n+1 This is known as Elmore s Delay model. RC = 0.5RC W want to verify this using NGSPICE. But, it is not possible to describe, say 1000 R-C networks in the NGSPICE netlist! Then how do we do this? Debapratim Ghosh Dept. of EE, IIT Bombay 19/20

NGSPICE Application- Study of Elmore Delay (cont d) Consider two interconnects we wish to simulate for Elmore delay, with length l = 1 mm, width and thickness w, t = 5 µm and gap d = 10 nm. We can write a C/C++ program that will take these dimensions (length, width, separation, etc.) as input and compute the total line R and C. The program will also ask the user for the number of R-C stages for delay approximation. Based on the number of stages, R and C, the program will write this data into an NGSPICE netlist file. This can be easily automated by feeding the number of stages n as a loop counter and having the stage resistance and capacitance as R/n and C/n respectively. In effect, rather than writing thousands of lines in an NGSPICE netlist, a C/C++ program can be used to automate the netlist creation. This is where the real power of NGSPICE lies- its ease of use in scripting! Debapratim Ghosh Dept. of EE, IIT Bombay 20/20