1

I want to have a bunch of .param directives to serve as test cases, one of which I will uncomment before doing a test. It allows me to make sure tests made in the past still work after making a modification, a bit like an unit test.

.param A=0 B=1 C=2
;.param A=10 B=-1 C=2
;.param A=100 B=2 C=4

One of these parameter is used on a voltage source, with value {D}. I want to assign a value of PWL(0 0 20m 5):

.param A=0 B=1 C=2 D={PWL(0 0 20m 5)}

However this doesn't work, I get a "WARNING: Cannot resolve .param A=0 B=1 C=2 D={PWL(0 0 20m 5)}" message on simulation startup.

I imagined .param as some kind of macro preprocessor so I expected it to work. Is there a way to do this?

I'm using LTspice.

JRE
  • 67,678
  • 8
  • 104
  • 179
Nicolas
  • 200
  • 1
  • 11
  • What made you think that the .param acts like a text substitution? Did you read this somewhere? – Elliot Alderson Apr 19 '22 at 18:29
  • No I just figured it would make sense. Also, according to [this answer](https://electronics.stackexchange.com/a/248891/83103) you can use `if` in a .param directive, so why not a voltage source definition? – Nicolas Apr 19 '22 at 18:36
  • 3
    @Nicolas , [a concerned citizen](https://electronics.stackexchange.com/a/308287/38098) talks about how you may achieve this. LTspice doesn't just parameterize and then re-process over and over. You cannot wrap PWL with {}. It has to be explicit. But you can bury your models into SUBCKTs and you can array a list of them and apply them. – jonk Apr 19 '22 at 18:36
  • 1
    @jonk Thanks it works great! Problem solved. – Nicolas Apr 19 '22 at 18:55
  • @Nicolas Glad to hear it! You may be able to get fancy by defining test, i, in the range from 1..N, but limit N to 99, then define source, j, in the range from 1..M, and then create a source model SUBCKT that is composed as 100*j+i. From that, you can set up a list of tests, 1...N to step through and each source, which knows their own *j* value, to select the appropriate model during test *i*. – jonk Apr 19 '22 at 19:02
  • @jonk Thank you for the reference. I realize now that I forgot to add one important bit, so it's added below the answer. – a concerned citizen Apr 19 '22 at 19:59
  • 1
    @aconcernedcitizen That seems to me to be an *important* note! You should make it part of the answer, I think. A comment can find itself beneath the notice of interested readers. – jonk Apr 19 '22 at 22:48
  • 1
    @jonk You're right, done. – a concerned citizen Apr 20 '22 at 07:55
  • @aconcernedcitizen Great! – jonk Apr 20 '22 at 08:05

0 Answers0