If function error in LTSpice

Thread Starter

DavidCccc

Joined Sep 5, 2017
2
Hi I am trying to simulate a simple subcircuit model in LTSpice but I get an if function error which says
"Syntax error: function if(): requires exactly three segments"

These are the if arguments in the subcircuit code

* Function G(V(t)) - Describes the device threshold
.func G(V) = IF(V<=Vp, IF(V>=-Vn, 0, -An*(exp(-V)-exp(Vn))), Ap*(exp(V)-exp(Vp)))

* Function F(V(t),x(t)) - Describes the SV motion
.func F(V1,V2) = IF(eta*V1>=0,IF(V2>=xp,exp(-alphap*(V2-xp))*wp(V2),1),IF(V2<=(1-xn),exp(alphan*(V2+xn-1))*wn(V2),1))

Based on the IF function { IF(a, then b, else c)} both of these functions have 3 segments for each of their IF components. Is there something I'm missing out?
I have attached screenshots of the error and the IF function segments of the code for reference.
 

Attachments

eetech00

Joined Jun 8, 2013
3,961
Hi

Here's the format for a nested If statement:

* Define Param
.param C = 1

* Define function
.func Z (A,B) {If (C<1,If(A>B,1,0),10)}

* Call function and hold result in X (this can also be a B device to output on waveform viewer)
.param X = Z(1,2)

* show result in log file
.meas Result param X
 

Thread Starter

DavidCccc

Joined Sep 5, 2017
2
Thanks for your replies guys. It was the nested if issue and I got ltspice to play nice by following eetech's template.
 
Top