0
\$\begingroup\$

This LTspice model

LTspcie circuit diagram

produces this netlist:

V2 N001 0 AC 1
R6 out1 0 10k
R32 N003 out1 50k
R31 N002 out1 50k
R1 N003 N001 R1
R2 N002 0 R2
C1 N003 0 C1
C2 N002 N001 C2
.ac oct 100 60 6000
.param R1=39k R2=47k C1=22n C2=10n
.backanno
.end

But produces these errors:

Error on line 6 : r1 n003 n001 r1
     Unable to find definition of model "r1"
Error on line 7 : r2 n002 0 r2
     Unable to find definition of model "r2"
Error on line 8 : c1 n003 0 c1
     Unable to find definition of model "c1"
Error on line 9 : c2 n002 n001 c2
     Unable to find definition of model "c2"
Fatal Error: Missing capacitance value for "C2"

Does anyone know:

  • Why can it not find the capacitance value for "C2"?
  • And what so the errors Unable to find definition of model "r1" mean.

Thanks

\$\endgroup\$
4
  • \$\begingroup\$ What you mean with "R1 N003 N001 R1" Resistor R1 sits between N003 and N004 and has value R1. What LTSpice reads: R1 sits between N003 and N004 and is a component with a model called "R1" You didn't define a model named R1 so it complains. I guess you have to look up the exact syntax that is needed to use parameter values for resistors etc. \$\endgroup\$ Commented Sep 8, 2020 at 10:41
  • 2
    \$\begingroup\$ Use {R1} for your R1 resistor. Follow similarly for the rest of your schematic. In the unique case of resistors, you can also use R=R1, for example. But I don't think that works for capacitors. \$\endgroup\$
    – jonk
    Commented Sep 8, 2020 at 10:49
  • \$\begingroup\$ @jonk You are absolutely right. Thanks for that. Can you post this as an answer, then I can accept it. \$\endgroup\$
    – Christian
    Commented Sep 8, 2020 at 11:58
  • \$\begingroup\$ @Christian Added, as requested. \$\endgroup\$
    – jonk
    Commented Sep 8, 2020 at 12:23

1 Answer 1

3
\$\begingroup\$

In LTspice, expressions are wrapped with braces: {}. Almost always, anyway. (I'm never 100% sure in any given situation. There seem to be various places where the parsing is a little bit different for one reason or another.)

In the case of resistors, you are allowed to use R=<expr> without using R={<expr>}. No, I don't know why. But I have noticed that with other sources you can sometimes use V=<expr> or I=<expr>, too. So if you are fond of these kinds of writing styles, you'll have to experiment. Usually, though, the braces are the way to go as your first attempt. Usually, it works.

There are lots of other details you'll need to learn to help parameterize schematics. (If I had time tonight, I might list a few of them. But for now, I guess the above will do.) Just be on the watch for them. Use the included help, also. It's not perfect and there is much one could wish was added to it. But it's a start and often enough I can figure things out by reading through it. In the few cases where I cannot, I then resort to web searches and/or experimentation.

The netlist is also of some help. Sometimes you can see something there that just looks "impossible to parse right." If you see something like that, you are probably right and this is why it's not working. (Spaces in named nodes, for example, would make it impossible to parse because spaces are used to separate keywords on the Spice line and so it would certainly confuse things. That's just an example to help make the broader point.)

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Everything after = for behavioural expressions is understood as evaluation; they don't need curly braces. They differ from Laplace (for ex.), which can be written both as Laplace=expr and Laplace expr. So a Laplace is not a behavioural expression, it's more a function of s (my understanding). It evaluates .param (s/(s+a)), but .func need {} (s/(s+{f(a)}). While simple values (RLC, or passive sources) are meant to have their values as literal numbers, and C1` is not a number. But if it is defined as a parameter, then curly braces (or single quotes) force evaluation. \$\endgroup\$ Commented Sep 8, 2020 at 14:03
  • 1
    \$\begingroup\$ @aconcernedcitizen Thanks for that expansion. It helps me. \$\endgroup\$
    – jonk
    Commented Sep 8, 2020 at 14:04
  • 1
    \$\begingroup\$ There are exceptions to behavioural expressions in Flux= and Q=, where they're also a function of x, and so they behave similar to Laplace where a .param is evaluated normally, but a .func needs {} (e.g. Flux=pi*x*{f(a)}, or Q=e*x*{f(1)}). Hope it helps. \$\endgroup\$ Commented Sep 8, 2020 at 14:07
  • 1
    \$\begingroup\$ @aconcernedcitizen Of course it helps. I had a more vague understanding before. I could get by, of course. Never found a problem I couldn't find out how to solve. But there seemed to always be something that would catch me and I'd have to regroup and try again. Every little bit helps! \$\endgroup\$
    – jonk
    Commented Sep 8, 2020 at 14:11
  • 1
    \$\begingroup\$ Maybe that was a case where you had an expression like this: Flux={ a * x * { f(1) } }. In this case, the braces encompassing the whole expression are useless. My interpretation is that x is a time-variable, and so it does not accept evaluation, so the parser seems to interpret any curly braces that encompass x as regular braces (see the expanded netlist for the above and for a * {x} * {f(1)} , for example). Which means f(1) ends up without any braces, so it looks like you have to add a second pair, just for it. But only one pair of braces will have the desired effect. \$\endgroup\$ Commented Sep 8, 2020 at 14:21

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.