• 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 18565
  • 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 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
  • 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