3251|1

2657

帖子

6

TA的资源

五彩晶圆(初级)

楼主
 

LTspice(2) .TEXT使用Xnn使用 [复制链接]

 

.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的电流,由此可以证明||里的内容是等价的。

代码如下

.text NODE=|"1"+"K"|

 

但这些并不是它原本想要表达的意思,大概是懂了,但没完全懂~

 

再上面的例子中,其使用了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

 

运行仿真后结果和刚刚的结果相同,其实和实际画电路效果也差不多~

 

今天就先聊到这,拜拜~

查看本帖全部内容,请登录或者注册
此帖出自模拟电子论坛
点赞 关注
个人签名

希望做一些大家觉得好用的东西!


回复
举报

2657

帖子

6

TA的资源

五彩晶圆(初级)

沙发
 

上一篇 LTspice(1) VScode与.model 因为是微信公众号先发的,顺序不能完全照着这个(1)23来

此帖出自模拟电子论坛
 
个人签名

希望做一些大家觉得好用的东西!

 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条
ADI &文晔 探索季第一站,邀您在活动帖跟帖,ADI资深工程师将与您一道寻求解决之道! ...
春晚,最出圈当属穿着棉马甲跳秧歌的机器人”秧Bot”。
转手绢、飞手绢、变换队形,精准度和稳定性甚至超越人类,这背后少不了电机控制技术。

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表