I have some subcircuits that I want to define as components, but still be able to specify the component models used internally, for a much quicker testing of the design's performance under different set of models.

I know how to change the attributes of internal parts by passing the numeric notation on the SpiceLine of a symbol (.asy) to which the names of the variables are the same as the variable names of attribute values in a .subckt model definition of a model .included in a schematic.

So here's a simple subcircuit


.SUBCKT vdrop_diode 1 2

D1 1 2 1N4148

.ends vdrop_diode

here's the snapshot of the symbol: enter image description here

The only attributes filled out were:

Prefix: X
Value: vdrop_diode

Then here I want to be able to change the model of the component


.SUBCKT vdrop_diode 1 2

D1 1 2 {D_model}

.ends vdrop_diode

snapshot: enter image description here

The only attributes filled out were:

Prefix: X
Value: vdrop_diode
SpiceLine: D_model=1n4148

The default model is 1N4148 (as specified in SpiceLine), but I to be able to simply change to any model I wish. The first problem was 1N4148 passed in SpiceLine was being interpreted as 1.4148e-9. It takes the N as nano, like it was just numeric notation. But, when I tried model names that cannot be interpreted as numbers, like say BAT54 it outputs:

WARNING: Can't resolve .param d_model=(bat54)

Am I not wrapping it in quotation marks or something? Or can this just not be done.

I'm not looking to stepping through a list of model names, just specify a model name for a subcircuit definition.


Since you are NOT looking to step through model names, automatically in a simulation, I think I can help you.

Place all of your .SUBCKT models into a .LIB file somewhere handy and save the file. You will reference this file in your symbol description.

Now, when editing your symbol, use the Edit/Attributes arrow and select the presented option called Edit Attributes. You will get a nice dialog box there. Note that one of the items is called ModelFile. That is the one you want to edit. Place your newly created .LIB file's name there. Save it.

Now, to make sure things were correctly added, call up that .ASY file you created in a text editor (Wordpad, for example.) Here's an example file I have made that shows an outline of what you might also see:

Version 4
SymbolType CELL
LINE Normal 0 44 32 44
LINE Normal 0 20 32 20
LINE Normal 32 20 16 44
LINE Normal 0 20 16 44
LINE Normal 16 0 16 20
LINE Normal 16 44 16 64
LINE Normal -16 0 0 0
LINE Normal 0 0 8 20
WINDOW 0 44 11 Left 0
WINDOW 38 44 50 Left 0
SYMATTR SpiceModel 2N6028
SYMATTR Description Programmable UJT
PIN 16 0 NONE 0
PINATTR SpiceOrder 1
PIN -16 0 NONE 0
PINATTR SpiceOrder 2
PIN 16 64 NONE 0
PINATTR SpiceOrder 3

Note that there is included ModelFile next to SYMATTR. That's about what you should also see. Keep in mind that you may need to first re-start (close, then re-open) LTspice in order to get it to find the files. Maybe not, but it is more sure that way.

(Note also that in editing you will want the SpiceModel to be a visible attribute, or else you will NOT be able to see your selection on the schematic. And not seeing your selection is almost always a bad thing.)

You can now use F2 to pop up your selection for your X device (.asy) and drop it into the schematic. Right click on the device and you will be able to edit the SpiceModel entry there and set it to whatever you want. That value will be directly scanned for, by LTspice, when skimming through your models in the .LIB file you gave for the ModelFile attribute of your symbol.

Hopefully, you find that works okay.

By the way, here is the .LIB file's contents for the above .ASY:

.SUBCKT 2N6028 1 2 3
*Programable Unijunction Transistor
*       anode  gate  cathode
*node:    1      2      3
Q1 2 4 3 NMOD
Q2 4 2 1 PMOD
.MODEL NMOD NPN(IS=2E-15 VAF=100 IKF=0.3 ISE=2.5E-12 NE=1.6 RE=0.15 RC=0.15 CJE=7E-10 TF=0.6E-8 CJC=2.2E-10 TR=4.76E-8 XTB=3)
.MODEL PMOD PNP(IS=22E-15 VAF=100 IKF=0.3 ISE=1E-12 NE=1.7 RE=0.15 RC=0.15 CJE=7E-10 TF=1.6E-8 CJC=2.2E-10 TR=5.1E-8 XTB=3)
.SUBCKT 2N6027 1 2 3
*Programable Unijunction Transistor
*       anode  gate  cathode
*node:    1      2      3
Q1 2 4 3 NMOD
Q2 4 2 1 PMOD
.MODEL NMOD NPN(IS=5E-15 VAF=100 IKF=0.3 ISE=1.85E-12 NE=1.45 RE=0.15 RC=0.15 CJE=7E-10 TF=0.6E-8 CJC=2.2E-10 TR=4.76E-8 XTB=3)
.MODEL PMOD PNP(IS=2E-15 VAF=100 IKF=0.3 ISE=1.90E-12 NE=1.5 RE=0.15 RC=0.15 CJE=7E-10 TF=1.6E-8 CJC=2.2E-10 TR=5.1E-8 XTB=3)

So you can see that it isn't that complicated, in practice!

EDIT: When I place my PUJT on the schematic, and right click on it, I see:

Prefix      X
InstName    U1
SpiceModel  2N6028

Note that Value, Value2, SpiceLine, and SpiceLine2 are empty. Note also that the Prefix is X (as I think you know it should be.) And note that I do NOT have some kind of = statement in the SpiceModel line. I merely provide the name of the SUBCKT that I want to use. Nothing else. LTspice will grab that value and search the .LIB file for the SUBCKT name and, if present, will find and use it.

  • \$\begingroup\$ Looks easy enough. Will try tonight. \$\endgroup\$ – Majin_Boo Aug 10 '16 at 3:46
  • \$\begingroup\$ I keep the same for subcircuit definition vdrop_diode.txt (first one) and when I simulate it returns Missing ".ends" statement in in file "vdrop_diode.txt" I tried renaming it to "vdrop_diode.lib", but returns the same error. That's all that's in the file, those 3 lines. \$\endgroup\$ – Majin_Boo Aug 10 '16 at 12:02
  • \$\begingroup\$ It keeps showing in the log: Expanding empty subcircuit: vdrop_diode \$\endgroup\$ – Majin_Boo Aug 10 '16 at 12:39
  • \$\begingroup\$ The files I show in my answer are the actual files I use. They work fine. I haven't attempted to create your situation because I don't have enough data from you to do so. Can you update your question and show your work? The exact asy and lib you are using? \$\endgroup\$ – jonk Aug 10 '16 at 12:53
  • \$\begingroup\$ You also should NOT be using the Value line. It should be completely empty. And do not use D_Model=, either. Not in your SpiceModel line. You just use the model name you want. Nothing more. \$\endgroup\$ – jonk Aug 10 '16 at 12:58

You can do like this: .step param modelselector list 11 12 13 14 .model 11 ako:1N4148 .model 12 ako:1N5819 .model 13 ako:BAT54 .model 14 ako:MBRS360

Use the diode symbol and call the diode {modelselector} in your sim.

You can then use this method to replace any subckt with another and step through them.

I'm not sure how to help you with passing the model name to the subckt.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.