Post Go back to editing

If statement for a value

Category: Software
Product Number: LTSpice
Software Version: XVII

I'm trying to create a model of an analogue switch, I'm sure that one already exists but this is to be used in a more complex model.
I have tried to modify some code from an existing model but I get an error that states "can't find definition of model 'Value". What am I missing?

.subckt TestR N1 N2 POS NEG
R1 N1 N2 value={ if( V(POS) > 2.5 , 0.01, 1000meg ) }
R2 POS NEG 1000meg
.ends

Parents
  • Hello there,

    I don't believe you can use an IF statement within the subcircuit model.

    What you can do is to define a switch, with on and off resistances.

    Take a look at ADG.lib in your LTspice /lib/sub directory for inspiration.

    We do have subcircuit models for a large number of our analogue switches, so be sure to do a sync release and check to see if the analogue switch model you require isn't already there, so you don't need to reinvent the wheel.

    Happy simulations!

    Best regards,

    Martin.

  • The analogue switch will be part of a more complex model, I'm not looking for an individual switch.
    I don't know why I didn't think to look at one of the switch models. I don't appear to have an adg library but I have now downloaded the adg601 model which is not encrypted. It has a number of if statements but they all appear to have the same format that I am using, maybe it can't be done with a standard part like a resistor.

  • Yes, I understand.  Most analogue switch models use a number of switch assignments to model the behaviour.  As an example of a more complex model in ADG.lib, please see this fragment:

    .subckt ADG5248F 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    C2 3 14 63p
    C5 13 14 63p
    S1 N046 13 14 N042 TN
    S2 3 N046 N042 14 BN
    S3 13 N049 N042 14 TP
    S4 N049 3 14 N042 BP

    ...

    .model N VDMOS(Kp=2m Vto= .5 Is=0 mtriode=1 Cgs=.049p Ksubthres=.4 nlev=3 gdsnoi=2)
    .model P VDMOS(Kp=2m Vto=-.5 pchan Is=0 mtriode=1 Cgs=.049p Ksubthres=.4 nlev=3 gdsnoi=2)
    .model TN SW(Ron=500 Roff=1G Vt=-.4 Vh=-.1)
    .model BN SW(Ron=500 Roff=1G Vt=.6 Vh=-.1)
    .model TP SW(Ron=500 Roff=1G Vt=.6 Vh=-.1)
    .model BP SW(Ron=500 Roff=1G Vt=-.4 Vh=-.1)
    .model ESD D(Ron=1 Roff=1G epsilon=1)
    .model OR D(Ron=1 Roff=1G epsilon=.25)
    .model OUT SW(Ron=150 Roff=10Meg Vt=.5 Vh=-.4)
    .model 3V VDMOS(Kp=200m Vto=-3 Ksubthres=.1)
    .model 20�A SW(Ron=20K Roff=10T Vt=.5 Vh=-10m Ilimit=20u level=2)
    .model DC SW(Ron=190 Roff=1G Vt=-.5 Vh=-.4)
    .ends ADG5248F
    *

    Where switches TN, BN, TP and NP are the top and bottom N- and P-Channel FETs.

    ADG.lib should be found in C:\Users\...\Documents\LTspiceXVII\lib\sub

    I hope that helps.

Reply
  • Yes, I understand.  Most analogue switch models use a number of switch assignments to model the behaviour.  As an example of a more complex model in ADG.lib, please see this fragment:

    .subckt ADG5248F 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    C2 3 14 63p
    C5 13 14 63p
    S1 N046 13 14 N042 TN
    S2 3 N046 N042 14 BN
    S3 13 N049 N042 14 TP
    S4 N049 3 14 N042 BP

    ...

    .model N VDMOS(Kp=2m Vto= .5 Is=0 mtriode=1 Cgs=.049p Ksubthres=.4 nlev=3 gdsnoi=2)
    .model P VDMOS(Kp=2m Vto=-.5 pchan Is=0 mtriode=1 Cgs=.049p Ksubthres=.4 nlev=3 gdsnoi=2)
    .model TN SW(Ron=500 Roff=1G Vt=-.4 Vh=-.1)
    .model BN SW(Ron=500 Roff=1G Vt=.6 Vh=-.1)
    .model TP SW(Ron=500 Roff=1G Vt=.6 Vh=-.1)
    .model BP SW(Ron=500 Roff=1G Vt=-.4 Vh=-.1)
    .model ESD D(Ron=1 Roff=1G epsilon=1)
    .model OR D(Ron=1 Roff=1G epsilon=.25)
    .model OUT SW(Ron=150 Roff=10Meg Vt=.5 Vh=-.4)
    .model 3V VDMOS(Kp=200m Vto=-3 Ksubthres=.1)
    .model 20�A SW(Ron=20K Roff=10T Vt=.5 Vh=-10m Ilimit=20u level=2)
    .model DC SW(Ron=190 Roff=1G Vt=-.5 Vh=-.4)
    .ends ADG5248F
    *

    Where switches TN, BN, TP and NP are the top and bottom N- and P-Channel FETs.

    ADG.lib should be found in C:\Users\...\Documents\LTspiceXVII\lib\sub

    I hope that helps.

Children
No Data