本文对比下Spice文件的写法
Spice1
1972年诞生于美国加利福尼亚大学 柏克莱分校的SPICE(Simulation Program with Integrated Circuit Emphasis)
Spice 标准写法
A SPICE input file, called source file, consists of three parts.
- Data statements: description of the components and the interconnections.
- Control statements: tells SPICE what type of analysis to perform on the circuit.
- Output statements: specifies what outputs are to be printed or plotted.
1TITLE STATEMENT
2ELEMENT STATEMENTS
3.
4.
5COMMAND (CONTROL) STATEMENTS
6OUTPUT STATEMENTS
7.END <CR>
The first line of this file is used as a title on output files. It is not included in the circuit description. A common and frustrating error is caused by omitting the title.
The file must end with the command .END followed by a newline.
Comment entire lines by beginning them with an asterisk(*),eg.
*comments
åor the rest of a line by using a ’;’Continue a statement on a new line with ’+’(一般一行最多只有80个字符)
SPICE uses only uppercase characters
Delimiter
Spaces, commas, equal signs, left and right parentheses, etc. can be used as delimiters, extra delimiters are invalid.
The Circuit Description(netlist)
The format of an element description is
1<letter><name> <n1> <n2> ...[mname] [parvals]
where <...>
must be present and [...]
is optional.
<letter>
is a single letter denoting the component type<name>
is a unique alpha-num combination describing the particular instance of this component<ni>
is the name of a node. One node name has a defined meaning. Node 0 is ground![mname]
is the (optional) model name[parvals]
are (sometimes optional) parameter values
首字母 | 电路元器件 | 首字母 | 电路元器件 |
---|---|---|---|
B | 砷化镓场效应管 | L | 电感 |
C | 电容 | M | MOS场效应管 |
D | 二极管 | Q | 双极型晶体管 |
E | 电压控制电压源 | R | 电阻 |
F | 电流控制电流源 | S | 电压控制开关 |
G | 电压控制电流源 | T | 传输线 |
H | 电流控制电压源 | V | 独立电压源 |
I | 独立电流源 | W | 电流控制开关 |
J | 结型场效应管 | X | 子电路 |
K | 互感(耦合系数) |
Sign Convention
Two-terminal elements (including sources!) assume the “load” sign convention
Unit
The following abbreviations for powers of ten are recognized by spice .
$$\begin{array}{cccccccccc} \text { F } & \text { P } & N & U & \text { M } & \text { K } & \text { MEG } & \text { G } & \text { T } & \text { MIL } \newline \text { femto } & \text { pico } & \text { nano } & \text { micro } & \text { milli } & \text { kilo } & \text { mega } & \text { giga } & \text { tera } & \text { mil }(10^{-3} \text { inch }) \newline 10^{-15} & 10^{-12} & 10^{-9} & 10^{-6} & 10^{-3} & 10^{+3} & 10^{+6} & 10^{+9} & 10^{+12} & 25.4 \times 10^{-6} \end{array}$$
Once a valid suffix is read, spice ignores following letters. Thus 10pF, 10pAmps, and 10psec all simply represent the value $10^{−12}$. MIL is used to convert distances in thousands of an inch, since spice uses metric lengths.
Passive Elements
The <letter>
that begins an element instance denotes the circuit element. The passive
elements are
R or r for resistors, L or l for inductors, and C or c for capacitors.
This <letter>
is followed by a unique instance name and then (in order) the nodes
associated with + and - voltage and the value of the associated parameter (R, L, or C).
Examples:
- R1 5 0 20k
- cload nIN GND 250pF
- L4 122 21 4mH
Independent Sources
1V<name> <n+> <n-> [type] <val>
defines an independent voltage source with its + terminal at node n+ and its - node at node n-.
1I<name> <n+> <n-> [type] <val>
defines an independent current source whose current flows through the source from node n+ to node n-.
Examples:
Vdd 4 0 5
defines a 5 V source with the + terminal connected at node 4 and the - terminal connected at node 0 (ground)ibias 18 4 DC 15m
V2 3 0 25V
( spice recognizes the common abbreviations for units, which helps to make source files more easily understood by humans.)- The optional type argument will be described in the analysis commands
Voltage-Controlled Dependent Sources
The voltage-controlled dependent sources are defined using statements of the form
1<letter><name> <nout+> <nout-> <nc+> <nc-> <gain>
or
1<letter><name> <nout+> <nout-> (<nc+>,<nc->) <gain>
where E is a voltage-controlled voltage source, G is a voltage-controlled current source, the output voltage is connected between nodes nout+ and nout-, and the control voltage is measured at node nc+ with respect to node nc-.
Examples:
Ex 5 1 4 3 10
defines a voltage source that makes node 5 a voltage 10(v4 − v3) above the voltage at node 1G1 2 1 (5,8) 50m
defines a current source connected between node 2 (the + node) and node 1 and supplying a current 50 mOhm^-1(v5 − v8)
Current-Controlled Dependent Sources
Diodes
Bipolar Junction Transistors
MOSFETs
Subcircuits
A subcircuit simplifies spice netlists by allowing re-use of a set of circuit elements. The syntax is
1SUBCKT <SubName> <N1> <N2> ...
2...
3.ENDS
The SubName is the name used to reference the subcircuit, and the nodes are the internal node numbers used to connect to the subcircuit.
- A subcircuit can contain any spice netlist statements, including .model statements and other subcircuits.
- Any elements, nodes, models, subcircuits, or definitions in the subcircuit are completely local to the subcircuit.
Hspice
Hspice 可在直流到100GHz的频率范围内对电路进行准确的仿真、分析及优化。其主要特征如 下:
- 极佳的收敛性。
- 精确的模型。
- 对模型及单元的电路优化,可同步优化多种参数。
- 支持蒙特卡罗和最差情况分析。
- 参数化单元的输入、输出及行为级代数描述。
Hspice 子电路
子电路定义声明
.subckt 或.macro
语法: .SUBCKT subnam n1 < n2 n3 …> < parnam=val …> 或 .MACRO subnam n1 < n2 n3 … > < parnam=val …> 说明:
- subnam 子电路名。
- n1,n2… 子电路接口节点名。
- parnam=val 子电路参数,应指定初值。
子电路定义结束声明
.ends 或.eom
子电路调用声明
语法: Xyyy n1 <n2 n3 …> subnam <parnam=val …> <M=val>
- Xyyy 子电路名,必须以“X”开始。
- n1,n2… 子电路连接到的外部节点。
- subnam 所调用的子电路名。
- parnam=val 为调用的子电路参数赋值。
例子
下面例子定义了两个子电路sub1和sub2 都是将电阻值参数化的电阻分压网络, 其中子电路 sub1 的定义中调用了子电路 sub2。x1,x2,x3 声明调用了这些子电路,由于 每次调用都为电阻赋了不同的值,三次调用产生了不同的子电路。
1*FILE SUB2.SP TEST OF SUBCIRCUITS
2.OPTIONS LIST ACCT
3*
4V1 1 0 1
5.PARAM P5=5 P2=10
6*
7.SUBCKT SUB1 1 2 P4=4
8R1 1 0 P4
9R2 2 0 P5
10X1 1 2 SUB2 P6=7
11X2 1 2 SUB2
12.ENDS
13*
14.MACRO SUB2 1 2
15P6=11
16R1 1 2 P6
17R2 2 0 P2
18.EOM
19*
20X1 1 2 SUB1 P4 =6
21X2 3 4 SUB1 P6=15
22X3 3 4 SUB2
23*
24.MODEL DA D CJA=CAJA CJP=CAJP VRB=-20 IS=7.62E-18
25+ PHI=.5 EXA=.5 EXP=.33 *
26.PARAM CAJA=2.535E-16 CAJP=2.53E-16
27.END
子电路节点调用
表示子电路中的器件,将电路层次以“.”连接: 如:X1.XBIAS.M5
表示子电路中的节点: 如:.PRINT v(X1.X4.sig25) ,sig25是子电路x4中的节点。
其他声明
.global 声明
.global全局性地定义节点名,不管处于电路中的什么层次上,只要与.global中定义的节点名称相同,他们就连接在一起。 .global通常用来定义电源连接。
例: .GLOBAL VDD input_sig
电路中所有与VDD重名的节点都连接在一起,所有与input_sig重名的节点也连接在 一起。
.temp 声明
声明电路运行的温度。默认为 25°C。 例:.TEMP -55.0 25.0 125.0
.data 声明
可用于.dc,.ac,.tran 等分析中的参数扫描,.data 可定义任意数目的参数,使用的参数必须事先定义,
.data 可定义三种数据
- 网表内数据(inline data)
- 外部文件串接数据(data concatenated from external files) - 外部文件并接数据(data column laminated from external files)
这里只介绍网表内数据的定义 语法: .DATA datanm pnam1 <pnam2 pnam3 … pnamxxx > + pval1<pval2 pval3 … pvalxxx> + pval1’ <pval2’ pval3’ … pvalxxx’> .ENDDATA 说明:
- Datanm 数据名,供仿真分析中调用使用。
- pnam1… 参数名。
- pval1… 参数值,可以有很多组。 例子:
1 .TRAN 1n 100n SWEEP DATA=devinf
2 .AC DEC 10 1hz 10khz SWEEP DATA=devinf
3 .DC TEMP -55 125 10 SWEEP DATA=devinf
4 .DATA devinf width length thresh cap
5 + 50u 30u 1.2v 1.2pf
6 + 25u 15u 1.0v 0.8pf
7 + 5u 2u 0.7v 0.6pf
8 + ... ... ... ...
9 .ENDDATA
上面的分析中.data 定义了网表内数据 devinf,由于 Hspice 根据.data 中使用的参数 数目,自动对数据分组,并给参数赋值,因此像例子中将数据与参数对准并非必要。上 例中也说明了.data 定义的数据调用的方式,即用 data=dataname 的方式,扫描时参数 值一组组地采用。