• 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 18615
  • 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
Parents
  • 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
  • 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
  • ShawnLogan
    ShawnLogan over 4 years ago in reply to sram17

    Dear Shisram,

    sram17 said:

    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. 

    it appears my copy and paste was missing some text and hence in error. The statement from the help article is shown bewow in bold text.

    $ 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)


    $

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

    Please read the documentation I suggested. I do not have any more time now.

    Shawn

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

    I had read it even prior to posting in the forum.

    Thanks for your comments, but my question remains unresolved.

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

    I am struggling to understand what is being asked here. First of all, there's no need to convert the SPICE model into Spectre syntax - you can use it directly in spectre (other than the fact that there was a missing close quotation mark at the end of the line):

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

    If you really do want to write in spectre syntax, there's also no need to pass  alpha  into the function since  alpha  is in scope within the subckt. So it's fine to use:

    real f1(real x, real y) {   return 0.5*alpha*x*y }

    I don't really understand what you're saying here about passing a node voltage to the function. You're already doing that, aren't you?

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

    (I added the parentheses around the connections for the bsource to make it easier to read, although spectre will tolerate them being missing).

    Andrew

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

    Andrew - thanks for your response. 

    My question was quite straight-forward. It was whether the Spectre equivalent code I had written was correct. Not sure what was not clear about it. My reading of the Spectre examples in the Help did not suggest that one could pass node voltages as arguments to a function. Also, there was some wording about not having user-functions declared inside subcircuits. So, I was trying to get clarification.

    To your point about not having to convert SPICE to Spectre, I agree. I was able to run a simulation with the SPICE subcircuit. But, when I tried to run Monte Carlo variation, I noticed that the parameters in the SPICE subcircuit were only being varied at the process level (once per MC point) and not at mismatch level (for every instance in my circuit). In trying to debug why, I decided to convert my SPICE subcircuit to the native Spectre and see if that somehow solves the issue.

    Thanks!

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

    Your original question was clear - I had no problem with that. The bit I didn't understand was your question later on at various points:

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

    Mainly because a quick test shows that it works (which I assumed you would have tried - that's what I did). Anyway, hope it's all clear now.

    Andrew

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

    Your original question was clear - I had no problem with that. The bit I didn't understand was your question later on at various points:

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

    Mainly because a quick test shows that it works (which I assumed you would have tried - that's what I did). Anyway, hope it's all clear now.

    Andrew

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

    Thanks, Andrew. Yes, it is all clear!

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

    Btw, Andrew, based on your response to another question in this thread (https://community.cadence.com/cadence_technology_forums/f/custom-ic-design/34599/monte-carlo-simulation-for-device-mismatch), I was able to solve my mismatch issue as well. So, thanks for that!

    • 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