Linux下的电路仿真
一、使用gschem编辑电路原理图
添加元件可以直接按快捷键i或者在菜单栏中点击【添加】--【】,就会弹出添加元件对话框:
添加元件的时候,尽量使用带有simulation字样的元件库。如果没有,使用其他元件库也可以,对于
仿真来说,重要的不是元件外观,也不是元件来至于那个元件库,而是元件的仿真相关的属性
好的mv双击刚刚放好的运算放大器,就会弹出属性对话框:
关于这些属性的意义,最好参考gEDA的文档,对于准备使用Linux系统的人来说,看文档是必备技能。这里简单复制一点文档内容:
refdes: The reference designator of the component.
value: For passives, this is the component value. For actives, this is the type (model no.) of the component (e.g. 2N3904, uA741). When a model for an active is instantiated separately from the component itself, the value attribute holds the name of the spice model.
model: This holds a one line spice model for the component.
file: This holds the name of a file. Typically, this is a file a SPICE .MODEL, .SUBCKT, or other SPICE code.
model-name: This holds the name of the spice model referred to in a .MODEL or
.SUBCKT statement. model-name is mainly used to identify the spice model name in the symbol spice-model-1.sym. Active components should call out this name in the device attribute to associate the component with its particular spice model or subcircuit.
type: This specifies the type of component and is used by spice when interpreting the model parameters. Valid values depend upon the device being modeled.
这里只设置仿真相关的属性,设置的时候,在下面的Add Attribute中选择Name,然后填写Value,再点击添加,即可添加属性,所有属性设置好以后如下所示:
这里,为了方便显示属性,我将每个属性都显示了属性名和属性值,设置后的元件如图:
如果,不想显示属性的Name,只需要在属性对话框中,将N对应的那一列的勾去掉即可。然后一次添加其他元件,所有元件添加好以后,效果如下:
摆放好元件,设置好属性以后,就连线,注意,这里要连接的是Net,【添加】---【Net】或者使用快捷键n,注意,鼠标右键是结束当前连接的Net,开始绘制新的Net。绘制好的电路图如下:
这时候,还需要给一些Net命名一下,注意,接地的网络要命名为0,其余的名称任意,也可以不命名。命名的方法,就是选中网络所连接的线,然后点击右键【Add Attribute】:
Name选择netname,在Value中添加网络名,这里我只设置0,Vin和Vout三个网络名。
设置好网络名如下所示:
这样,电路就基本完成了,还需要设置一些仿真用的信息。首先,需要下载LM324.MOD,这个文件你可以在谷歌直接搜索文件名下载。
LM324.MOD中有这样一句:
.SUBCKT LM324/NS    1  2  99  50  28
注意,这里需要把/NS删掉,否则仿真的时候会报错,说不到.SUBCKT LM324。
这个文件下载下来以后,在原理图所在的文件夹中,新建个文件夹,命名为models,专门用来存放MOD文件。这个仿真中只用到了LM324.MOD。其他元件,如果能够仿真,一般供应商都会提供MOD文件,或者提供相应的参数,具体可以查PSICE资料学习。
很多IC元件仿真的MOD文件都可以在网上下载的到,因为这些MOD文件有版权的,所以ngspice并不包含这些文件,需要你自己从网络下载,或者到IC供应商的网站上下载。
添加MOD文件到原理图中,在SPICE仿真库中,添加这个元件:
这个SPICE元件就是告诉你要包含那些模型文件,就是MOD文件。添加并设置属性下:
其中,file属性,就是你的.MOD文件的所在位置,填写相对路径即可。