# LTspice .param variable component selection

Update: In case I could not explain myself clearly, I am reparaphrasing what I want to achieve. Let's say I will have 8 opAmps. Their symbol is opamp2 and their values will be LM741 with ".lib lm741.sub" attached. Now, consider I want to change all those opAmps at the same time to being TL082 which is another model and I have also included it with ".lib tl082.sub". For now, I do that by changing all LM741s with TL082 manually. So, I want to give a variable to all those opAmps which will be a string of the model name. So just by changing the value of that parameter, I can get all opAmps changed. As seen, I don't try to change things during simulation. I just need to do it before simulation.. Thus, if the situation was I could not explain my goal, I hope this time it is clear.

Can I use .param to change the model of a component in LTspice? I am talking about something like that:

Apparently, this style does not work, I wonder is there a way to do this. The reason why I want to be able to do it is, to be able to change multiple components with one modification.

Apparently, from your comments, you already know how to find and use the Opamps\opamp2 symbol. But you'd like to step through a variety of opamp models in simulation and you'd like to avoid having to run around editing things.

## Approach 1

LTspice doesn't like non-numerics, as a rule. It's more like a fancy numeric calculator than a symbolic algebraic processor. So if you'd just wrap up your opamps into .subckt models using numbers as their names, things go much more nicely.

So, let's take your schematic and make it work (please note that I don't have a TL082 model, so I'm using different devices for which I do have models):

Note that I've wrapped up the opamp models into little .subckt macros. But also note that those model names are numeric. This is important.

Now, the above will run fine. And, if you want to change the opamp all you have to do is to, for example, set filterOA=1632 to access the other model I've included. So it's really easy to change, now. Yes?

Here I've used .op because that gives you a complete dump of useful values. You could also use .tran, too.

## Approach 2

Of course, I'm lazy. Who wants to run it, edit it, run it again, etc? If you are really, really lazy like I am then the above becomes:

I've used .tran here. (You can still use .op if you want.) Regardless, now it will step through, using all of the opamp models that you have available and listed.

What you lose in stepping values though is that the .op card will no longer provide a nice dump of all the DC operating point values for each step. Instead, it wants to act more like .tran except that the $$\x\$$-axis now represents your numbered .subckt models. You can use that to some advantage (use 1, 2, and 3, etc, instead of wildly different numbers I just used.) But it does make getting all the DC operating point values a little more cumbersome when you use .step.

## Approaches for BJTs, MOSFETs, Diodes, etc.

There are entirely different techniques for BJTs, for example. (And there's more for other part types, but then I'd have to write a book and I'd rather not. I don't mind long answers, but textbooks are beyond my interest -- and besides, they already exist.)

There exists an ako modifier of the .model card. And it's really a lot easier to use than .subckt (which you can still also use, too -- more on that, later.) I am not going to write examples using MOSFETs, but I'll cover BJTs and an LED for fun. Everything in one nice package.

And here's the results of that run:

As you can see, you can go nuts with this. I've provided three different BJT models, three different LED models, and combined all of them for a total of 9 runs.

It just works.

## Approaches for BJTs, MOSFETs, Diodes, etc -- Using .subckt instead

You can, of course, do all this with .subckt, instead. It's harder, though.

First off, you have to edit the BJT symbol by using ctrl-right-Click on the BJT to call up the Component Attribute Editor. Here, you need to change the "Prefix" from (in the case of an NPN) QN to X. This is because the original symbol was designed to be a Q of type N and that won't access the .subckt mechanism. So you do have to change the symbol's attributes so that LTspice knows that it is a sub-circuit symbol and not a BJT symbol, anymore.

So here is the same circuit, from above, but now implemented with .subckt, instead:

Please note that I had to modify the NPN symbols using the following dialog (Yellow color highlights what you need to change):

## Summary

For those as interested as the OP in understanding Spice as it applies to all versions present in the world today, "The Spice Book," by Andrei Vladimirescu is very helpful. Also this very important thesis paper is a must-have (and it's free now): Spice2: A Computer Program to Simulate Semiconductor Circuits.

• Comments are not for extended discussion; this conversation has been moved to chat. Any conclusions reached should be edited back into the question and/or any answer(s). Dec 15 '19 at 14:08
• @Dave Thanks for cleaning this up. I mean it this time.
– jonk
Dec 15 '19 at 15:01
• Nice solution! I read from the help file: To invoke parameter substitution and expression evaluation, enclose the expression in curly braces. The enclosed expression will be replaced with the floating-point value. That's reason text won't work Dec 15 '19 at 21:39
• @Huisman Thanks for the kind comment. Spice is a tool and the better one understands the nuances of the tool, the more useful it becomes. For example, using the above technique you can set up min and max boundary conditions for all of the devices of interest and set up every single permutation of them (or every permutation of interest) to see how it affects the range of the quiescent DC operating point of a circuit, and which affect it more or less so. And without having to do dozens of runs and write down notes. Only two .STEP cards are typically useful. So this gets around that problem.
– jonk
Dec 15 '19 at 22:36

If you are using models (not subcircuits), the best method is to use ako. If you are using a subcircuit, then you might be able to use numbers as their names, then change them with a .step.

The reason I say might, is because the subcircuits need to be similar, since prior to simulation the whole netlist is flattened, and the subcircuits need to behave similarly in order to be able to be stepped.

Here is a small example:

Q1 is the symbol for an NPN transistor, but it's used as a subcircuit (the prefix is x, instead of QN). Its name is changed to be a variable, x, evaluated by the curly braces.

The .step command steps between either 1 and 2, or 1 and 3, where 1, 2, and 3 are the subcircuits to the right. 1 is a basic transistor (one element), modified to be a subcircuit, 2 is some 1st order lowpass filter (two elements), and 3 is a resistive divider (also two elements).

Stepping between 1 and 3 will work, stepping between 1 and 2 won't. It will also fail for 2 and 3. Anywhere 2 needs to be stepped together with any other, the simulation will fail with Invalid .stepped circuit! error. Why? I can't be sure, but it should be related to the way the subcircuits are expanded into memory. Maybe due to the fact that, internally, there are too many pins (the VCCS has 4)? I am only speculating, but this should give you an idea how to use it and what you might want to avoid.

Forgot to add that recently there is an additional SPICE directive, .text (see the manual at LTspice > Dot Commands > .TEXT), but which doesn't allow stepping subcircuits or models with strings as names.

• The OP is looking to step opamp types, I think. And yes, .subckt can be stepped, so long as it has a numeric name (and matches up, pin-wise, of course.) Unfortunately, LTspice doesn't support ako for .subckt, so you can't ako an LT1800 for example.
– jonk
Dec 14 '19 at 20:16
• @jonk Yes, that's why I added (not subcircuits) within parentheses. Maybe I should have rephrased that, but now your answer greatly supersedes mine. :-) Dec 18 '19 at 15:48