Super simple question here. Is it possible to use an if statement in a .param LTSpice directive? If so, what is the syntax? Shown below does not function.

enter image description here

Note that the .step function can not be used for my purposes, to the best of my knowledge, because I want to simulate a step response over time.


From what I understand, the .PARAM directive is evaluated at startup. The answer to your literal question is thus no.

You can, however, put the equation as the resistance:

enter image description here

  • \$\begingroup\$ Thanks @pipe. This is the answer I feared. What if I'm evaluating eight other parameters based on my first? I'm actually trying to simulate the step response from a brushless DC motor, and only used this simple example to illustrate my question. I suppose I could calculate the results outside of LTSpice and put if statements in the model where appropriate. \$\endgroup\$ – Brian Dohler Jul 22 '16 at 14:54
  • \$\begingroup\$ @BrianDohler Yeah, can't help with that I'm afraid, I hope you find a solution. It would be useful. \$\endgroup\$ – pipe Jul 22 '16 at 23:53

You can, put it in curly braces like so: .param R = {if(time>0.5,1,2)} and set the value of R1 to {R}.

You can also make more complex statements like this:

.param MODE 1 .param FREQ {if(MODE == 0, 1000, if(MODE == 1, 500, if(MODE == 2,250)))}.

This will select a FREQ based on the given MODE.

  • 1
    \$\begingroup\$ Did you try it? This does not work in my LTspice, but perhaps it's a new feature. I have't upgraded in a year. \$\endgroup\$ – pipe Jul 31 '16 at 8:46
  • \$\begingroup\$ I used it in LTSpice IV and LTSpice XVII to simulate a function generator. My voltage source is controlled like this: PULSE({Vinitial} {Von} [...] {Tperiod}) where each parameter is defined in a block of .params, like this: .param Vinitial = {if(MODE==2, 0, 1)}. What might be important is that .params in one text block are processed top to bottom, i.e. MODE needs to be defined before Vinitial. \$\endgroup\$ – Tox Jul 31 '16 at 12:33
  • \$\begingroup\$ Here's the schematic. \$\endgroup\$ – Tox Jul 31 '16 at 12:41
  • \$\begingroup\$ But you don't use IF(time>0.5,1,2) anywhere. time is a special variable, and the problem here is that time is not evaluated in a .PARAM statement. OP wants to have a time-dependent resistance without embedding it into the actual resistor. \$\endgroup\$ – pipe Jul 31 '16 at 14:24
  • \$\begingroup\$ Oh darn, I've expected that time will be parsed. Hmm, I guess not because it constantly changes but parameters are only evaluated once at the beginning of the simulation. I don't think it'll work but might be worth a try: store time in a parameter (.param T time) and then use T rather than time. \$\endgroup\$ – Tox Aug 1 '16 at 9:42



from 0 to t1 R value = R1; from t1 to t2 R changes lineally from R1 to R2, then R value will remain equal to R2 till the end


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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