LTSpice and subcircuits

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Disabled Account
Joined 2003
Hi, folks:

I am trying to incorporate the spice models provided by IRF in my design simulated under LTSpice. the IRF models come in as sub circuits and I went through the FAQ and here is what it said about using 3rd party subcircuit spice model:

"If you want to use a subcircuit, follow the following steps:

1. Change the "Prefix" attribute of the component instance of the symbol to be an 'X'. Don’t change the symbol, just the instances of the symbol as a component on a schematic.

2. Edit the value of the component to coincide with the name of the subcircuit you wish to use.

3. Add a SPICE directive on the schematic such as ".inc filename" where filename is the name of the file containing the definition of the subcircuit."

Just precisely what I should do to incorporate a subcircuit in a file called IRF540.spi that reads like:

Thanks in advance.

=======IRF540.spi==========================
.SUBCKT irf540 1 2 3
**************************************
* Model Generated by MODPEX *
*Copyright(c) Symmetry Design Systems*
* All Rights Reserved *
* UNPUBLISHED LICENSED SOFTWARE *
* Contains Proprietary Information *
* Which is The Property of *
* SYMMETRY OR ITS LICENSORS *
*Commercial Use or Resale Restricted *
* by Symmetry License Agreement *
**************************************
* Model generated on Apr 24, 96
* Model format: SPICE3
* Symmetry POWER MOS Model (Version 1.0)
* External Node Designations
* Node 1 -> Drain
* Node 2 -> Gate
* Node 3 -> Source
M1 9 7 8 8 MM L=100u W=100u
* Default values used in MM:
* The voltage-dependent capacitances are
* not included. Other default values are:
* RS=0 RD=0 LD=0 CBD=0 CBS=0 CGBO=0
.MODEL MM NMOS LEVEL=1 IS=1e-32
+VTO=3.56362 LAMBDA=0.00291031 KP=25.0081
+CGSO=1.60584e-05 CGDO=4.25919e-07
RS 8 3 0.0317085
D1 3 1 MD
.MODEL MD D IS=1.02194e-10 RS=0.00968022 N=1.21527 BV=100
+IBV=0.00025 EG=1.2 XTI=3.03885 TT=1e-07
+CJO=1.81859e-09 VJ=1.1279 M=0.449161 FC=0.5
RDS 3 1 4e+06
RD 9 1 0.0135649
RG 2 7 5.11362
D2 4 5 MD1
* Default values used in MD1:
* RS=0 EG=1.11 XTI=3.0 TT=0
* BV=infinite IBV=1mA
.MODEL MD1 D IS=1e-32 N=50
+CJO=2.49697e-09 VJ=0.5 M=0.9 FC=1e-08
D3 0 5 MD2
* Default values used in MD2:
* EG=1.11 XTI=3.0 TT=0 CJO=0
* BV=infinite IBV=1mA
.MODEL MD2 D IS=1e-10 N=0.4 RS=3e-06
RL 5 10 1
FI2 7 9 VFI2 -1
VFI2 4 0 0
EV16 10 0 9 7 1
CAP 11 10 2.49697e-09
FI1 7 9 VFI1 -1
VFI1 11 6 0
RCAP 6 10 1
D4 0 6 MD3
* Default values used in MD3:
* EG=1.11 XTI=3.0 TT=0 CJO=0
* RS=0 BV=infinite IBV=1mA
.MODEL MD3 D IS=1e-10 N=0.4
.ENDS

==========end=========================
 
Forget what they write in the FAQ and do it this way, which
should work (I actually just tested since it has been a while
since I did it).

1) Save the file with the subcircuit definition (the one you quoted)
in the lib/sub directory and call it irf540.sub

2) in the lib/sym directory, you find all the graphical symbols.
Copy the file nmos.asy and call it irf540.asy (must be the same
name as the sub file above). Then click on this file to open the
symbol editor where you can change the generic name NMOS
to IRF540.

"Advanced course"
------------------------
The asy file may be placed in a subdirectory of lib/sym. Since
many MOSFET models come as subcircuits rather than just
spice models, I have a directory named transistors where
I put all such transistors. You will find there already are
such subdirectories for opamps etc. and this ís reflected by
the component selection hierarchy you see when using LTSpice.
As far as I remember you cannot have a hierarchy in the mod
directory on the other hand, but that matters less since the
sym directory dictates the selection hierarchy.

Furthermore, in case you don't already know it, components
that come as .model commands need not be handled
in the above way. They are better just added to the appropriate
file in the lib/cmp directory. There are files called standard.bjt
standard.cap etc, with the obvious meaning.
 
Disabled Account
Joined 2003
Thanks, Christer.

another question: how do you link the symbol with the model? I can pick up the irf540, and place it on the schematic. but when I right click on it, choose "Pick New MOSFET", how do I tell LTSpice that it should use the newly created IRF540.sub?

Thanks in advance.
 
millwood said:
Thanks, Christer.

