• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Mixed-Signal Design
  3. Spice to Spectre conversion

Stats

  • Locked Locked
  • Replies 17
  • Subscribers 64
  • Views 18557
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Spice to Spectre conversion

sram17
sram17 over 4 years ago

Hi Experts - I'm a novice trying to convert a subcircuit from HSPICE to Spectre. I am not sure how Spectre refers to node voltages or uses user-defined functions. Could you please let me know if this conversion is valid? Help is very much appreciated!

Thanks,

Shriram

SPICE:

.SUBCKT dom n1 n2 p1

.param alpha = 'a1'

* user-defined function

.param f1(x,y) = '0.5* alpha*x*y

*current source is function of Voltage at p1 and Voltage difference across n1 and n2

G_p1 0 p1 CUR = '-f1(V(p1),2) - V(n1,n2)'

.ENDS dom 

Spectre:

subckt dom (n1 n2 p1)

parameters alpha = a1

// user-defined function; need to pass alpha as a variable (different from SPICE)

real f1(real x, real y, real alpha) {

return 0.5*alpha*x*y

}

// Is this a valid way to define the current source using node voltages and user-defined function in Spectre?

G_p1 0 p1 bsource i=-f1(v(p1),2,alpha)-v(n1,n2)

ends dom

  • Cancel
  • ShawnLogan
    ShawnLogan over 4 years ago

    Dear Shriram,

    sram17 said:
    // Is this a valid way to define the current source using node voltages and user-defined function in Spectre?

    Did you happen to check the spectre manual or the On-line support partal? If not, the following document details the syntax and scope of user defined functions:

    https://support.cadence.com/apex/techpubDocViewerPage?xmlName=spectreref.xml&title=Spectre%20Circuit%20Simulator%20Reference%20--%20Other%20Simulation%20Topics%20-%20User%20Defined%20Functions%20(functions)&hash=pgfId-1068879&c_version=20.1&path=spectreref/spectreref20.1/chap4.html#pgfId-1068879

    Otherwise, from the UNIX prompt, type:

    spectre -h expressions

    and

    spectre -h bsource

    The short answer is your syntax does not conform with that required by spectre. spectre uses parenthesis to enclose node names. As an example from the spectre -h output,

    Voltage-controlled current source
             vsrc (n1 n2) resistor r=100k
             vccs1 (n3 n4) bsource i=v(n1,n2)/2000.0

    I hope this provides enough information and I understood your questions Shriram!

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sram17
    sram17 over 4 years ago in reply to ShawnLogan

    Thanks a lot, Shawn! I noticed the paranthesis, however, ADE somehow did not throw up a syntax error when I saved the Spectre file without paranthesis, so I assumed they were optional.

    It is still not clear to me based on the examples if I am allowed to send a node voltage as a variable to a user-defined function in bsource and have the sub-circuit behave as it does in SPICE.

    Are you suggesting that it is correct?

    Thanks again,

    Shriram

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 4 years ago in reply to sram17

    Dear Shriram,

    sram17 said:
    It is still not clear to me based on the examples if I am allowed to send a node voltage as a variable to a user-defined function in bsource and have the sub-circuit behave as it does in SPICE.

    Perhaps I am not understanding your question correctly and I apologize if I am not!

    However, in the example I provided, v(n1,n2) represents the voltages between circuit nodes n1 and n2 and is used in the bsource  function v(n1,n2)/2000.0 as its current. Are you suggesting defining the voltage v(n1,n2) as a separate distinct variable? In lieu of that, perhaps you can just define a voltage net in your circuit, say vdelta, as the difference between node voltages n1 and n2, and then use voltage vdelta in your expression, for example i=v(vdelta)/2000.0.

    Did I manage to understand your comment?

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sram17
    sram17 over 4 years ago in reply to ShawnLogan

    Hi Shawn - I think we are converging on the same item. I have reduced the complexity of my dependent current source for the purpose of the forum posting. My current source is a somewhat complicated function of not only the voltage difference v(n1,n2), but also a node voltage v(p1). I have tried to express that as f1(v(p1)), with a user-defined function. I was trying to understand if this is a valid way to define a complicated functional relationship in Spectre for a dependent-current source. Hope my question is clear.

    Thanks again for your time and comments!

    Shriram

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sram17
    sram17 over 4 years ago in reply to sram17

    Sorry, maybe I messed up and wrote f1(v(p1)) when clearly f1 has 3 variables. So, the correct expression should have been:

    G_p1 0 p1 bsource i=-f1(v(p1), 2, alpha)-v(n1,n2)

    where x=v(p1) and y=2

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sram17
    sram17 over 4 years ago in reply to sram17

    I fixed the expressions in the original post. Sorry about the confusion!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 4 years ago in reply to sram17

    Dear Shiram,

    sram17 said:
    My current source is a somewhat complicated function of not only the voltage difference v(n1,n2), but also a node voltage v(p1). I have tried to express that as f1(v(p1)), with a user-defined function. I was trying to understand if this is a valid way to define a complicated functional relationship in Spectre for a dependent-current source. Hope my question is clear.

    Did you examine the examples when you type spectre -h expressions at the UNIX command line? If you examined it, it suggest you type spectre -h function for additional information on calling your own functions in expressions. Typing this at the UNIX prompt yiedls:

    "$ spectre -h functions

    **********************
    User Defined Functions
    **********************

    Spectre's user-defined function capability allows you to build upon the provided set of built-in mathematical and trigonometric functions. You can write
    your own functions, and call these functions from within any expression. The syntax for calling a user-defined function is the same as the syntax for
    calling a built-in algebraic or trigonometric function. Note that user-defined functions must be defined before they are referenced (called). Arguments
    to user-defined functions will be taken as real values, and the functions will return real values. A user-defined function may contain only a single
    statement in braces and this statement must return an expression (which will typically be an expression involving the function arguments). The return
    expression may reference the built in parameters `temp' and `tnom'. User-defined functions must be declared at the top level only, and must not be
    declared within subcircuits. User-defined functions may be called from anywhere that an expressions can be currently used in Spectre. User-defined
    functions may call other functions (both user-defined and built-in), however any user-defined function will need to be declared before it can be called.
    User-defined functions can override built-in mathematical and trigonometric functions.
    NOTE: Only real values for arguments and return values are supported in this release.
    See `spectre -h expressions' for a list of built-in algebraic and trigonometric functions

    Synopsis:
    real myfunc( [real arg1, ...real argn] ) {
       return <expr of arg1..argn>
    }


    Examples:


    real myfunc( real a, real b ) {
        return a+b*2+sqrt(a*sin(b));
    }

    An example of a function calling a previously defined function follows

    real yourfunc( real a, real b ) {
        return a+b*myfunc(a,b);     // call "myfunc"
    }

    The final example shows how a user-defined function may be called from an expression in the Spectre netlist:

    r1 (1 0) resistor r=myfunc(2.0, 4.5)"

    Does this help?

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sram17
    sram17 over 4 years ago in reply to ShawnLogan

    Hi Shawn - I read all that already. There are a few suspicious things. First, it says one cannot define functions inside sub-circuits, which kind of seems quite problematic, since we work at different levels of abstraction and a subcircuit allows one that flexibility. None of the examples use node voltages as inputs to user functions. 

    My question can be stated as below:

    Can one use node-voltages as inputs to a user-defined function for the purposes of defining a controlled current source inside a sub-circuit in Spectre?

    Thanks,

    Shriram

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 4 years ago in reply to sram17

    Dear Shihram,

    I think you may have overlooked a statement in the help articles I suggested....you added an additional constraint that I either overlooked or you did not include when you noted concerning a subcircuit...:

    sram17 said:
    Can one use node-voltages as inputs to a user-defined function for the purposes of defining a controlled current source inside a sub-circuit in Spectre?

    From the help article:

    "User-defined functions must be  declared within subcircuits."

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sram17
    sram17 over 4 years ago in reply to ShawnLogan

    Hi Shawn - not sure where that is. This is what I see:

    User-defined functions must be declared at the top level only, and must not be
    declared within subcircuits. 

    Also, do you have any idea about whether one can pass a node voltage as an argument?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
>

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information