Ngspice Tutorial
Ngspice Tutorial
Ngspice Tutorial
EEE 52 1516s2
What is NGSPICE
mixed-level/mixed-signal circuit simulator based
on three open source software packages
Spice3f5, Cider1b1, Xspice
Running NGSPICE
After extracting, run the executable file
ngspice under the bin folder.
ngspice terminal
Nodes
Parameter
* CE AMPLIFIER *
V1
I1
D1
R1
Q1
1
1
2
1
0
0
2
0
3
2
5V
50uA
50kOhms
3
Element Description
Capacitor
Diode
I
L
M
Q
R
V
Current Source
Inductor
MOSFET
BJT
Resistor
Voltage Source
* CE AMPLIFIER *
V1
I1
D1
R1
Q1
1
1
2
1
0
0
2
0
3
2
5V
50uA
50kOhms
3
Name
Factor
Tera
1012
Giga
109
Meg
Mega
106
Kilo
103
mil
Mil
25.4x10-6
milli
10-3
Micro
10-6
Nano
10-9
Pico
10-12
femto
10-15
13 (integer)
-1 (negative integer)
3.14159 (floating point)
1e-16, 1.23e6 (integer exponent)
1Meg (scaling factor)
Defining variables
Variables can be defined using .param
Easier to change variable definition than to edit
numbers at different sections of the code
Helpful especially for long codes.
Used for parametric analysis (later)
* Resistors *
* Resistors *
.param Rx=1kohm
R1 1 2 1kohm
R2 3 4 1kohm
R3 5 6 1kohm
R1 1 2 Rx
R2 3 4 Rx
R3 5 6 Rx
Setting Up Simulations
.DC
Format:
.dc src1 start1 stop1 incr1 [src2
start2 stop2 incr2]
src can be an independent voltage/current source, a
resistor, or temperature
Examples:
.dc R1 10k 100k 2.5k
.dc VDS 0 10 0.5 VGS 0 5 1
Setting Up Simulations
.AC AC small signal analysis
.OP operating point
.TF transfer function
Like AC analysis but evaluated only at 0Hz or DC
Open ngspice
Go to the directory that contains your netlist
through the terminal (cd [directory])
Load the spice file (source [filename])
Run the simulation (run)
View the results (plot/meas/print)
SPICE demo