another question: how do you link the symbol with the model? I can pick up the irf540, and place it on the schematic. but when I right click on it, choose "Pick New MOSFET", how do I tell LTSpice that it should use the newly created IRF540.sub?

Thanks in advance.

You can't :)

LTSpice doesn't know that it is a MOSFET since it is defined
by a subcircuit. Hence, every component suchly defined must
have its own symbol file (the .asy file). Those MOSFETs that
ship with the program are defined by .model commands only
and are located in the standard.mos (or whatever it was) file.
These are known by the program to be MOSFETs and share
a common generic symbol, so you can choose any particular
device of those in this file. However, this file cannot contain
subcircuits, so these must be treated as special cases. A bit
awkward, but nothing one cannot live with.

This also means that you must know from the beginning that
you are going to use an IRF540. You cannot put a generic
MOSFET in and then say that it is an IRF540. You can delete
the generic MOSFET and replace it with an IRF540, though.
Actually, you do have the same problem with opamps. You
can't start with a generic one and then decide that it should
be an LT1115.
 
Disabled Account
Joined 2003
Christer,

I had created IRF540.sub in lib/sub directory, as well as IRF540.asy under lib/sym/My Devices.

the problem is that when I put in an IRF540, it is the default NMOS model. so if I right click it, i have just the choices in standard.mos.

In essence, there is no link between IRF540.asy to IRF540.sub. Whenever I put in IRF540 in the schematics, the software is actually thinking that it is a perfect n-channel mosfet.

I just wanted to add a little bit. the lt opamps are implemented somewhat different (via subckt I believe) in that once you had them selected, you cannot switch. I guess all I needed to do is to figure out how the LT opamps are implemented and do the samething with the irf subcircuits.
 
You are quite right. I actually did think that I had to provide
such linking last time I did it, but was fooled by the fact that
the newer version of LTSPice brings up a graphical editor instead
of Notepad when you click an asy file, and I didn't find a way
to access the linkage info (there probably is one). Sorry
for that.

You must actually edit the .asy file with a text editor. Below is an
example how I modified the .asy file for an 2SK1058, which is
also an NMOS. Perhaps it is simplest that you take this file and
just replace the device number everywhere. I think that should
be all there is to it. You may compare it to the generic NMOS
file to see the pattern for how to modify these files.

Version 3
SymbolType CELL
LINE Normal 12 12 12 24
LINE Normal 4 20 12 20
LINE Normal 10 12 12 12
LINE Normal 4 12 10 11
LINE Normal 4 12 10 13
LINE Normal 10 11 10 13
LINE Normal 4 2 4 6
LINE Normal 4 10 4 14
LINE Normal 4 18 4 22
LINE Normal 0 20 2 20
LINE Normal 2 4 2 20
LINE Normal 12 4 4 4
LINE Normal 12 0 12 4
WINDOW 0 14 8 Left 0
WINDOW 3 14 18 Left 0
SYMATTR Prefix X
SYMATTR SpiceModel 2sk1058.mod
SYMATTR Value 2SK1058
SYMATTR Value2 2SK1058
SYMATTR Description N-Channel MOSFET transistor
PIN 0 20 NONE 0
PINATTR PinName G
PINATTR SpiceOrder 2
PIN 12 0 NONE 0
PINATTR PinName D
PINATTR SpiceOrder 1
PIN 12 24 NONE 0
PINATTR PinName S
PINATTR SpiceOrder 3
 
Here's what I did with the AD797 op-amp with LTSpice.

1.) Copied an existing LT opamp symbol file to ad797.asy in the lib\sym\opamps directory.

2.) Renamed the Analog Devices model file ad797.mod and put it into the lib\sub directory.

3.) Edited the .asy file in the graphical editor. Brought up the attributes editor using Edit, attributes (Ctrl-A).

4.) Chose:
Symbol type: cell
Prefix: X
SpiceModel: ad797.mod
Value: ad797
Value2: ad797
and put in a description

5.) Right-click on each pin/port and make sure "netlist order" value is the same as the position of the parameter of the subcircuit in the .mod file. These aren't node numbers, but the "parameter numbers", which are sequential from 1 to the number of parameters of the subcircuit.

This worked without needing a .inc directive, probably because I made use of existing directories for the files that the program already knows about.

If you get completely stuck, there's a great group on Yahoo for LTSpice at:
http://groups.yahoo.com/group/LTspice

One group member, Helmut Sennewald, has created a cool utility which takes the binary .raw files and converts them to ASCII, with tons of options for what parameters to include and exclude. Great for post-processing. I've gotten some great tips there for using .FOUR for distortion analysis, choosing the sample times to minimize spurious harmonic data, and other cool stuff.
 
millwood said:
I am this close to it, :)
used .include to include irf540.spi, and got a "SPICE Error: Too many parameters for subcircuit type "irf540" (instance: xu1)".

Any suggestions?
Millwood ,

If you have put the line like
“SYMATTR SpiceModel IRF540.spi”
into the IRF540.asy file, delete it, i.e. modify only “SYMATTR Prefix” (use X) and “SYMATTR Value” lines. This done and for spice analysis .inc (.include) command will be enough.

