# Parameterizing diode value in SPICE

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


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

And here is the output:

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:

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:

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:

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:

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