Electrical – LTspice .param variable component selection

ltspice

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:

enter image description here

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.

Best Answer

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):

enter image description here

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:

enter image description here

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.

enter image description here

And here's the results of that run:

enter image description here

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:

enter image description here

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

enter image description here

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.