Ngspice 2
Ngspice 2
Ngspice 2
Debapratim Ghosh
deba21pratim@gmail.com
Semiconductor Devices
Pre-defined circuit elements such as diodes and transistors
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.
All circuit nodes are named/numbered. The netlist requires one ground
node (zero potential).
1 1 k 2
Vin +
replacements
5V
Vin +
1 F Vc (t)
0 -
10ms 11ms 20ms t
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!
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.
+ 3
Vin Vout
2V
0
+
2
Vin +
0
0V
4 5
+
680 100 ID
1 2
3 +
VDS + VDD
+
VGG +
VGS -
- 0
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.
1 k 0.1 F
5
2 + 15 V
Vin 1
0 Vout
+ 4
0 3 - 15 V
Consider the shunt clipper shown in Example III. Change (a) the diode
connections (b) the 2 V battery polarity and simulate to observe Vout v/s
Vin 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 Vout v/s Vin 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?
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
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.
n+1
For an n stage approximation, the delay can be shown to be T = 2n RC.
Thus, for a very large n (distributed effect), the delay is then given by
n+1
T = lim RC = 0.5RC
n 2n
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.