Ngspice User Manual
Total Page:16
File Type:pdf, Size:1020Kb
Ngspice User’s Manual Version 35 plus (ngspice development version) Holger Vogt, Marcel Hendrix, Paolo Nenzi, Dietmar Warning September 27, 2021 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). 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.4 Convergence ................................... 42 1.4.1 Voltage convergence criterion ..................... 42 1.4.2 Current convergence criterion ..................... 43 1.4.3 Convergence failure ........................... 43 2 Circuit Description 45 2.1 General Structure and Conventions ...................... 45 2.1.1 Input file structure ........................... 45 2.1.2 Syntax check .............................. 45 5 6 CONTENTS 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