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

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. – Brian Dohler 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

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
• 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. – Tox Aug 1 '16 at 9:42

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