888888 发表于 2021-7-9 08:37:21

Models and sub-circuits 代码规则汇总

1.Sub-circuit Identification:subct < name > < pin 1 > < pin 2 > < pin 3 > :: ... PARAMS : < optional component values >
例1:.subckt 4N25 1 2 3 4 5. . .. . . ...ends 4N25A 1 K 2 C 3 E 4 B 52. Sub-circuit Body
< component name > < node1 > < node 2 > < node 3 > ... : < value >where the elements are:component name the reference of primitive component such as R2nodes the nodes within the sub-circuit to which it is connectedvalue which may contain temperature coefficient and other qualifiers or the name ofa parameter in curly brackets whose value can be set externally
代码例2:
. C2 5 0 10u
Lseries 0 3 {Lx}
D1 2 3 MyDiode   直接从库中调用;
Rout 4 2 100 tc1=0.0002
代码2解析:
This will set the value of C2 at 10u, and that cannot be changed.
Lseries is declaredas a parameter, and a value must be supplied. 电感感抗是参数控制;
Rout also is fixed at 100 Ω and so is itslinear temperature coefficient of 0.0002.设置电阻阻值和温度系数;

3.Models and Other Sub-circuits
.model < model name >
< model type > < model parameters >
.model that of an existing SPICE model, usually a semiconductor devicemodel name as found in the model database and which has been invoked previouslyin the list such as ‘MyDiode’ above although it is not an error to add a model thatis not actually used – it just bloats the sub-circuit.

model type used to specify what sort of model SPICE will use 模型类型
model parameters enclosed in brackets to change them from the default modelvalues,模型参数,可以更改默认模型值;
代码例3:
.model MyDiode D (Is=1.2e-12)

4. Ends
The sub-circuit is concluded with .ends<name>although LTspice does not insist onthe name.

888888 发表于 2021-7-9 09:29:17

5.Exclusions
A sub-circuit may not contain SPICE directives (dot commands), so it cannot specifya type of analysis such as transient, nor measure statements.
Example – Opto-Isolator Sub-circuitThe sub-circuit of the 4N25 optoisolator is: 光电耦合器4N25代码参数如下:

*Copyright © Linear Technology Corp. 1998, 1999, 2000. All rightsreserved.
.subckt 4N25 1 2 3 4 5         设置5个节点;
R1 N003 2 2D1 1 N003 LD   这表明在节点N003和2之间有一个2Ω电阻;
G1 3 5 N003 2 .876m            电压依赖电流源G1,其值为0.876 m;
C1 1 2 18p                        小电容容值18 pF;
Q1 3 5 4 NP                   晶体管Q1 其模型NP定义为一个NPN晶体管,后面有一系列参数;
.model LD D(Is=1e-20 Cjo=18p)    一个LD类型的二极管D1,它由模型调用定义,其中LD被声明为一个标准的二极管D,有两个参数从默认值更改;
.model NP NPN(Bf=610 Vaf=140 Ikf=15m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=1e-15) 调用NPN并设置相关参数
.ends 4N25

This shows that it has a 2 Ω resistor between nodes N003 and 2;
a diode D1 oftype LD which is defined by the model call where LD is declared to be a standarddiode D with two parameters changed from the default.
It also includes a voltage dependent current source G1 whose value is 0.876 m, a small capacitor of 18 pF anda transistor Q1 which has a model NP defined as an NPN transistor followed by a listof parameters.

We should also note that all the components have at least one nodeconnected to an external pin, although that is not often the case.
页: [1]
查看完整版本: Models and sub-circuits 代码规则汇总