IF statement on LTspice

Thread Starter

Firenze02

Joined Sep 1, 2018
47
Hi,

I would like to create a variable resistor as following:

R2=1 if i(R2)<1
R2=2 if 1<i(R2)<10
R2=3 if i(R2)>10

I know that the sintax is:

R=if(condition,valueiftrue,valueiffalse)

What about if I have three intervals?

The .asc file and the IF statement law is also shown in the attached files.

Which is the correct sintax to do that?

Thank you.
 

Attachments

Thread Starter

Firenze02

Joined Sep 1, 2018
47
HI

The statements are incomplete.

Write them in "if then else" pseudo code so we understand what you want.

eT
Dear eetech,

I would like to "translate" in LTspice the following code:

if i(R2)<1 {
R2=1
}

if i(R2)>=1 && I(R2)<=10 {
R2=2
}

else{
R2=3
}
 

eetech00

Joined Jun 8, 2013
3,859
See below.

In the .func statement, the "if" statement has to resolve to a number. I've added 0.5 at the end.
In the "Limit" statement, I've added arbitrary Min and Max values, 0.1,12, respectively. A discontinuity will occur if not used because at the start of the simulation R equals nothing (NaN). This will produce a "time step too small" error. The "Limit" statement will keep R2 equal to some value between 0.1 and 12.

eT

upload_2019-3-8_14-33-51.png
 

Thread Starter

Firenze02

Joined Sep 1, 2018
47
See below.

In the .func statement, the "if" statement has to resolve to a number. I've added 0.5 at the end.
In the "Limit" statement, I've added arbitrary Min and Max values, 0.1,12, respectively. A discontinuity will occur if not used because at the start of the simulation R equals nothing (NaN). This will produce a "time step too small" error. The "Limit" statement will keep R2 equal to some value between 0.1 and 12.

eT

View attachment 171912
Thank you eetech,

Finally I was able to simulate the circuit that I wanted, but unfortunately it doesn't work.

It gives me the following message:

Analysis: Time step too small, trouble with node v4.

Please find attached the .asc file.

Can you help me?

Thank you.
 

Attachments

Top