.TEXT使用
凡是先看说明书,啥都不看先看语法,觉得大概是 c语言define那个意思。
Syntax: .text <name>=<string literal>
Example: .text DIODE = "1N4148"
The .text allows the creation of user-defined strings. It allows a string with a name. That name can be used, e.g., a model or subcircuit name and then by changing the string associated with the name, a different model or subcircuit is used throughout the simulation.
The .text can be included inside a subcircuit definition to limit the scope the string value to that subcircuit. Text evaluation is done before the subcircuits to a flat netlist.
To text substitution and text expression evaluation, enclose the expression in pipe, '|', characters. The enclosed expression will be replaced with string value of the name inside the pipes.
Below is an example using both a and local .text definitions.
下面是它给出的例子
*
V1 1 0 PULSE(0 1 0 1u 1u .5m 1m)
R1 |node| 1 |"1" + "K"|
C1 |node| 0 |foobar|
X1 2 div 0 NIX
.text node="2"
.text foo=".1" bar="u"
.text foobar = foo + bar
.tran 3m
.text top="100k"
.text bot="100k"
.subckt nix a b c
.text bot="1Meg"
R1 a b |top| ; uses global scope definition of top
R2 b c |bot| ; uses locally scope definition of bot
.ends nix
.end
|
看其例子给出的语法,大概就是||里的内容是等价的,构建仿真图纸如下,
设置R1为10K时候R1的电流
设置R1为1K时候R1的电流,由此可以证明||里的内容是等价的。
代码如下
但这些并不是它原本想要表达的意思,大概是懂了,但没完全懂~
再上面的例子中,其使用了X1,我们找到X1的定义看看X1是咋回事。
Syntax: Xxxx n1 n2 n3... <subckt name> [<parameter>=<expression>]
Subcircuits allow circuitry to be defined and stored in a library for later by name. Below is an example of defining and calling a voltage divider and it in a circuit.
*
* This calls the circuit
X1 in out 0 divider top=9K bot=1K
V1 in 0 pulse(0 1 0 .5m .5m 0 1m)
*
* This is the subcircuit definition
.subckt divider A B C
R1 A B {top}
R2 B C {bot}
.ends divider
*
.tran 3m
|
看样子大概就是可以调用 divider 里面的东西,然后随意更改divider 里面东西的参数。
在LTspice里面可以直接用代码仿真,如下
把Top 改成1K分压值就变了,变成一半一半
在使用代码仿真时候,需要添加观察的波形就 Add Traces 就能看自己想看的波形。
其中X1这一行的对应关系如下:
In
|
Divider 的A
|
Out
|
Divider 的B
|
0
|
Divider 的C
|
Divider
|
代表divider的模块
|
{TOP}
|
R1的参数
|
{BOT}
|
R2的参数
|
验证我们想法,直接将代码改为以下
X1 in out 0 divider top=10K bot=10N
V1 in 0 pulse(0 1 0 .5m .5m 0 1m)
*
* This is the subcircuit definition
.subckt divider A B C
R1 A B {top}
C2 B C {bot}
.ends divider
*
.tran 3m
|
得到如下的波形,说明我们的想法是对的。
在.TEXT中有一段代码如下 令人迷惑的是它带入了r:1:1 以及r:1:2
*
v1 1 0 pulse(0 1 0 1u 1u .5m 1m)
r1 2 1 1k
c1 2 0 .1u
r:1:1 2 div 100k
r:1:2 div 0 1meg
.tran 3m
.end
|
它其实没有什么特殊作用,就是一种命名,但让人觉得疑惑,屏蔽掉1mega的对地电阻仿真结果如下
将r:1:2启动,将1mega电阻改为100k仿真结果如下,刚好等于一半
再去折腾.TEXT 改变命令行,将R1的阻值改成自定义的阻值仿真代码如下
v1 1 0 pulse(0 1 0 1u 1u .5m 1m)
.text as1=|"1"+"k"|
r1 2 1 |as1|
c1 2 0 .1u
r:1:1 2 div 100k
r:1:2 div 0 100k
.tran 3m
.end
|
运行仿真后结果和刚刚的结果相同,其实和实际画电路效果也差不多~
今天就先聊到这,拜拜~