Menu

if condition statement in .param (PSpice models to ngpsice)

2016-11-30
2016-11-30
  • Gnrfaf Akmpss

    Gnrfaf Akmpss - 2016-11-30

    Hello everyone,

    I am trying to simulate an inverter by using the MOS devices provided by Infineon (Infineon Simulation Models).

    The provided .lib contains .SUBCKT definitions and several "levels" of modeling (3 different SUBCKT are defined for each component: BSC0925ND_highside_L0, BSC0925ND_highside_L1 and BSC0925ND_highside).

    I got the first circuit (BSC0925ND_highside_L0) working with no issue.

    The second circuit (BSC0925ND_lowside_L1) was a little more challenging:

    1.- The .param statements used a "limit" function. So I had to add the ".func LIMIT(x,a,b) {min(max(x, a), b)}" statement, as per the manual (16.13.2)

    2.- I had to replace all the "if" statements in the .param and .func definitions with equivalent logical operations.

    Before:

    .PARAM  dRd={Rd/a+if(dVth==0,limit(dR,0,1)*max(Rlim-Rd/a-Rs-Rp,0),0)}
    .FUNC  I0(Uee,p,pp,z1)  {if(Uee>pp,(Uee-c*z1)*z1,p*(pp-p)/c*exp((Uee-pp)/p))}
    

    After:

    .PARAM  dRd={Rd/a+(dVth==0)*(limit(dR,0,1)*max(Rlim-Rd/a-Rs-Rp,0))}
    .FUNC  I0(Uee,p,pp,z1)  {(Uee>pp)*((Uee-c*z1)*z1)+(Uee<=pp)*(p*(pp-p)/c*exp((Uee-pp)/p))}
    

    My question:
    Is this a known limitation? or maybe there is a syntax error (for ngspice) in the original definition that I did not see?

    After changing all the if statements the model seems to work. By this I mean I can now simulate and get no more error messages.

    Thank you for any help/guidance you can provide,
    Gnrfaf

     

    Last edit: Gnrfaf Akmpss 2016-11-30
  • marcel hendrix

    marcel hendrix - 2016-11-30

    The IF(a, b, c) can be defined as

    .func if(a,b,c) 'ternary_fcn( a , b , c )'
    

    or you can directly use ternary_fcn in the C-fashion:

    a ? b : c
    

    -marcel

    PS:

    .func LIMIT(x, y, z) {min(max(x, min(y, z)), max(z, y))}
    .func INT(x) { sign(x)*floor(abs(x)) }
    
     
    • Gnrfaf Akmpss

      Gnrfaf Akmpss - 2016-11-30

      It works!

      Thank you very much for the help.
      Gnrfaf.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.