2
\$\begingroup\$

I have a bunch of diodes of the same type on a schematic in LTSpice. How do I parameterize the diode's type (Value) so that I can change it in one place and it would change it for them all?

The .PARAM statement doesn't seem to be supporting literals, so I cannot use something like

.PARAM DiodeValue=NSPW500BS
\$\endgroup\$
2
\$\begingroup\$

There is a workaround using the .SUBCKT dot command. Here is an example circuit:

enter image description here

And here is the output: enter image description here

In short you should create a subcircuit with two terminals whose only internal component is the diode you want.

The SPICE code:

.subckt MyDiode A K
D A K 1N4148
.ends

defines a subcircuit called MyDiode with two terminals named A and K (these names are local to the subcircuit definition). .ends ends the definition. The code inbetween is regular SPICE code which says that a diode D is placed between (local) nodes A and K and that diode has a 1N4148 SPICE model.

The .lib standard.dio is required to load the models (1N4148) used inside the subcircuit. If the models of the diodes you want to use are not in the standard LTspice part libraries you must put the complete path in the .lib directive (see LTspice guide for details).

Note that you have to change the default attributes of the diodes you usually place on the schematic, as shown in this image:

enter image description here

Note that the Prefix must be changed from D to X (to tell LTspice the part is a subcircuit and not a standard diode) and the Value attribute must be the name of the subcircuit (here MyDiode).

From now on, if you want to change the "implementation" of MyDiode parts, it is sufficient to change the subcircuit definition, as you can see in the image below, where I changed it to use an 1N4007 model:

enter image description here

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Since I discovered a relevant undocumented feature of LTspice, I post this new, possibly better, answer.

Disclaimer: this was an edit to another answer I posted in this thread before. Since then I discovered the accepted practice on SE sites is to post additional answers if they are logically independent (see this Meta.EE.SE question).

It turns out that a simpler method exists, thanks to an undocumented feature of LTspice I recently discovered. The .model directive allows a format where you can specify that the model you are defining is A Kind Of some other model (AKO):

.model MyDiode AKO: 1N4007

Therefore the previous simulation setup can be simplified in this way:

enter image description here

In this case you don't need to change the advanced attributes of the diodes as before. You only need to specify MyDiode as the value of the part:

enter image description here

That feature is documented here in LTspice Yahoo group WIKI and allows a couple other tricks, such as changing some parameters of the existing model, or defining a model with a purely numeric name, which allows using it in a .step directive to step through different models (all having custom numeric model names).

| improve this answer | |
\$\endgroup\$

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.