Electrical – Adding models in LT-SPICE

ltspice

I have LT Spice the latest version XVII and I have tried to add some models from component supplies. I did it following instruction:

  • I created 2 subfolders in library folder lib placed in My user name/documents/LTSpiceXVII and either sym subfolder or sub subfolder with name MyLib for schematic symbols and model lib/sub files.
  • Copied some standard schematic library file with sym extension, for example, bipolar transistor and I changed standard name to component name.
  • Opened it in LT Spice and from menu Edit/Atributes
  • In Symbol Attribute Editor window I have changed: prefix to X, in SpiceModel I typed the component model location with file name, in Value and Value1 I typed name of component and model.
  • I saved it
    When I created schematic and found that component in library list and I placed it in schematic.
    When I wanted to edit it I got error message:

enter image description here

Could anyone tell me what is going on and why I can not edit it.


Thank you for your help. Indeed,your advice "Try adding your subcircuit name in the SpiceModel line, and the path and name of the library in the ModelFile line, and it should work as you probably intended" helped and it works as I wanted.

At the moment I have another issue. I added model with type model, this time and when I edited schematic attributes and as prefix I typed M instead of X, because it is not sub-circuit model, in SpiceModel line I put name of model, in ModelFile line I put path and file containing thes spice model.
When I run simulation I get an error message like this:

enter image description here

I don't know really what prefix I should use in schematic attribute editor when I want to add the model with model type, not sub-circuit model?
Maybe to solve this problem I could edit in model file and I could add some lines like those

.SUBCRK model_name 123
Q1 123 MAIN parameter
.model MAIN NPN
{body of model}

What do you think about it? But I don't still know what parameter I should use?
I think it is easier way to do it.

Thank you in advance,

Best Answer

Messing with the default installation files is a sure way to create confusion should you need to export a project to another computer, or to someone else, because they will not have your libraries, almost surely. It's not forbidden, either, but don't forget to only blame yourself if things go wrong.

Having said that, if you open up the manual under Schematic Capture > Creating New Symbols > Adding Attributes, you'll see this somewhere in the page:

There is a special combination of attributes that will cause a required library to be automatically included in every schematic that uses the symbol:

Prefix: X
SpiceModel: <name of file including the spicemodel>
Value: <What ever you want visible on the schematic>
Value2: <The value as you want in the netlist>

Value2 would be made to coincide with a subcircuit name defined in the file including the spicemodel and may pass additional parameters to the subcircuit. When a symbol is defined in this manner, an instance of the symbol as a component on a schematic cannot be edited to have different attributes.

(emphasis mine) You could have found this out on your own in less than 5min. Try not to avoid the manual, even if it is rather spartan, it may have the answers you're looking for. Additionally, you could also search ltwiki for other, hidden explanations. But it really boils down to: know your tool before using it.


Try adding your subcircuit name in the SpiceModel line, and the path and name of the library in the ModelFile line, and it should work as you probably intended.


This should be a new question, but models are not handled like subcircuits. Models reside in LTspiceXVII/lib/cmp, and there is no other default path where LTspice looks into. It's not recommended that you should modify these files, but it's not forbidden, also; if something goes wrong, don't forget o blame yourself, not others, or LTspice.

The recommended ways of doing it are:

  • Add your model as a SPICE directive: press s and paste the .model definition there, place it in the schematic, then rename the symbol as the .model. You could use any symbol that has the correct number of pins, but it's easier to work with readily avaiable ones. For example, if you want a NPN, you should choose the default NPN symbol (or NPN2/3/4), and only rename NPN to whatever name the model has. If it's .model BC107 NPN(...), then rename NPN to BC107.

  • Or, if your model definitions are stored elsewhere, LTspice also accepts full paths to that location in the form of .inc /full/path/to/custom_models.txt, or whatever path and name exists.

So, for your case, if you have a transistor model, not a subcircuit, then place an appropriate symbol in the schematic, rename NPN, or NMOS, or whatever to the desired .model <NAME> ..., and make sure that the prefix is the correct one: N for NPN or PNP, M for NMOS or PMOS, etc. Then, either use the .inc card to include an ASCII file with the model definition that resides on your storage, or copy-paste the definition and place it as a SPICE directive in the schematic by pressing s.