Electronic – LTSpice: how to pass to a function a component name as parameter

functionltspicesubcircuit

Good morning all.
I am implementing a subcircuit in LTspice, and I want also to modify the plot.defs to calculate some quantities with the voltages/currents inside the subcircuit. Thus, I will have a function like:

.func A(x) V(x:Vo)/V(x:Vin)

where the function "A" should take the instance name of the subcircuit as parameter, in order to access to its nodes (labelled Vo and Vin in the subcircuit, using a behavioral voltage source to make the node name always the same).

The syntax written above doesn't work, I get the error:

undefined symbol in: "A(<>)"

Where of course "X1" is the name given by spice to the instance of my subcircuit.
What could be the problem? Please note that by explicitly writing the expression of "A" in the plot panel, everything works fine, so it is a matter of how to pass the instance name as parameter.

Thanks all in advance!

Best Answer

There are two problems here, I couldn't get a user defined function to work in the graph. The other one is your trying to make a function that passes in a parameter, when you can only use them to pass numerical information.

The other one is you can't reference a pin current anywhere but a graph, so if your using the colons, that won't work. The way to reference a pin current is described in a few answers like this one. The short answer is if you want to reference a pin current is with a zero ohm resistor or 0V voltage source and then measuring the current (ie: for a resistor called R2, you can do this I(R2), but not this I(R2:1))

You can't use use user defined functions graphically, you can use them in b sources and other areas in the spice file. If the need arises where a function needs to be graphed, use a b-source to convert the function to data that can be graphed. Inconvenient, but that's the way it is, and is unlikely to change do to the way LT spice works.

enter image description here