4
\$\begingroup\$

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!

\$\endgroup\$
3
  • \$\begingroup\$ See this answer and comments. \$\endgroup\$ Jul 23, 2018 at 12:33
  • \$\begingroup\$ I read through the thread, but i don't see a reference to my problem... If i understood correctly, the main concern in that thread is how to reference a current inside the model, instead i have all the quantities available, i just want to be able to pass the component name (not a pin, the whole subcircuit) to the function. Or are you suggesting that i can't do this because it implies parsing a current inside the subcircuit? \$\endgroup\$ Jul 23, 2018 at 13:32
  • \$\begingroup\$ Because of the parsing, yes, though I'd be glad if I can be proven wrong on this one. \$\endgroup\$ Jul 23, 2018 at 15:46

2 Answers 2

1
\$\begingroup\$

Apparently it works with both voltages and currents, but the format of the definition is different, that's what I have missed:

.func Vx()=V(X1:Vo)/V(X1:Vin)

And when you want to plot it, simply call Vx(). It actually works for currents into/out of pins, too, then it's Ix(X1,R1), for example, but notice that the designator must include the number, too, i.e. X1, not simply X. Also, the node will be the symbol's pin, not the subcircuit's definition. E.g. if you have .subckt xxx 1 2, but the symbol has the pins named A and B, then the current should be Ix(U1:A), not Ix(U1:1)

For this to work you must have checked one, or both options, in Control Panel > Save Defaults > Save subcircuit [...].

The bad assumption (mea culpa) I made in the comments was about the parsing, but that is no longer relevant since plotting is after the simulation, the plot.defs file is only needed afterwards.

\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ Ok thanks, i was afraid of this.... So i could just put in my subcircuit a ".func A() ..... " and attach a behavioral source that implements the function, then plot the voltage at the output of this source? \$\endgroup\$ Jul 23, 2018 at 16:01
  • \$\begingroup\$ Yep, just like in the picture. However, if your trying to reference a pin current see the edit. meta.stackexchange.com/questions/126180/… \$\endgroup\$
    – Voltage Spike
    Jul 23, 2018 at 16:11
  • \$\begingroup\$ Oh, another thing use the limit function if you using a divide like A/B, because the values can quickly become very large as B approaches zero (or infinite) if you limit the output of the b source to like ±100k it can be more suitable for graphing I think the function would be b=limit(input,-100k,100k) \$\endgroup\$
    – Voltage Spike
    Jul 23, 2018 at 16:15
  • \$\begingroup\$ Thanks a lot! Now by knowing this, i will post a new question in a separate topic about GFT. \$\endgroup\$ Jul 24, 2018 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.