If you still have a problems, as a first aid this is the .model file for IRF540. Just copy it to the lib/cmp/standard.mos file.

________________________________________________
.model IRF540 NMOS(Level=3 Gamma=0 Delta=0 Eta=0 Theta=0 Kappa=0.2 Vmax=0 Xj=0
+ Tox=100n Uo=600 Phi=.6 Rs=21.34m Kp=20.71u W=.94 L=2u Vto=3.136
+ Rd=22.52m Rds=444.4K Cbd=2.408n Pb=.8 Mj=.5 Fc=.5 Cgso=1.153n
+ Cgdo=445.7p Rg=5.557 Is=2.859p N=1 Tt=142n)
*$
________________________________________________

Pedja
 
I've been bashing my head against the same problem for 3 hours, I've had a good google, but have just found brief instructions. Something is not right and I haven't found any examples of .asy and .sub files that actually work. I've tried a coupke of other ones I found elsewhere, but always get an error.

Here's my best guess, which does work, could anyone tell me what I'm doing wrong?

/lib/sub/BSC026N02KS.sub

.SUBCKT BSC026N02KS drain gate source

Lg gate g1 3n
Ld drain d1 1n
Ls source s1 1n
Rs s1 s2 361u

Rg g1 g2 1.5
M1 d2 g2 s2 s2 DMOS L=1u W=1u
.MODEL DMOS NMOS ( KP= 552.4 VTO=1.61 THETA=0 VMAX=1.5e5 ETA=0.01 LEVEL=3)
Rd d1 d2 1.28m TC=6.5m

Dbd s2 d2 Dbt
.MODEL Dbt D(BV=24 M=0.35 CJO=3.24n VJ=0.7V)
Dbody s2 21 DBODY
.MODEL DBODY D(IS=1225.4p N=1.21 RS=0.95u EG=1.12 TT=3n)
Rdiode d1 21 0.95m TC=7m

.MODEL sw NMOS(VTO=0 KP=10 LEVEL=1)
Maux g2 c a a sw
Maux2 b d g2 g2 sw
Eaux c a d2 g2 1
Eaux2 d g2 d2 g2 -1
Cox b d2 2.57n
.MODEL DGD D(M=1 CJO=2.57n VJ=0.5)
Rpar b d2 1Meg
Dgd a d2 DGD
Rpar2 d2 a 10Meg
Cgs g2 s2 5.62n

.ENDS


in /lib/sym/BSC026N02KS.asy

Version 4
SymbolType CELL
LINE Normal 48 48 48 96
LINE Normal 16 80 48 80
LINE Normal 40 48 48 48
LINE Normal 16 48 40 44
LINE Normal 16 48 40 52
LINE Normal 40 44 40 52
LINE Normal 16 8 16 24
LINE Normal 16 40 16 56
LINE Normal 16 72 16 88
LINE Normal 0 80 8 80
LINE Normal 8 16 8 80
LINE Normal 48 16 16 16
LINE Normal 48 0 48 16
WINDOW 0 56 32 Left 2
WINDOW 3 56 72 Left 2
SYMATTR Value BSC026N02KS
SYMATTR Prefix X
SYMATTR SpiceModel BSC026N02KS
SYMATTR Description BSC026N02KS
PIN 48 0 NONE 0
PINATTR PinName D
PINATTR SpiceOrder 1
PIN 0 80 NONE 0
PINATTR PinName G
PINATTR SpiceOrder 2
PIN 48 96 NONE 0
PINATTR PinName S
PINATTR SpiceOrder 3

I've tried the subcircuit as .mod and .inc, but it still barfs, error message:

Unknown subcircuit called in:

xu1 n005 n003 bsc026n02ks.sub bsc026n02ks

I've also tried another spice model for that transistor, same problem:

.SUBCKT BSC026N02KS_L1 drain gate source PARAMS: dVth=0 dRdson=0 dgfs=0 dC=0 Ls=1n Ld=1n Lg=3n

.PARAM Rs=361u Rg=1.5 Rd=50u Rm=190u
.PARAM Inn=50 Unn=4.5 Rmax=2.6m gmin=57
.PARAM act=6.77

X1 d1 g s Tj S3_20_s_var PARAMS: a={act} dVth={dVth} dR={dRdson} dgfs={dgfs} Inn={Inn} Unn={Unn}
+Rmax={Rmax} gmin={gmin} Rs={Rs} Rp={Rd} dC={dC} Rm={Rm}
Rg g1 g {Rg}
Lg gate g1 {Lg*if(dgfs==99,0,1)}
Gs s1 s VALUE={V(s1,s)/(Rs*(1+(limit(V(Tj),-200,999)-25)*4m)-Rm)}
Rsa s1 s 1Meg
Ls source s1 {Ls*if(dgfs==99,0,1)}
Rda d1 d2 {Rd}
Ld drain d2 {Ld*if(dgfs==99,0,1)}

E1 Tj w VALUE={TEMP}
R1 w 0 1u

.ENDS
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.