# ltspice .param if statement

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. 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.

• If it's about using an if() inside a .param, yes, it's possible. If it's about using the keyword time inside a .param, no. As I said back then, it is possible to use a .func for that. Apr 13 at 11:25

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: • 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. Jul 22 '16 at 14:54
• @BrianDohler Yeah, can't help with that I'm afraid, I hope you find a solution. It would be useful.
– pipe
Jul 22 '16 at 23:53

For those of you coming across this question several years late, it looks like this is indeed actually possible if instead of .param you use the .func directive.

Just do .func R(t) if(t>0.5,1,2) and R = R(time). And it works! (Tested in LTSpice XVII)

• Brilliant! I’ve been using LTspice for 10 years and have never seen this before. Apr 13 at 11:50

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.

• 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.
– pipe
Jul 31 '16 at 8:46
• 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.
– Tox
Jul 31 '16 at 12:33
• Here's the schematic.
– Tox
Jul 31 '16 at 12:41
• 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.
– pipe
Jul 31 '16 at 14:24
• @Tox You can forget about using time in a .param statement. time cannot be "stored" anywhere, since it's continuously changing. It can be used in .func declarations, though, directly or indirectly. What you meant with R=function(time) only applies to behavioural resistors, and thus it's an expression to be used as is inside the Value field (of the appropiate element). Aug 4 '16 at 11:25

R=table(time,0.5,2,0.501.1)

R=table(time,t1,R1,t2,R2)

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