0% found this document useful (0 votes)
137 views

NGspice Basics

This document provides an introduction to using NGSPICE, an open source circuit simulator, including: - NGSPICE allows users to describe circuits as netlists of components and analyze them through simulations. - It provides basic circuit elements, semiconductor devices, and circuit analysis techniques like DC, AC, transient, and noise analyses. - Examples demonstrate setting up and running transient and AC analyses on an RC circuit in NGSPICE, including using subcircuits to simplify netlists for repeated components.

Uploaded by

vishal kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views

NGspice Basics

This document provides an introduction to using NGSPICE, an open source circuit simulator, including: - NGSPICE allows users to describe circuits as netlists of components and analyze them through simulations. - It provides basic circuit elements, semiconductor devices, and circuit analysis techniques like DC, AC, transient, and noise analyses. - Examples demonstrate setting up and running transient and AC analyses on an RC circuit in NGSPICE, including using subcircuits to simplify netlists for repeated components.

Uploaded by

vishal kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

NGSPICE- Usage and Examples

Debapratim Ghosh Mohamed Jabir

Wadhwani Electronics Laboratory (WEL)


Department of Electrical Engineering
Indian Institute of Technology Bombay
July 2017

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 1/17
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 & Mohamed Jabir Dept. of EE, IIT Bombay 2/17
What is NGSPICE?

I 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.

I 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.

I It is freely available for use in Linux and Windows. It is recommended to


use Linux for NGSPICE.

I 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 & Mohamed Jabir Dept. of EE, IIT Bombay 3/17
NGSPICE provides you with....

Basic Circuit Elements


I Passive components- resistors, capacitors, inductors, etc.
I Sources- independent voltage and current sources, controlled sources

Semiconductor Devices
I Pre-defined circuit elements such as diodes and transistors
I Allows you to define or include models of specific devices e.g.
specialized transistors and op-amps

Circuit Analysis Techniques


I DC and AC analyses
I Transient and Steady-state analyses
I Pole-Zero, Noise analyses and more

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 4/17
Getting Started with NGSPICE (Linux)
I 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.

I All NGSPICE comments start with an asterix, i.e. ‘*’

I The NGSPICE file comprises of the circuit netlist followed by the details
of the analysis the user wishes to do.

I NGSPICE files are usually saved with the extension ‘.cir’ or ‘.spice’.

I 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.

I All circuit nodes are named/numbered. The netlist requires one ground
node (zero potential).

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 5/17
Inside the NGSPICE Shell
I 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.

I 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.

I The commands specified between .control and .endc in the netlist file may be
used in the NGSPICE prompt separately.

I 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)

I You can even save the plots using different colours. Read the NGSPICE manual
for that, and much more!

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 6/17
Example I- Transient Analysis of an RC Circuit
A simple RC circuit, excited by a user-defined signal Vin . We want to find the capacitor voltage i.e. Vc (t). The
netlist is as shown.

1 1k 2
vin +
5V
vin + 1u vc

0 -
10ms 11ms 20ms t

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 & Mohamed Jabir Dept. of EE, IIT Bombay 7/17
Example I- Transient Analysis of an RC Circuit (cont’d)
I Once you have typed your netlist, save it with an appropriate name, say
rcCkt.cir.
I 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.
I Run the netlist file using the command ngspice rcCkt.cir
I And that’s it- your netlist should run! A snapshot is as shown.

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 8/17
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 & Mohamed Jabir Dept. of EE, IIT Bombay 9/17
Subcircuits

I We have seen how to use electronic devices to build a circuit and test it
using NGSPICE.
I 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?
I 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.
I 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!
I 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 & Mohamed Jabir Dept. of EE, IIT Bombay 10/17
Example - Subcircuits
See the circuit shown below.
IN R1 1 R2 2 R3 OUT
1 kΩ 1 kΩ 1 kΩ
Vin C1 C2 C3
5 Vp-p 1 uF 1 uF 1 uF
0 Voffset
1 kHz

