2
\$\begingroup\$

I'm in the process of modelling a buck converter following the approach in Sam Ben-Yaakov's A unified SPICE compatible average model of PWM converters article in which he models a switched inductor using behavioural current sources (PDF link,) but I am running in to trouble when I try and make the switched inductor an LTspice sub-circuit.

Here is a toy example that produces the same error.

BI example

There is an independent voltage source V1 and a dependent behavioural current source B1, the current through B1 is related to the V1 by a simple expression.

If I now take B1 and make it into a sub-circuit I get the error

"Unknown circuit node "u1:in" requested in behavioural source"

It's obvious that the sub-circuit cannot access the node outside of it's self.

How can I give the subcircuit access to this voltage? It's not a parameter (in the usual sense) and it is not a node. Is there a way to pass the voltage in?

enter image description here I

\$\endgroup\$
3
  • 1
    \$\begingroup\$ If you want to model switching converters, I recommend you consider the PWM switch model forged by Vatché Vorpérian in 1986. It is described in my APEC 2013 seminar and later declined in many different subcircuits, operating in various modes (voltage- and current-mode control, fixed or variable frequency etc.). \$\endgroup\$ Commented Jun 15, 2023 at 20:07
  • \$\begingroup\$ Thanks! I will take a look. One of the nice things about Sam’s approach is that it works for buck, boost, buck-boost and automatically transitions between DCM and CCM. But I’m just finding my feet, so there may well be something out there that is a better fit. \$\endgroup\$ Commented Jun 15, 2023 at 20:47
  • 2
    \$\begingroup\$ The models I have published in my book do transition automatically between the modes and predict sub-harmonic oscillations for the current-mode case. You could also consider SIMPLIS simulations which can extract ac response from a switching circuit. See my free ready-made templates to know more about this approach. \$\endgroup\$ Commented Jun 16, 2023 at 5:32

1 Answer 1

2
\$\begingroup\$

Traditionally, a SPICE subcircuit only understands the nodes defined within it and also any nodes explicitly attached to it. Therefore, in your test circuit you would typically need at least a 3rd port on your subcircuit to pass the IN node so the subcircuit can see it, like shown below. NOTE: I used an existing 4-port symbol so I didn't have to create a custom symbol.

enter image description here


If you're familiar with software, you can think of the subcircuit like a function where it can only see the parameters explicitly passed to it. Also in software, you can go around this passing of parameters by using variables with global scope. Fortunately, LTspice offers something similar. The built-in LTspice help says that nodes starting with $G_ will have global scope. So, you can also change your circuit to look like the following to achieve that.

enter image description here

\$\endgroup\$

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