Buscar

ngspice-manual

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 3, do total de 695 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 6, do total de 695 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 9, do total de 695 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Prévia do material em texto

Ngspice User’s Manual
Version 36 plus
(ngspice development version)
Holger Vogt, Marcel Hendrix, Paolo Nenzi, Dietmar Warning
January 18, 2022
2
Locations
The project and download pages of ngspice may be found at
Ngspice home page http://ngspice.sourceforge.net/
Project page at SourceForge http://sourceforge.net/projects/ngspice/
Download page at SourceForge https://sourceforge.net/projects/ngspice/files/ng-spice-
rework/
Git source download https://sourceforge.net/p/ngspice/ngspice/ci/master/tree/
Status
This manual is a work in progress. Some to-dos are listed in Chapt. 24.3. More is surely
needed. You are invited to report bugs, missing items, wrongly described items, bad
English style, etc.
How to use this Manual
The manual is a “work in progress.” It may accompany a specific ngspice release, e.g.
ngspice-35 as manual version 35. If its name contains ‘Version xxplus’, it describes the
actual code status, found at the date of issue in the Git Source Code Management (SCM)
tool. This manual is intended to provide a complete description of ngspice’s functionality,
features, commands, and procedures. This manual is not a book about learning SPICE
usage, however the novice user may find some hints how to start using ngspice. Chapter
21.1 gives a short introduction how to set up and simulate a small circuit. Chapter 32 is
about compiling and installing ngspice from a tarball or the actual Git source code, which
you may find on the ngspice web pages. If you are running a specific Linux distribution,
you may check if it provides ngspice as part of the package. Some are listed here.
License
This document is covered by the Creative Commons Attribution Share-Alike (CC-BY-SA)
v4.0..
Part of chapters 12 and 25-27 are in the public domain.
Chapter 30 is covered by New BSD (chapt. 33.3.2).
http://ngspice.sourceforge.net/
http://sourceforge.net/projects/ngspice/
https://sourceforge.net/projects/ngspice/files/ng-spice-rework/
https://sourceforge.net/projects/ngspice/files/ng-spice-rework/
https://sourceforge.net/p/ngspice/ngspice/ci/master/tree/
http://ngspice.sourceforge.net/download.html
http://ngspice.sourceforge.net/packages.html
https://creativecommons.org/licenses/by-sa/4.0/
https://creativecommons.org/licenses/by-sa/4.0/
Part I
Ngspice User’s Manual
3
Contents
I Ngspice User’s Manual 3
1 Introduction 33
1.1 Simulation Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.1.1 Analog Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.1.2 Device Models for Analog Simulation . . . . . . . . . . . . . . . . . 34
1.1.3 Digital Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.1.4 Mixed-Signal Simulation . . . . . . . . . . . . . . . . . . . . . . . . 35
1.1.5 Mixed-Level Simulation . . . . . . . . . . . . . . . . . . . . . . . . 36
1.2 Supported Analyses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.2.1 DC Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.2.2 AC Small-Signal Analysis . . . . . . . . . . . . . . . . . . . . . . . 38
1.2.3 Transient Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
1.2.4 Pole-Zero Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.2.5 Small-Signal Distortion Analysis . . . . . . . . . . . . . . . . . . . . 39
1.2.6 Sensitivity Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.2.7 Noise Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
1.2.8 Periodic Steady State Analysis . . . . . . . . . . . . . . . . . . . . . 40
1.3 Analysis at Different Temperatures . . . . . . . . . . . . . . . . . . . . . . 40
1.3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
1.3.2 Controlling the temperature . . . . . . . . . . . . . . . . . . . . . . 42
1.4 Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.4.1 Voltage convergence criterion . . . . . . . . . . . . . . . . . . . . . 43
1.4.2 Current convergence criterion . . . . . . . . . . . . . . . . . . . . . 44
1.4.3 Convergence failure . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5
6 CONTENTS
2 Circuit Description 45
2.1 General Structure and Conventions . . . . . . . . . . . . . . . . . . . . . . 45
2.1.1 Input file structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.1.2 Syntax check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.1.3 Circuit elements (device instances) . . . . . . . . . . . . . . . . . . 46
2.1.4 Some naming conventions . . . . . . . . . . . . . . . . . . . . . . . 47
2.2 Dot commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.3 Basic lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.3.1 .TITLE line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.3.2 .END Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.3.3 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.3.4 End-of-line comments . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.3.5 Continuation lines . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.4 .MODEL Device Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.5 .SUBCKT Subcircuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.5.1 .SUBCKT Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.5.2 .ENDS Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.5.3 Subcircuit Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.6 .GLOBAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.7 .INCLUDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.8 .LIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.9 .PARAM Parametric netlists . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.9.1 .param line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.9.2 Brace expressions in circuit elements: . . . . . . . . . . . . . . . . . 57
2.9.3 Subcircuit parameters . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.9.4 Symbol scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.9.5 Syntax of expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.9.6 Reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.9.7 A word of caution on the three ngspice expression parsers . . . . . . 62
2.10 .FUNC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.11 .CSPARAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.12 .TEMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.13 .IF Condition-Controlled Netlist . . . . . . . . . . . . . . . . . . . . . . . . 64
2.14 Parameters, functions, expressions, and command scripts . . . . . . . . . . 66
2.14.1 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.14.2 Nonlinear sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.14.3 Control commands, Command scripts . . . . . . . . . . . . . . . . . 66
CONTENTS 7
3 Circuit Elements and Models 69
3.1 About netlists, device instances, models and model parameters . . . . . . . 69
3.2 General options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.2.1 Paralleling devices with multiplier m . . . . . . . . . . . . . . . . . 70
3.2.2 Instance and model parameters . . . . . . . . . . . . . . . . . . . . 72
3.2.3 Model binning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.2.4 Initial conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.3 Elementary Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.3.1 Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.3.2 Semiconductor Resistors .. . . . . . . . . . . . . . . . . . . . . . . 76
3.3.3 Semiconductor Resistor Model (R) . . . . . . . . . . . . . . . . . . 76
3.3.4 Resistors, dependent on expressions (behavioral resistor) . . . . . . 78
3.3.5 Resistor with nonlinear r2_cmc model . . . . . . . . . . . . . . . . 78
3.3.6 Capacitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.3.7 Semiconductor Capacitors . . . . . . . . . . . . . . . . . . . . . . . 80
3.3.8 Semiconductor Capacitor Model (C) . . . . . . . . . . . . . . . . . 80
3.3.9 Capacitors, dependent on expressions (behavioral capacitor) . . . . 82
3.3.10 Inductors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.3.11 Inductor model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.3.12 Coupled (Mutual) Inductors . . . . . . . . . . . . . . . . . . . . . . 85
3.3.13 Inductors, dependent on expressions (behavioral inductor) . . . . . 86
3.3.14 Capacitor or inductor with initial conditions . . . . . . . . . . . . . 87
3.3.15 Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
3.3.16 Switch Model (SW/CSW) . . . . . . . . . . . . . . . . . . . . . . . 89
4 Voltage and Current Sources 91
4.1 Independent Sources for Voltage or Current . . . . . . . . . . . . . . . . . 91
4.1.1 Pulse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.1.2 Sinusoidal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.1.3 Exponential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.4 Piece-Wise Linear . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.5 Single-Frequency FM . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.1.6 Amplitude modulated source (AM) . . . . . . . . . . . . . . . . . . 95
4.1.7 Transient noise source . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.1.8 Random voltage source . . . . . . . . . . . . . . . . . . . . . . . . . 97
8 CONTENTS
4.1.9 External voltage or current input . . . . . . . . . . . . . . . . . . . 97
4.1.10 Arbitrary Phase Sources . . . . . . . . . . . . . . . . . . . . . . . . 98
4.2 Linear Dependent Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.2.1 Gxxxx: Linear Voltage-Controlled Current Sources (VCCS) . . . . 98
4.2.2 Exxxx: Linear Voltage-Controlled Voltage Sources (VCVS) . . . . . 99
4.2.3 Fxxxx: Linear Current-Controlled Current Sources (CCCS) . . . . 99
4.2.4 Hxxxx: Linear Current-Controlled Voltage Sources (CCVS) . . . . 99
4.2.5 Polynomial Source Compatibility . . . . . . . . . . . . . . . . . . . 100
5 Non-linear Dependent Sources (Behavioral Sources) 101
5.1 Bxxxx: Nonlinear dependent source (ASRC) . . . . . . . . . . . . . . . . . 101
5.1.1 Syntax and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5.1.2 Special B-Source Variables time, temper, hertz . . . . . . . . . . . . 105
5.1.3 par(’expression’) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.1.4 Piecewise Linear Function: pwl . . . . . . . . . . . . . . . . . . . . 105
5.2 Exxxx: non-linear voltage source . . . . . . . . . . . . . . . . . . . . . . . 108
5.2.1 VOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
5.2.2 VALUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
5.2.3 TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
5.2.4 POLY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
5.2.5 LAPLACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
5.3 Gxxxx: non-linear current source . . . . . . . . . . . . . . . . . . . . . . . 110
5.3.1 CUR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.3.2 VALUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.3.3 TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.3.4 POLY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.3.5 LAPLACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.3.6 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.4 Debugging a behavioral source . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.5 POLY Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.5.1 E voltage source, G current source . . . . . . . . . . . . . . . . . . 114
5.5.2 F voltage source, H current source . . . . . . . . . . . . . . . . . . . 114
CONTENTS 9
6 Transmission Lines 117
6.1 Lossless Transmission Lines . . . . . . . . . . . . . . . . . . . . . . . . . . 117
6.2 Lossy Transmission Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
6.2.1 Lossy Transmission Line Model (LTRA) . . . . . . . . . . . . . . . 118
6.3 Uniform Distributed RC Lines . . . . . . . . . . . . . . . . . . . . . . . . . 120
6.3.1 Uniform Distributed RC Model (URC) . . . . . . . . . . . . . . . . 120
6.4 KSPICE Lossy Transmission Lines . . . . . . . . . . . . . . . . . . . . . . 121
6.4.1 Single Lossy Transmission Line (TXL) . . . . . . . . . . . . . . . . 122
6.4.2 Coupled Multiconductor Line (CPL) . . . . . . . . . . . . . . . . . 122
7 Diodes 125
7.1 Junction Diodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.2 Diode Model (D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7.3 Diode Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
8 BJT 133
8.1 Bipolar Junction Transistors (BJTs) . . . . . . . . . . . . . . . . . . . . . . 133
8.2 BJT Models (NPN/PNP) . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
8.2.1 Gummel-Poon Models . . . . . . . . . . . . . . . . . . . . . . . . . 134
8.2.2 VBIC Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
8.2.3 MEXTRAM Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.2.4 HICUM level 2 Model . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.2.5 HICUM level 0 Model . . . . . . . . . . . . . . . . . . . . . . . . . 143
9 JFETs 145
9.1 Junction Field-Effect Transistors (JFETs) . . . . . . . . . . . . . . . . . . 145
9.2 JFET Models (NJF/PJF) . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
9.2.1 Basic model statement . . . . . . . . . . . . . . . . . . . . . . . . . 145
9.2.2 JFET level 1 model with Parker Skellern modification . . . . . . . . 145
9.2.3 JFET level 2 Parker Skellern model . . . . . . . . . . . . . . . . . . 148
10 MESFETs 151
10.1 MESFETs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
10.2 MESFET Models (NMF/PMF) . . . . . . . . . . . . . . . . . . . . . . . . 151
10.2.1 Basic model statements . . . . . . . . . . . . . . . . . . . . . . . . . 151
10.2.2 Model by Statz e.a. . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
10.2.3 Model by Ytterdal e.a. . . . . . . . . . . . . . . . . . . . . . . . . . 152
10.2.4 hfet1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
10.2.5 hfet2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
10 CONTENTS
11 MOSFETs 155
11.1 MOSFET devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
11.2 MOSFET models (NMOS/PMOS) . . . . . . . . . . . . . . . . . . . . . . 156
11.2.1 MOS Level 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
11.2.2 MOS Level 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
11.2.3 MOS Level 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
11.2.4 MOS Level 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
11.2.5 Notes on Level 1-6 models . . . . . . . . . . . . . . . . . . . . . . . 158
11.2.6 MOS Level 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
11.2.7 BSIM Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
11.2.8 BSIM1 model (level 4) . . . . . . . . . . . . . . . . . . . . . . . . . 162
11.2.9 BSIM2 model (level 5) . . . . . .. . . . . . . . . . . . . . . . . . . 164
11.2.10 BSIM3 model (levels 8, 49) . . . . . . . . . . . . . . . . . . . . . . . 164
11.2.11 BSIM4 model (levels 14, 54) . . . . . . . . . . . . . . . . . . . . . . 164
11.2.12 EKV2.6 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
11.2.13 PSP Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
11.2.14 BSIMSOI models (levels 10, 58, 55, 56, 57) . . . . . . . . . . . . . . 166
11.2.15 SOI3 model (level 60) . . . . . . . . . . . . . . . . . . . . . . . . . . 166
11.2.16 HiSIM models of the University of Hiroshima . . . . . . . . . . . . 166
11.3 Power MOSFET model (VDMOS) . . . . . . . . . . . . . . . . . . . . . . 167
12 Mixed-Mode and Behavioral Modeling with XSPICE 173
12.1 Code Model Element & .MODEL Cards . . . . . . . . . . . . . . . . . . . 173
12.1.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
12.1.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
12.1.3 Search path for file input . . . . . . . . . . . . . . . . . . . . . . . . 178
12.2 Analog Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
12.2.1 Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
12.2.2 Summer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
12.2.3 Multiplier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
12.2.4 Divider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
12.2.5 Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
12.2.6 Controlled Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
12.2.7 PWL Controlled Source . . . . . . . . . . . . . . . . . . . . . . . . 186
12.2.8 Filesource (PWL sourced from file) . . . . . . . . . . . . . . . . . . 188
CONTENTS 11
12.2.9 multi_input_pwl block . . . . . . . . . . . . . . . . . . . . . . . . . 190
12.2.10 Analog Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
12.2.11 Alternative Analog Switch . . . . . . . . . . . . . . . . . . . . . . . 192
12.2.12 Zener Diode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
12.2.13 Current Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
12.2.14 Hysteresis Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
12.2.15 Differentiator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
12.2.16 Integrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
12.2.17 S-Domain Transfer Function . . . . . . . . . . . . . . . . . . . . . . 202
12.2.18 Slew Rate Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
12.2.19 Inductive Coupling . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
12.2.20 Magnetic Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
12.2.21 Controlled Sine Wave Oscillator . . . . . . . . . . . . . . . . . . . . 211
12.2.22 Controlled Triangle Wave Oscillator . . . . . . . . . . . . . . . . . . 212
12.2.23 Controlled Square Wave Oscillator . . . . . . . . . . . . . . . . . . 213
12.2.24 Controlled One-Shot . . . . . . . . . . . . . . . . . . . . . . . . . . 214
12.2.25 Capacitance Meter . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
12.2.26 Inductance Meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
12.2.27 Memristor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
12.2.28 2D table model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
12.2.29 3D table model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
12.2.30 Simple Diode Model . . . . . . . . . . . . . . . . . . . . . . . . . . 223
12.2.31 Analog delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
12.3 Hybrid Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
12.3.1 Digital-to-Analog Node Bridge . . . . . . . . . . . . . . . . . . . . . 226
12.3.2 Analog-to-Digital Node Bridge . . . . . . . . . . . . . . . . . . . . . 228
12.3.3 Controlled Digital Oscillator . . . . . . . . . . . . . . . . . . . . . . 229
12.3.4 Node bridge from digital to real with enable . . . . . . . . . . . . . 230
12.3.5 A Z**-1 block working on real data . . . . . . . . . . . . . . . . . . 231
12.3.6 A gain block for event-driven real data . . . . . . . . . . . . . . . . 231
12.3.7 Node bridge from real to analog voltage . . . . . . . . . . . . . . . 232
12.4 Digital Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
12.4.1 Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
12.4.2 Inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
12.4.3 And . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
12 CONTENTS
12.4.4 Nand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
12.4.5 Or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
12.4.6 Nor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
12.4.7 Xor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
12.4.8 Xnor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
12.4.9 Tristate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
12.4.10 Pullup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
12.4.11 Pulldown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
12.4.12 D Flip Flop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
12.4.13 JK Flip Flop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
12.4.14 Toggle Flip Flop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
12.4.15 Set-Reset Flip Flop . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
12.4.16 D Latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
12.4.17 Set-Reset Latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
12.4.18 State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
12.4.19 Frequency Divider . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
12.4.20 RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
12.4.21 Digital Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
12.4.22 LUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
12.4.23 General LUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
12.5 Predefined Node Types for event driven simulation . . . . . . . . . . . . . 269
12.5.1 Digital Node Type . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
12.5.2 Real Node Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
12.5.3 Int Node Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
12.5.4 (Digital) Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . 270
13 Verilog A Device models 271
13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
13.2 ADMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
13.3 How to integrate a Verilog-A model into ngspice . . . . . . . . . . . . . . . 271
13.3.1 How to setup a *.va model for ngspice . . . . . . . . . . . . . . . . 271
13.3.2 Adding admsXml to your build environment . . . . . . . . . . . . . 272
13.3.3 Compile ngspice with ADMS . . . . . . . . . . . . . . . . . . . . . 272
14 Mixed-Level Simulation (ngspice with TCAD) 273
14.1 Cider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
14.2 GSS, Genius . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
CONTENTS 13
15 Analyses and Output Control (batch mode) 275
15.1 Simulator Variables (.options) . . . . . . . . . . . . . . . . . . . . . . . . . 275
15.1.1 General Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
15.1.2 OP andDC Solution Options . . . . . . . . . . . . . . . . . . . . . 277
15.1.3 AC Solution Options . . . . . . . . . . . . . . . . . . . . . . . . . . 278
15.1.4 Transient Analysis Options . . . . . . . . . . . . . . . . . . . . . . . 279
15.1.5 ELEMENT Specific options . . . . . . . . . . . . . . . . . . . . . . 280
15.1.6 Transmission Lines Specific Options . . . . . . . . . . . . . . . . . . 280
15.1.7 Precedence of option and .options commands . . . . . . . . . . . . . 280
15.2 Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
15.2.1 .NODESET: Specify Initial Node Voltage Guesses . . . . . . . . . . 281
15.2.2 .IC: Set Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . 281
15.3 Analyses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
15.3.1 .AC: Small-Signal AC Analysis . . . . . . . . . . . . . . . . . . . . 282
15.3.2 .DC: DC Transfer Function . . . . . . . . . . . . . . . . . . . . . . 283
15.3.3 .DISTO: Distortion Analysis . . . . . . . . . . . . . . . . . . . . . . 284
15.3.4 .NOISE: Noise Analysis . . . . . . . . . . . . . . . . . . . . . . . . 286
15.3.5 .OP: Operating Point Analysis . . . . . . . . . . . . . . . . . . . . . 287
15.3.6 .PZ: Pole-Zero Analysis . . . . . . . . . . . . . . . . . . . . . . . . . 288
15.3.7 .SENS: DC or Small-Signal AC Sensitivity Analysis . . . . . . . . . 289
15.3.8 .TF: Transfer Function Analysis . . . . . . . . . . . . . . . . . . . . 289
15.3.9 .TRAN: Transient Analysis . . . . . . . . . . . . . . . . . . . . . . 290
15.3.10 Transient noise analysis (at low frequency) . . . . . . . . . . . . . . 290
15.3.11 .PSS: Periodic Steady State Analysis . . . . . . . . . . . . . . . . . 294
15.4 Measurements after AC, DC and Transient Analysis . . . . . . . . . . . . . 295
15.4.1 .meas(ure) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
15.4.2 batch versus interactive mode . . . . . . . . . . . . . . . . . . . . . 295
15.4.3 General remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
15.4.4 Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
15.4.5 Trig Targ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
15.4.6 Find ... When . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
15.4.7 AVG|MIN|MAX|PP|RMS|MIN_AT|MAX_AT . . . . . . . . . . . . . . . . 299
15.4.8 Integ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
15.4.9 param . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
15.4.10 par(’expression’ ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
14 CONTENTS
15.4.11 Deriv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
15.4.12 More examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
15.5 Safe Operating Area (SOA) warning messages . . . . . . . . . . . . . . . . 302
15.5.1 Resistor and Capacitor SOA model parameters . . . . . . . . . . . 303
15.5.2 Diode SOA model parameters . . . . . . . . . . . . . . . . . . . . . 303
15.5.3 BJT SOA model parameters . . . . . . . . . . . . . . . . . . . . . . 304
15.5.4 MOS SOA model parameters . . . . . . . . . . . . . . . . . . . . . 304
15.5.5 VDMOS SOA model parameters . . . . . . . . . . . . . . . . . . . 305
15.6 Batch Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
15.6.1 .SAVE: Name vector(s) to be saved in raw file . . . . . . . . . . . . 305
15.6.2 .PRINT Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
15.6.3 .PLOT Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
15.6.4 .FOUR: Fourier Analysis of Transient Analysis Output . . . . . . . 307
15.6.5 .PROBE: Save device node currents or differential voltages . . . . . 308
15.6.6 par(’expression’): Algebraic expressions for output . . . . . . . . . . 311
15.6.7 .width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
15.7 Measuring current through device terminals . . . . . . . . . . . . . . . . . 312
15.7.1 Using the .probe command . . . . . . . . . . . . . . . . . . . . . . . 312
15.7.2 Adding a voltage source in series . . . . . . . . . . . . . . . . . . . 312
15.7.3 Using option ’savecurrents’ . . . . . . . . . . . . . . . . . . . . . . . 312
16 Starting ngspice 315
16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
16.2 Where to obtain ngspice . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
16.3 Command line options for starting ngspice . . . . . . . . . . . . . . . . . . 316
16.4 Starting options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
16.4.1 Batch mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
16.4.2 Interactive mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
16.4.3 Control mode (Interactive mode with control file or control section) 319
16.5 Standard configuration file spinit . . . . . . . . . . . . . . . . . . . . . . . 320
16.6 User defined configuration file .spiceinit . . . . . . . . . . . . . . . . . . . . 321
16.7 Environmental variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
16.7.1 Ngspice specific variables . . . . . . . . . . . . . . . . . . . . . . . . 321
16.7.2 Common environment variables . . . . . . . . . . . . . . . . . . . . 322
16.8 Memory usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
CONTENTS 15
16.9 Simulation time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
16.10Ngspice on multi-core processors using OpenMP . . . . . . . . . . . . . . . 323
16.10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
16.10.2 Internals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
16.10.3 Some results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
16.10.4 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
16.10.5 Literature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
16.11Server mode option -s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
16.12Pipe mode option -p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
16.13Ngspice control via input, output fifos . . . . . . . . . . . . . . . . . . . . . 329
16.14Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
16.14.1 Compatibility mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
16.14.2 Missing functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
16.14.3 Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
16.14.4 Controls and commands . . . . . . . . . . . . . . . . . . . . . . . . 332
16.14.5 PSPICE Compatibility mode . . . . . . . . . . . . . . . . . . . . . 333
16.14.6 LTSPICE Compatibility mode . . . . . . . . . . . . . . . . . . . . . 334
16.14.7 LTSPICE/PSPICE Compatibility mode . . . . . . . . . . . . . . . 336
16.14.8 KiCad Compatibility mode . . . . . . . . . . . . . . . . . . . . . . . 336
16.14.9 Spectre Compatibility mode . . . . . . . . . . . . . . . . . . . . . . 337
16.14.10HSPICE Compatibility mode . . . . . . . . . . . . . . . . . . . . . 337
16.15Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
16.16Tools for debugging a circuit netlist . . . . . . . . . . . . . . . . . . . . . . 338
16.16.1 options and initial conditions . . . . . . . . . . . . . . . . . . . . . 338
16.16.2 set debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
16.16.3 set ngdebug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
16.16.4 miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
16.17Reporting bugs and errors . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
17 Interactive Interpreter 341
17.1 Introduction . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 341
17.2 Expressions, Functions, and Constants . . . . . . . . . . . . . . . . . . . . 342
17.3 Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
17.4 Command Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
17.4.1 On the console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
16 CONTENTS
17.4.2 Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
17.4.3 Add-on to circuit file . . . . . . . . . . . . . . . . . . . . . . . . . . 348
17.5 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
17.5.1 Ac*: Perform an AC, small-signal frequency response analysis . . . 348
17.5.2 Alias: Create an alias for a command . . . . . . . . . . . . . . . . . 349
17.5.3 Alter*: Change a device or model parameter . . . . . . . . . . . . . 349
17.5.4 Altermod*: Change model parameter(s) . . . . . . . . . . . . . . . 351
17.5.5 Alterparam*: Change value of a global parameter . . . . . . . . . . 352
17.5.6 Asciiplot: Plot values using old-style character plots . . . . . . . . . 353
17.5.7 Aspice*: Asynchronous ngspice run . . . . . . . . . . . . . . . . . . 353
17.5.8 Bug: Output URL for ngspice bug tracker . . . . . . . . . . . . . . 353
17.5.9 Cd: Change directory . . . . . . . . . . . . . . . . . . . . . . . . . . 353
17.5.10 Cdump: Dump the control flow to the screen . . . . . . . . . . . . . 354
17.5.11 Circbyline*: Enter a circuit line by line . . . . . . . . . . . . . . . . 354
17.5.12 Codemodel*: Load an XSPICE code model library . . . . . . . . . 355
17.5.13 Compose: Compose a vector . . . . . . . . . . . . . . . . . . . . . . 356
17.5.14 Cutout: Cut out a section of all vectors in a tran plot . . . . . . . . 357
17.5.15 Dc*: Perform a DC-sweep analysis . . . . . . . . . . . . . . . . . . 357
17.5.16 Define: Define a function . . . . . . . . . . . . . . . . . . . . . . . . 357
17.5.17 Deftype: Define a new type for a vector or plot . . . . . . . . . . . 358
17.5.18 Delete*: Remove a trace or breakpoint . . . . . . . . . . . . . . . . 358
17.5.19 Destroy: Delete an output data set . . . . . . . . . . . . . . . . . . 358
17.5.20 Devhelp: information on available devices . . . . . . . . . . . . . . 358
17.5.21 Diff: Compare vectors . . . . . . . . . . . . . . . . . . . . . . . . . 359
17.5.22 Display: List known vectors and types . . . . . . . . . . . . . . . . 359
17.5.23 Echo: Print text . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
17.5.24 Edit*: Edit the current circuit . . . . . . . . . . . . . . . . . . . . . 360
17.5.25 Edisplay: Print a list of all the event nodes . . . . . . . . . . . . . 360
17.5.26 Eprint: Print an event driven node . . . . . . . . . . . . . . . . . . 360
17.5.27 Eprvcd: Dump event nodes in VCD format . . . . . . . . . . . . . 361
17.5.28 Esave: Save a set of event node outputs . . . . . . . . . . . . . . . 361
17.5.29 FFT: fast Fourier transform of vectors . . . . . . . . . . . . . . . . 361
17.5.30 Fourier: Perform a Fourier transform . . . . . . . . . . . . . . . . . 363
17.5.31 Getcwd: Print the current working directory . . . . . . . . . . . . . 364
17.5.32 Gnuplot: Graphics output via gnuplot . . . . . . . . . . . . . . . . 364
CONTENTS 17
17.5.33 Hardcopy: Save a plot to a file for printing . . . . . . . . . . . . . . 365
17.5.34 Help: Print summaries of Ngspice commands . . . . . . . . . . . . . 365
17.5.35 History: Review previous commands . . . . . . . . . . . . . . . . . 365
17.5.36 Inventory: Print circuit inventory . . . . . . . . . . . . . . . . . . . 368
17.5.37 Iplot*: Incremental plot . . . . . . . . . . . . . . . . . . . . . . . . 368
17.5.38 Jobs*: List active asynchronous ngspice runs . . . . . . . . . . . . . 368
17.5.39 Let: Assign a value to a vector . . . . . . . . . . . . . . . . . . . . 368
17.5.40 Linearize*: Interpolate to a linear scale . . . . . . . . . . . . . . . . 369
17.5.41 Listing*: Print a listing of the current circuit . . . . . . . . . . . . . 370
17.5.42 Load: Load rawfile data . . . . . . . . . . . . . . . . . . . . . . . . 371
17.5.43 Mc_source*: Reload the circuit netlist from an internal storage . . 371
17.5.44 Meas*: Measurements on simulation data . . . . . . . . . . . . . . 371
17.5.45 Mdump*: Dump the matrix values to a file (or to console) . . . . . 372
17.5.46 Mrdump*: Dump the matrix right hand side values to a file (or to
console) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
17.5.47 Noise*: Noise analysis . . . . . . . . . . . . . . . . . . . . . . . . . 373
17.5.48 Op*: Perform an operating point analysis . . . . . . . . . . . . . . 373
17.5.49 Option*: Set a ngspice option . . . . . . . . . . . . . . . . . . . . . 373
17.5.50 Plot: Plot vectors on the display . . . . . . . . . . . . . . . . . . . 374
17.5.51 Pre_<command>: execute commands prior to parsing the circuit . 376
17.5.52 Print: Print values . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
17.5.53 Psd: power spectral density of vectors . . . . . . . . . . . . . . . . 377
17.5.54 Quit: Leave Ngspice . . . . . . . . . . . . . . . . . . . . . . . . . . 377
17.5.55 Rehash: Reset internal hash tables . . . . . . . . . . . . . . . . . . 377
17.5.56 Remcirc*: Remove the current circuit . . . . . . . . . . . . . . . . . 378
17.5.57 Remzerovec: Remove zero length vectors . . . . . . . . . . . . . . . 378
17.5.58 Reset*: Reset an analysis . . . . . . . . . . . . . . . . . . . . . . . 378
17.5.59 Reshape: Alter the dimensionality or dimensions of a vector . . . . 378
17.5.60 Resume*: Continue a simulation after a stop . . . . . . . . . . . . . 379
17.5.61 Rspice*: Remote ngspice submission . . . . . . . . . . . . . . . . . 379
17.5.62 Run*: Run analysis from the input file . . . . . . . . . . . . . . . . 380
17.5.63 Rusage: Resource usage . . . . . . . . . . . . . . . . . . . . . . . . 380
17.5.64 Save*: Save a set of outputs . . . . . . . . . . . . . . . . . . . . . . 381
17.5.65 Sens*: Run a sensitivity analysis . . . . . . . . . . . . . . . . . . . 382
17.5.66 Set: Set the value of a variable . . . . . . . . . . . . . . . . . . . . 383
18 CONTENTS
17.5.67 Setcs: Set the value of a variable, case preserved . . . . . . . . . . . 384
17.5.68 Setcirc*: Change the current circuit . . . . . . . . . . . . . . . . . . 384
17.5.69 Setplot: Switch the current set of vectors . . . . . . . . . . . . . . . 384
17.5.70 Setscale: Set the scale vector for the current plot . . . . . . . . . . 385
17.5.71 Setseed: Set the seed value for the random number generator . . . . 385
17.5.72 Settype: Set the type of a vector . . . . . . . . . . . . . . . . . . . 385
17.5.73 Shell: Call the command interpreter . . . . . . . . . . . . . . . . . . 386
17.5.74 Shift: Alter a list variable . . . . . . . . . . . . . . . . . . . . . . . 386
17.5.75 Show*: List device state . . . . . . . . . . . . . . . . . . . . . . . . 386
17.5.76 Showmod*: List model parameter values . . . . . . . . . . . . . . . 387
17.5.77 Snload*: Load the snapshot file . . . . . . . . . . . . . . . . . . . . 387
17.5.78 Snsave*: Save a snapshot file . . . . . . . . . . . . . . . . . . . . . 388
17.5.79 Source: Read a ngspice input file . . . . . . . . . . . . . . . . . . . 389
17.5.80 Spec: Create a frequency domain plot . . . . . . . . . . . . . . . . . 390
17.5.81 Status*: Display breakpoint information . . . . . . . . . . . . . . . 390
17.5.82 Step*: Run a fixed number of time-points . . . . . . . . . . . . . . 390
17.5.83 Stop*: Set a breakpoint . . . . . . . . . . . . . . . . . . . . . . . . 391
17.5.84 Strcmp: Compare two strings . . . . . . . . . . . . . . . . . . . . . 391
17.5.85 Sysinfo*: Print system information . . . . . . . . . . . . . . . . . . 392
17.5.86 Tf*: Run a Transfer Function analysis . . . . . . . . . . . . . . . . 392
17.5.87 Trace*: Trace nodes . . . . . . . . . . . . . . . . . . . . . . . . . . 393
17.5.88 Tran*: Perform a transient analysis .. . . . . . . . . . . . . . . . . 393
17.5.89 Transpose: Swap the elements in a multi-dimensional data set . . . 394
17.5.90 Unalias: Retract an alias . . . . . . . . . . . . . . . . . . . . . . . . 394
17.5.91 Undefine: Retract a definition . . . . . . . . . . . . . . . . . . . . . 394
17.5.92 Unlet: Delete the specified vector(s) . . . . . . . . . . . . . . . . . . 394
17.5.93 Unset: Clear a variable . . . . . . . . . . . . . . . . . . . . . . . . . 395
17.5.94 Version: Print the version of ngspice . . . . . . . . . . . . . . . . . 395
17.5.95 Where*: Identify troublesome node or device . . . . . . . . . . . . . 396
17.5.96 Wrdata: Write data to a file (simple table) . . . . . . . . . . . . . . 397
17.5.97 Write: Write data to a file (Spice3f5 format) . . . . . . . . . . . . . 397
17.5.98 Wrnodev: Write node voltage values to a file (.ic=xx format) . . . . 398
17.5.99 Wrs2p: Write scattering parameters to file (Touchstone® format) . 399
17.6 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
17.6.1 While - End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
CONTENTS 19
17.6.2 Repeat - End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
17.6.3 Dowhile - End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
17.6.4 Foreach - End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
17.6.5 If - Then - Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
17.6.6 Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
17.6.7 Goto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
17.6.8 Continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
17.6.9 Break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
17.7 Internally predefined variables . . . . . . . . . . . . . . . . . . . . . . . . . 403
17.8 Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
17.8.1 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
17.8.2 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
17.8.3 Assessing vectors in subcircuits . . . . . . . . . . . . . . . . . . . . 411
17.8.4 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
17.8.5 control structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
17.8.6 Example script ’spectrum’ . . . . . . . . . . . . . . . . . . . . . . . 416
17.8.7 Example script for random numbers . . . . . . . . . . . . . . . . . . 418
17.8.8 Parameter sweep . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
17.8.9 Output redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
17.9 Scattering parameters (S-parameters) . . . . . . . . . . . . . . . . . . . . . 421
17.9.1 Intro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
17.9.2 S-parameter measurement basics . . . . . . . . . . . . . . . . . . . 421
17.9.3 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
17.10Using shell variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
17.11MISCELLANEOUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
17.12Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
18 Ngspice User Interfaces 425
18.1 MS Windows Graphical User Interface . . . . . . . . . . . . . . . . . . . . 425
18.2 MS Windows Console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
18.3 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
18.4 CygWin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
18.5 Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
18.6 Output-to-file options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
18.6.1 Graphics files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
20 CONTENTS
18.6.2 Tabulated files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
18.7 Gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
18.7.1 Using Gnuplot to produce 1D graphs of (electrical) simulation results438
18.7.2 Using gnuplot to produce 2D contour plots for Cider . . . . . . . . 439
18.8 Integration with CAD software and ‘third party’ GUIs . . . . . . . . . . . 443
18.8.1 KiCad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
18.8.2 Xschem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
18.8.3 GNU Spice GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
18.8.4 XCircuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
18.8.5 GEDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
18.8.6 MSEspice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
18.8.7 GNU Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
19 ngspice as shared library or dynamic link library 445
19.1 Compile options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
19.1.1 How to get the sources . . . . . . . . . . . . . . . . . . . . . . . . . 445
19.1.2 Linux, MINGW, CYGWIN . . . . . . . . . . . . . . . . . . . . . . 445
19.1.3 MS Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
19.2 Linking shared ngspice to a calling application . . . . . . . . . . . . . . . . 446
19.2.1 Linking during creating the caller . . . . . . . . . . . . . . . . . . . 446
19.2.2 Loading at runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
19.3 Shared ngspice API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
19.3.1 structs and types defined for transporting data . . . . . . . . . . . . 446
19.3.2 Exported functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
19.3.3 Callback functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
19.4 General remarks on using the API . . . . . . . . . . . . . . . . . . . . . . . 454
19.4.1 Loading a netlist . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
19.4.2 Running the simulation . . . . . . . . . . . . . . . . . . . . . . . . . 456
19.4.3 Accessing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
19.4.4 Altering model or device parameters . . . . . . . . . . . . . . . . . 457
19.4.5 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
19.4.6 Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
19.5 Example applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
19.6 ngspice parallel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
19.6.1 Go parallel! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
19.6.2 Additional exported functions . . . . . . . . . . . . . . . . . . . . . 460
19.6.3 Additional callback functions . . . . . . . . . . . . . . . . . . . . . 461
19.6.4 Parallel ngspice example . . . . . . . . . . . . . . . . . . . . . . . . 462
CONTENTS 21
20 TCLspice 463
20.1 tclspice framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
20.2 tclspice documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
20.3 spicetoblt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
20.4 Running TCLspice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
20.5 examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
20.5.1 Active capacitor measurement . . . . . . . . . . . . . . . . . . . . . 465
20.5.2 Optimization of a linearization circuit for a Thermistor . . . . . . . 467
20.5.3 Progressive display . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
20.6 Compiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
20.6.1 Linux . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
20.6.2 MS Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
20.7 MS Windows 32 Bit binaries . . . . . . . . . . . . . . . . . . . . . . . . . . 473
21 Example Circuits 475
21.1 AC coupled transistor amplifier . . . . . . . . . . . . . . . . . . . . . . . . 475
21.2 Differential Pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
21.3 MOSFET Characterization . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
21.4 RTL Inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
21.5 Four-Bit Binary Adder (Bipolar) . . . . . . . . . . . . . . . . . . . . . . . 482
21.6 Four-Bit Binary Adder (MOS) . . . . . . . . . . . . . . . . . . . . . . . . . 484
21.7 Transmission-Line Inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
22 Statistical circuit analysis 487
22.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
22.2 Using random param(eters) . . . . . . . . . . . . . . . . . . . . . . . . . . 487
22.3 Behavioral sources (B, E, G, R, L, C) with random control . . . . . . . . . 489
22.4 ngspice scripting language . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
22.5 Monte-Carlo Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
22.5.1 Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
22.5.2 Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
22.5.3 Example 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
22.6 Data evaluation with Gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . 494
22 CONTENTS
23 Circuit optimization with ngspice 497
23.1 Optimization of a circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
23.2 ngspice optimizer using ngspice scripts . . . . . . . . . . . . . . . . . . . . 498
23.3 ngspice optimizer using tclspice . . . . . . . . . . . . . . . . . . . . . . . . 498
23.4 ngspice optimizer using a Python script . . . . . . . . . . . . . . . . . . . . 498
23.5 ngspice optimizer using ASCO . . . . . . . . . . . . . . . . . . . . . . . . . 498
23.5.1 Three stage operational amplifier . . . . . . . . . . . . . . . . . . . 499
23.5.2 Digital inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
23.5.3 Bandpass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
23.5.4 Class-E power amplifier . . . . . . . . . . . . . . . . . . . . . . . . 502
24 Notes 503
24.1 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
24.2 Acronyms and Abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . 504
24.3 To Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
II XSPICE Software User’s Manual 509
25 XSPICE Basics 511
25.1 ngspice with the XSPICE option . . . . . . . . . . . . . . . . . . . . . . . 511
25.2 The XSPICE Code Model Subsystem . . . . . . . . . . . . . . . . . . . . . 511
25.3 XSPICE Top-Level Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 512
26 Execution Procedures 515
26.1 Simulation and Modeling Overview . . . . . . . . . . . . . . . . . . . . . . 515
26.1.1 Describing the Circuit . . . . . . . . . . . . . . . . . . . . . . . . . 515
26.2 Circuit Description Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
26.2.1 XSPICE Syntax Extensions . . . . . . . . . . . . . . . . . . . . . . 521
26.3 How to create code models . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
27 Example circuits 527
27.1 Amplifier with XSPICE model ‘gain’ . . . . . . . . . . . . . . . . . . . . . 528
27.2 XSPICE advanced usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
27.2.1 Circuit example C3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
27.2.2 Running example C3 . . . . . . . . . . . . . . . . . . . . . . . . . . 532
CONTENTS 23
28 Code Models and User-Defined Nodes 537
28.1 Code Model Data Type Definitions . . . . . . . . . . . . . . . . . . . . . . 538
28.2 Creating Code Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
28.3 Creating User-Defined Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . 539
28.4 Adding a new code model library . . . . . . . . . . . . . . . . . . . . . . . 540
28.5 Compiling and loading the new code model (library) . . . . . . . . . . . . 541
28.6 Interface Specification File . . . . . . . . . . . . . . . . . . . . . . . . . . 541
28.6.1 The Name Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
28.6.2 The Port Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
28.6.3 The Parameter Table . . . . . . . . . . . . . . . . . . . . . . . . . . 545
28.6.4 Static Variable Table . . . . . . . . . . . . . . . . . . . . . . . . . . 547
28.7 Model Definition File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
28.7.1 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
28.7.2 Function Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
28.8 User-Defined Node Definition File . . . . . . . . . . . . . . . . . . . . . . . 565
28.8.1 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
28.8.2 Function Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
28.8.3 Example UDN Definition File . . . . . . . . . . . . . . . . . . . . . 569
29 Error Messages 573
29.1 Preprocessor Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . 573
29.2 Simulator Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
29.3 Code Model Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . 579
29.3.1 Code Model aswitch . . . . . . . . . . . . . . . . . . . . . . . . . . 579
29.3.2 Code Model climit . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
29.3.3 Code Model core . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
29.3.4 Code Model d_osc . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
29.3.5 Code Model d_source . . . . . . . . . . . . . . . . . . . . . . . . . 581
29.3.6 Code Model d_state . . . . . . . . . . . . . . . . . . . . . . . . . . 581
29.3.7 Code Model oneshot . . . . . . . . . . . . . . . . . . . . . . . . . . 582
29.3.8 Code Model pwl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
29.3.9 Code Model s_xfer . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
29.3.10 Code Model sine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
29.3.11 Code Model square . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
29.3.12 Code Model triangle . . . . . . . . . . . . . . . . . . . . . . . . . . 584
24 CONTENTS
III CIDER 585
30 CIDER User’s Manual 587
30.1 SPECIFICATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
30.1.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
30.2 BOUNDARY, INTERFACE . . . . . . . . . . . . . . . . . . . . . . . . . . 589
30.2.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
30.2.2 PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
30.2.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
30.3 COMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
30.3.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
30.3.2 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
30.4 CONTACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
30.4.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
30.4.2 PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
30.4.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
30.4.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . 592
30.5 DOMAIN, REGION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
30.5.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
30.5.2 PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
30.5.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
30.5.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
30.6 DOPING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
30.6.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
30.6.2 PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
30.6.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
30.6.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
30.7 ELECTRODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
30.7.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
30.7.2 PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
30.7.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
30.7.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
30.8 END . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
30.8.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
30.9 MATERIAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
CONTENTS 25
30.9.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
30.9.2 PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
30.9.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
30.9.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
30.10METHOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
30.10.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
30.10.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
30.10.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
30.11Mobility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
30.11.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
30.11.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
30.11.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
30.11.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
30.11.5 BUGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
30.12MODELS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
30.12.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
30.12.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
30.12.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
30.12.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
30.12.5 Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
30.13OPTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
30.13.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
30.13.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
30.13.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
30.13.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
30.14OUTPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
30.14.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
30.14.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
30.14.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
30.14.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
30.15TITLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
30.15.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
30.15.2 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
30.15.3 BUGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
30.16X.MESH, Y.MESH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
26 CONTENTS
30.16.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
30.16.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
30.16.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
30.16.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
30.17NUMD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
30.17.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
30.17.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
30.17.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
30.17.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
30.17.5 BUGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
30.18NBJT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
30.18.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
30.18.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
30.18.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
30.18.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
30.18.5 BUGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
30.19NUMOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
30.19.1 DESCRIPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
30.19.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
30.19.3 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
30.19.4 SEE ALSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
30.202D contour plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
30.21Cider examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
IV Miscellaneous 619
31 Model and Device Parameters 621
31.1 Accessing internal device parameters . . . . . . . . . . . . . . . . . . . . . 621
31.2 Elementary Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
31.2.1 Resistor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
31.2.2 Capacitor - Fixed capacitor . . . . . . . . . . . . . . . . . . . . . . 625
31.2.3 Inductor - Fixed inductor . . . . . . . . . . . . . . . . . . . . . . . 626
31.2.4 Mutual - Mutual Inductor . . . . . . . . . . . . . . . . . . . . . . . 627
31.3 Voltage and current sources . . . . . . . . . . . . . . . . . . . . . . . . . . 628
31.3.1 Bxxxx - Arbitrary source (ASRC) . . . . . . . . . . . . . . . . . . . 628
CONTENTS 27
31.3.2 Isource - Independent current source . . . . . . . . . . . . . . . . . 629
31.3.3 Vsource - Independent voltage source . . . . . . . . . . . . . . . . . 630
31.3.4 Fxxxx: Current-Controlled Current Source (CCCS) . . . . . . . . . 631
31.3.5 Hxxxx: Current-Controlled Voltage Source (CCVS) . . . . . . . . . 631
31.3.6 Gxxxx: Voltage-Controlled Current Source (VCCS) . . . . . . . . . 632
31.3.7 Exxxx: Voltage-Controlled Voltage Source (VCVS) . . . . . . . . . 632
31.4 Transmission Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
31.4.1 CplLines - Simple Coupled Multiconductor Lines . . . . . . . . . . 633
31.4.2 LTRA - Lossy transmission line . . . . . . . . . . . . . . . . . . . . 634
31.4.3 Tranline - Lossless transmission line . . . . . . . . . . . . . . . . . . 635
31.4.4TransLine - Simple Lossy Transmission Line . . . . . . . . . . . . . 636
31.4.5 URC - Uniform R. C. line . . . . . . . . . . . . . . . . . . . . . . . 637
31.5 BJTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
31.5.1 BJT - Bipolar Junction Transistor . . . . . . . . . . . . . . . . . . . 638
31.5.2 VBIC - Vertical Bipolar Inter-Company Model . . . . . . . . . . . . 641
31.6 MOSFETs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
31.6.1 MOS1 - Level 1 MOSFET model with Meyer capacitance model . . 645
31.6.2 MOS2 - Level 2 MOSFET model with Meyer capacitance model . . 648
31.6.3 MOS3 - Level 3 MOSFET model with Meyer capacitance model . . 652
31.6.4 MOS6 - Level 6 MOSFET model with Meyer capacitance model . . 656
31.6.5 MOS9 - Modified Level 3 MOSFET model . . . . . . . . . . . . . . 659
31.6.6 BSIM1 - Berkeley Short Channel IGFET Model . . . . . . . . . . . 663
31.6.7 BSIM2 - Berkeley Short Channel IGFET Model . . . . . . . . . . . 666
31.6.8 BSIM3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670
31.6.9 BSIM4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
32 Compilation notes 673
32.1 Ngspice Installation under Linux (and other ’UNIXes’) . . . . . . . . . . . 673
32.1.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
32.1.2 Install from Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
32.1.3 Install from a tarball, e.g. from ngspice-36.tar.gz . . . . . . . . . . . 675
32.1.4 Compilation using an user defined directory tree for object files . . 675
32.1.5 ngspice as a shared library . . . . . . . . . . . . . . . . . . . . . . . 676
32.1.6 Relative paths for spinit and code models . . . . . . . . . . . . . . . 676
32.1.7 Installation on Red Hat or Oracle Linux (and similar, e.g. Centos) . 677
28 CONTENTS
32.1.8 Advanced Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
32.1.9 Compilers and Options . . . . . . . . . . . . . . . . . . . . . . . . . 679
32.1.10 Compiling For Multiple Architectures . . . . . . . . . . . . . . . . . 680
32.1.11 Installation Names . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
32.1.12 Optional Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
32.1.13 Specifying the System Type . . . . . . . . . . . . . . . . . . . . . . 681
32.1.14 Sharing Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
32.1.15 Operation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
32.2 Ngspice Compilation under Windows OS . . . . . . . . . . . . . . . . . . . 681
32.2.1 Building ngspice with MS Visual Studio 2019 . . . . . . . . . . . . 681
32.2.2 How to make ngspice with MINGW and MSYS2 . . . . . . . . . . 684
32.2.3 make ngspice with pure CYGWIN . . . . . . . . . . . . . . . . . . . 687
32.2.4 ngspice mingw or cygwin console executable w/o graphics . . . . . 688
32.2.5 ngspice for MS Windows, cross compiled from Linux . . . . . . . . 688
32.3 Ngspice Compilation under macOS . . . . . . . . . . . . . . . . . . . . . . 689
32.3.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
32.3.2 Compiling ngspice . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
32.3.3 Compiling ngspice shared library . . . . . . . . . . . . . . . . . . . 690
32.4 Reporting errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
33 Copyrights and licenses 691
33.1 Documentation license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
33.2 ngspice license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
33.3 Some license details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
33.3.1 CC-BY-SA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
33.3.2 ‘Modified’ BSD license . . . . . . . . . . . . . . . . . . . . . . . . . 692
33.4 On the historical evolvement of the ngspice licenses . . . . . . . . . . . . . 693
33.4.1 XSPICE SOFTWARE (documentation) copyright . . . . . . . . . . 693
33.4.2 CIDER RESEARCH SOFTWARE AGREEMENT (superseded by
33.4.3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
33.4.3 ‘Modified’ BSD license . . . . . . . . . . . . . . . . . . . . . . . . . 694
33.4.4 XSPICE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
33.4.5 tclspice, numparam . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
33.4.6 Linking to GPLd libraries (e.g. readline, fftw, table.cm): . . . . . . 695
Prefaces
Preface to the first edition
This manual has been assembled from different sources:
1. The spice3f5 manual,
2. the XSPICE user’s manual,
3. the CIDER user’s manual
and some original material needed to describe the new features and the newly implemented
models. This cut and paste approach, while not being orthodox, allowed ngspice to have
a full manual in a fraction of the time that writing a completely new text would have
required. The use of LaTex and LYX instead of TeXinfo, which was the original encoding
for the manual, further helped to reduce the writing effort and improved the quality of
the result, at the expense of an on-line version of the manual but, due to the complexity
of the software I hardly think that users will ever want to read an on-line text version.
In writing this text I followed the spice3f5 manual, both in the chapter sequence and
presentation of material, mostly because that was already the user manual of SPICE.
Ngspice is an open source software, users can download the source code, compile, and
run it. This manual has an entire chapter describing program compilation and available
options to help users in building ngspice (see Chapt. 32). The source package already
comes with all ‘safe’ options enabled by default, and activating the others can produce
unpredictable results and thus is recommended to expert users only. This is the first
ngspice manual and I have removed all the historical material that described the differences
between ngspice and spice3, since it was of no use for the user and not so useful for the
developer who can look for it in the Changelogs of in the revision control system.
I want to acknowledge the work done by Emmanuel Rouat and Arno W. Peters for
converting the original spice3f documentation to TEXinfo. Their effort gave ngspice users
the only available documentation that described the changes for many years. A good
source of ideas for this manual came from the on-line spice3f manual written by Charles
D.H. Williams (Spice3f5 User Guide), constantly updated and useful for its many insights.
As always, errors, omissions and unreadable phrases are only my fault.
Paolo Nenzi
Roma, March 24th 2001
29
http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/index.html#toc
30 CONTENTS
Indeed. At the end of the day, this is engineering, and one learns to live
within the limitations of the tools.
Kevin Aylward, Warden of the King’s Ale
Preface to the current edition (as of Aug 2021)
Due to the wealth of new material and options in ngspice the actual order of chapters has
been revised. Several new chapters have been added. The LYX text processor has allowed
adding internal cross references. The PDF format has become the standard format for
distribution of the manual. There is also a xhtml version available. Within each new
ngspice distribution (starting with ngspice-21) a manual edition is provided reflecting the
ngspice status at the time of distribution. At the same time, located at ngspice manuals,
the manual is constantly updated. Every new ngspice feature should enter this manual
as soon as it has been made available in the Git source code master branch.
Holger Vogt
Mülheim, 2021
http://ngspice.sourceforge.net/docs/ngspice-html-manual/manual.xhtml
http://ngspice.cvs.sourceforge.net/viewvc/ngspice/ngspice/ng-spice-manuals/
Acknowledgments
ngspice contributors
Spice3 and CIDERwere originally written at The University of California at Berkeley
(USA).
XSPICE has been provided by Georgia Institute of Technology, Atlanta (USA).
Since then, there have been many people working on the software, most of them releasing
patches to the original code through the Internet.
The following people have contributed in some way:
Vera Albrecht,
Cecil Aswell,
Giles C. Billingsley,
Phil Barker,
Steven Borley,
Stuart Brorson,
Mansun Chan,
Wayne A. Christopher,
Al Davis,
Glao S. Dezai,
Jon Engelbert,
Daniele Foci,
Noah Friedman,
David A. Gates,
Alan Gillespie,
John Heidemann,
Marcel Hendrix,
Jeffrey M. Hsu,
JianHui Huang,
S. Hwang,
Chris Inbody,
Gordon M. Jacobs,
Min-Chie Jeng,
Beorn Johnson,
Stefan Jones,
Kenneth H. Keller,
Francesco Lannutti,
31
32 CONTENTS
Robert Larice,
Mathew Lew,
Robert Lindsell,
Weidong Liu,
Kartikeya Mayaram,
Richard D. McRoberts,
Manfred Metzger,
Jim Monte,
Wolfgang Muees,
Paolo Nenzi,
Gary W. Ng,
Hong June Park,
Stefano Perticaroli,
Arno Peters,
Serban-Mihai Popescu,
Georg Post,
Thomas L. Quarles,
Emmanuel Rouat,
Jean-Marc Routure,
Jaijeet S. Roychowdhury,
Lionel Sainte Cluque,
Takayasu Sakurai,
Amakawa Shuhei,
Kanwar Jit Singh,
Bill Swartz,
Hitoshi Tanaka,
Brian Taylor,
Steve Tell,
Andrew Tuckey,
Andreas Unger,
Holger Vogt,
Dietmar Warning,
Michael Widlok,
Charles D.H. Williams,
Antony Wilson,
and many others...
If someone helped in the development and has not been inserted in this list then this
omission was unintentional. If you feel you should be on this list then please write to
<ngspice-devel@lists.sourceforge.net>. Do not be shy, we would like to make a list as
complete as possible.
mailto:ngspice-devel@lists.sourceforge.net
Chapter 1
Introduction
Ngspice is a general-purpose circuit simulation program for nonlinear and linear analyses.
Circuits may contain resistors, capacitors, inductors, mutual inductors, independent or
dependent voltage and current sources, loss-less and lossy transmission lines, switches,
uniform distributed RC lines, and the five most common semiconductor devices: diodes,
BJTs, JFETs, MESFETs, and MOSFETs.
Some introductory remarks on how to use ngspice may be found in Chapt. 21.
Ngspice is an update of Spice3f5, the last Berkeley’s release of Spice3 simulator family.
Ngspice is being developed to include new features to existing Spice3f5 and to fix its bugs.
Improving a complex software like a circuit simulator is a very hard task and, while some
improvements have been made, most of the work has been done on bug fixing and code
refactoring.
Ngspice has built-in models for the semiconductor devices, and the user need specify only
the pertinent model parameter values.
Ngspice supports mixed-level simulation and provides a direct link between technology pa-
rameters and circuit performance. A mixed-level circuit and device simulator can provide
greater simulation accuracy than a stand-alone circuit or device simulator by numerically
modeling the critical devices in a circuit. Compact models can be used for all other de-
vices. The mixed-level extensions to ngspice is CIDER, a mixed-level circuit and device
simulator integrated into ngspice code.
Ngspice supports mixed-signal simulation through the integration of XSPICE code. XSPICE
software, developed as an extension to Spice3C1 by GeorgiaTech, has been enhanced and
ported to ngspice to provide ‘board’ level and mixed-signal simulation.
The XSPICE extension enables pure digital simulation as well.
New devices can be added to ngspice by several means: behavioral B-, E- or G-sources,
the XSPICE code-model interface for C-like device coding, and the ADMS interface based
on Verilog-A and XML.
Finally, numerous small bugs have been discovered and fixed, and the program has been
ported to a wider variety of computing platforms.
33
34 CHAPTER 1. INTRODUCTION
1.1 Simulation Algorithms
Computer-based circuit simulation is often used as a tool by designers, test engineers,
and others who want to analyze the operation of a design without examining the physical
circuit. Simulation allows you to change quickly the parameters of many of the circuit ele-
ments to determine how they affect the circuit response. Often it is difficult or impossible
to change these parameters in a physical circuit.
However, to be practical, a simulator must execute in a reasonable amount of time.
The key to efficient execution is choosing the proper level of modeling abstraction for
a given problem. To support a given modeling abstraction, the simulator must provide
appropriate algorithms.
Historically, circuit simulators have supported either an analog simulation algorithm or a
digital simulation algorithm. Ngspice inherits the XSPICE framework and supports both
analog and digital algorithms and is a ‘mixed-mode’ simulator.
1.1.1 Analog Simulation
Analog simulation focuses on the linear and non-linear behavior of a circuit over a con-
tinuous time or frequency interval. The circuit response is obtained by iteratively solving
Kirchhoff’s Laws for the circuit at time steps selected to ensure the solution has converged
to a stable value and that numerical approximations of integrations are sufficiently accu-
rate. Since Kirchhoff’s laws form a set of simultaneous equations, the simulator operates
by solving a matrix of equations at each time point. This matrix processing generally
results in slower simulation times when compared to digital circuit simulators.
The response of a circuit is a function of the applied sources. Ngspice offers a variety
of source types including DC, sine-wave, and pulse. In addition to specifying sources,
the user must define the type of simulation to be run. This is termed the ‘mode of
analysis’. Analysis modes include DC analysis, AC analysis, and transient analysis. For
DC analysis, the time-varying behavior of reactive elements is neglected and the simulator
calculates the DC solution of the circuit. Swept DC analysis may also be accomplished
with ngspice. This is simply the repeated application of DC analysis over a range of
DC levels for the input sources. For AC analysis, the simulator determines the response
of the circuit, including reactive elements to small-signal sinusoidal inputs over a range
of frequencies. The simulator output in this case includes amplitudes and phases as
a function of frequency. For transient analysis, the circuit response, including reactive
elements, is analyzed to calculate the behavior of the circuit as a function of time.
1.1.2 Device Models for Analog Simulation
There are three models for bipolar junction transistors, all based on the integral-charge
model of Gummel and Poon; however, if the Gummel-Poon parameters are not specified,
the basic model (BJT) reduces to the simpler Ebers-Moll model. In either case and in
either models, charge storage effects, ohmic resistances, and a current-dependent output
conductance may be included. The second bipolar model BJT2 adds dc current compu-
tation in the substrate diode. The third model (VBIC) contains further enhancements
for advanced bipolar devices.
1.1. SIMULATION ALGORITHMS 35
The semiconductor diode model can be used for either junction diodes or Schottky barrier
diodes. There are two models for JFET: the first (JFET) is based on the model of
Shichman and Hodges, the second (JFET2) is based on the Parker-Skellern model. All
the original six MOSFET models are implemented: MOS1 is described by a square-law
I-V characteristic, MOS2 [1] is an analytical model, while MOS3 [1] is a semi-empirical
model; MOS6 [2] is a simple analytic model accurate in the short channel region; MOS9,
is a slightly modified Level 3 MOSFET model - not to confuse with Philips level 9; BSIM
1 [3, 4]; BSIM2 [5] are the old BSIM (Berkeley Short-channel IGFET Model) models.
MOS2, MOS3, and BSIM include second-order effects such as channel-length modulation,
subthreshold conduction, scattering-limited velocity saturation, small-size effects, and
charge controlled capacitances. The recent MOS models for

Continue navegando