I The netlist of the circuit will have redundant initiations of resistors and
capacitors.
I Since all resistors and capacitors are in the same orientation, a subcircuit
can be created with these components as shown below.

In R Out
1 kΩ
C
resistor 1 uF
com

I The above subcircuit has 3 terminals, In, Out and com. It can be invoked
multiple times to form the complete circuit.
Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 11/17
Example - Subcircuits (cont’d)
Let us do a transient analysis for the circuit discussed previously.
RC Circuit Transient Analysis using Subcircuits
*Defining the Subcircuit ’RC subcircuit’
.subckt RC subcircuit In Out com
r In Out 1K
c Out com 1u
.ends
*Subcircuit definition ends here
vsin IN gnd sin(0 2.5 1K 0 0)
Invoking RC subcircuit
xrc 1 IN 1 gnd RC subcircuit
xrc 2 1 2 gnd RC subcircuit
xrc 3 2 OUT gnd RC subcircuit
.control
tran 0.02m 40m
plot v(IN)
plot v(OUT)
.endc
.end

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 12/17
Example - Subcircuits (cont’d)
Thus, a subcircuit can be invoked multiple times to form the complete circuit.
We can also initiate the components of the subcircuit with desired values,
while its being invoked.
RC Circuit Transient Analysis using Subcircuits
.subckt RC subcircuit In Out com r 1=1K c 1=1u
r In Out r 1
c Out com c 1
.ends
vsin IN gnd sin(0 2.5 1K 0 0)
xrc 1 IN 1 gnd RC subcircuit
xrc 2 1 2 gnd RC subcircuit r 1=100 c 1=0.1u
xrc 3 2 OUT gnd RC subcircuit
.control
tran 0.02m 5m
plot v(IN) v(OUT)
.endc
.end
Here, r 1 and c 1 are the parameters of the subcircuit, with default values of 1KΩ and
1µF respctively. The circuit for the above netlist will have R2 and C2 as 100Ω and
0.1µF respectively. All other resistors and capacitors will have the default values of
subcircuit parameters.
Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 13/17
Example- Integrator using op-amp (741)
1 MΩ

1 kΩ 0.1 µF
5
2 + 15 V
Vin 1 −
0 Vout
+ 4
0 3 - 15 V

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 & Mohamed Jabir Dept. of EE, IIT Bombay 14/17
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 Vout v/s Vin
characteristic for this circuit, say for -5 V ≤ Vin ≤ +5 V.
1 1 kΩ 2

+ 3
Vin − Vout
2V
0

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 & Mohamed Jabir Dept. of EE, IIT Bombay 15/17
MOSFET Characterization- Family of Curves

Here, we will look at how to characterise a MOSFET. We will do it by


generating a family of curves. Consider the circuit shown below,

Id
+ Vds
− 1.8 V
+ Vgs
− 1.8 V

To generate the family of curves, we change one of the voltages, say Vgs in
steps, while the other, Vds is varied its entire range for each step of Vgs.
Thus, we can plot the MOSFET current, Id (for various step values of Vgs)
versus Vds.

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 16/17
MOSFET Characterization- Family of Curves (cont’d)

Let us generate the id v/s vds characteristics for various values of vgs. You
should be getting the I-V characteristics as shown below.

Family of Curves

*Model file for the MOSFET


.include tsmc spice 180nm.txt

*Usually, the order of terminals are


*drain, gate, source and body respectively

m1 d g gnd gnd CMOSN


vgs g gnd dc 1.8V
vds dummy gnd dc 1.8V
vdummy dummy d dc 0V
.control
dc vds 0 1.8 0.02 vgs 0 1 0.2
plot i(vdummy)
.endc
.end

Debapratim Ghosh & Mohamed Jabir Dept. of EE, IIT Bombay 17/17

You might also like