Menu

Switch resistance during transient simulation

2022-01-09
2022-09-13
  • Holger Vogt

    Holger Vogt - 2022-01-09

    To switch the resistance during transient simulation, you may use a resistor like:

    Rs 1 0 R = 'TIME > 3m ? 2k : 1k'
    
     
    👍
    1
    • Clyde

      Clyde - 2022-01-13

      Holger, thanks for sharing. This is a slick trick.

       
    • Abd AlHaleem

      Abd AlHaleem - 2022-03-24

      didn't understand the part "2k : 1k" , what does it mean?

       
      • marcel hendrix

        marcel hendrix - 2022-03-24

        "x ? y : z" is C-like syntax for "if(x) y; else z;" or SPICE-like IF(x,y,z). It works in places where NGSPICE expects an expression.

         
  • Nathan Speer

    Nathan Speer - 2022-08-17

    This notation is called the 'ternary operator.' It's sometimes used in C/C++ and supported in most other popular languages (I know Julia also uses it, for example). It's mostly a shorthand notation for an if-else statement, with the one difference that it returns a value.

    The statement

    x = a ? b : c

    assigns the value b to x if condition a is true, else value c is assigned to x. It's equivalent to

    int x;
    if(a)
    {
    x = b;
    }
    else
    {
    x=c;
    }

     
  • dick freebird

    dick freebird - 2022-09-13

    Interesting.

    A couple of questions occur to me.

    One, how many "transitions" can be had? Just one, "before, after"? Could "TIME" be the argument to a more complex resistor-value expression, and get an "arbitrary resistance time profile"?

    Two, is the transition "smoothed" or "sharp" when you hit the timepoint in the example? Thinking about transient solution troubles.

     

    Last edit: dick freebird 2022-09-13
    • marcel hendrix

      marcel hendrix - 2022-09-13

      Could "TIME" be the argument to a more complex resistor-value expression, and
      get an "arbitrary resistance time profile"?

      Yes. Better use a TABLE then instead of a series of "IF(,,)" or ",?,:, "then.

      Two, is the transition "smoothed" or "sharp" when you hit the timepoint in the example?
      Thinking about transient solution troubles.

      With the conditional statement it is "sharp" (because that may be the point of the simulation, study a load or input disturbance). A TABLE or PWL based expression performs linear interpolation. Using POLY() lets you control an arbitrary (amount of) derivative(s).

      There are devices that are by nature discontinuous (like a switch), but at least in XSPICE these are all 'tweaked' to work with the SPICE solver.

      -marcel

       

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.