• 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. Custom IC Design
  3. Ocean/Calculator expressions and their units

Stats

  • Locked Locked
  • Replies 12
  • Subscribers 126
  • Views 11931
  • 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

Ocean/Calculator expressions and their units

MicheleA
MicheleA over 13 years ago

Hi all,

I know it's not advised to put more than one questions per post, however I hope I'll structure this such that there won't be no confusion.

Main Topic

I am defining some expressions I would like to assess in my designs. To this end, I use the calculator in conjunction with some "ocean" script...Actually I just write expressions and define variables on a plain text file, but the idea is to expand on that with plotting functions and maybe output to file.

So let's say I have an AC sim. I then define some curves as follows:

 

twoPi = 44.0/7.0

vtank = VF("/tank_pos")-VF("/tank_neg")

itank = IF("/Vgen/MINUS")

icap = IF("/Cprobe/PLUS")

icapfix = IF("/Cfprobe/PLUS")

iind = IF("/Lprobe/PLUS")

runfreq = xval(vtank)

Ytank = itank/vtank

Zcap = vtank/icap

Zcapfix = vtank/icapfix

Zind = vtank/iind

cap = 1/(-twoPi*runfreq*imag(Zcap))

 

Now, it all works good if I copy/paste these definitions in the CIW, then ask --> plot(cap)

The issue I have with this is that now the Y-axis shows "freq" units...

cap value in femtohertz?

I observed that runfreq, defined as xval, is still correct. But if I do 1/runfreq, what I get is something with units of 1/(1/Hz), instead of s.

So probably here's where it loses it. Anyways, I see two possibilities here:

 

  1. I am doing it wrong
  2. I am doing it right

 

If 1 holds, then what's the right approach for something like this?

If 2 holds, do I have a way of "forcing" units onto expressions?

--------------------------------------------------------------------------------------------- END ----------------------------------------------------------------------------------------- 

Side Topic

 I find it more comfortable to write my expressions in the text editor rather than inputting them in the output definition box of ADE or ADE-XL. Is there a way of having the environment read my definitions as a file, and then just output the final expressions? In the (simple) case at hand, I would have defined all expressions as above, and plot them either from the CIW or directly from the file...

 

Thanks for your help!!

 Michele

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    Hi Michele,

    The units are maintained by each calculator expression working on a waveform - but it doesn't really do a reduction - it's not that smart.

    You can change the units using these functions:

    /* abSetUnits.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Oct 08, 2009 
    Modified   
    By         
    
    abSetUnits(waveform "s")
    
    sets the units on a waveform to be seconds.
    
    abRegSetUnitsSpecialFunction()
    
    registers a function in the calculator to alter the units on a 
    waveform.
    
    ***************************************************
    
    SCCS Info: @(#) abSetUnits.il 03/12/12.12:58:38 1.2
    
    */
    
    /****************************************************************
    *                                                               *
    *                    (abSetUnits wave units)                    *
    *                                                               *
    * Sets the units on a waveform, or all the members of a family. *
    * If it is just a value, pass straight through (can't set units *
    *                         on a number).                         *
    *                                                               *
    ****************************************************************/
    
    (defun abSetUnits (wave units)
      (cond 
        ((drIsWaveform wave)
         (putpropq (drGetWaveformYVec wave) units units)
         wave
         )
        ((famIsFamily wave)
         (famMap 'abSetUnits wave units)
         )
        )
      )
    
    /***************************************************************
    *                                                              *
    *                    (abCreateSetUnitsForm)                    *
    *                                                              *
    *  Set up a form for the special function on the calculator,   *
    *  which gives choices for the units. It needs to be cyclic,   *
    *   because if it's a type in field, quotes don't get added    *
    *                      around the units.                       *
    *                                                              *
    ***************************************************************/
    
    (defun abCreateSetUnitsForm ()
      (let (units)
        (setq units (ahiCreateCyclicField
                      ?name 'units
                      ?prompt "Units"
                      ?choices '("V" "A" "s" "W" "dB" "Wb" "C" "Hz")
                      ?value "V"
                      ))
        (calCreateSpecialFunctionsForm
          'abSetUnitsForm
          (list 
            (list units 0:0  180:20 140)
            )
          )
        ))
    
    /*****************************************************************
    *                                                                *
    *                 (abSetUnitsSpecialFunctionCB)                  *
    *                                                                *
    * Callback for the abSetUnits special function, which constructs *
    *           the buffer input from the form and stack.            *
    *                                                                *
    *****************************************************************/
    
    (defun abSetUnitsSpecialFunctionCB ()
      (calCreateSpecialFunction
       ?formSym 'abSetUnitsForm
       ?formInitProc 'abCreateSetUnitsForm
       ?formTitle "Set Units"
       ?formCallback 
       "(calSpecialFunctionInput 'abSetUnits '(units))"
       ))
    
    
    /***************************************************************
    *                                                              *
    *                (abRegSetUnitsSpecialFunction)                *
    *                                                              *
    *                Register the special function                 *
    *                                                              *
    ***************************************************************/
    
    (defun abRegSetUnitsSpecialFunction ()
      (calRegisterSpecialFunction
       (list "abSetUnits..." 'abSetUnitsSpecialFunctionCB))
      t
      )
     

     

    And for the x-axis:

    /* abSetXUnits.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Jul 13, 2012 
    Modified   
    By         
    
    abSetXUnits(waveform "s")
    
    sets the units on the X axis a waveform to be seconds.
    
    abRegSetXUnitsSpecialFunction()
    
    registers a function in the calculator to alter the units on a 
    waveform.
    
    This is based on abSetUnits, but does it for the X axis.
    
    ***************************************************
    
    SCCS Info: @(#) abSetXUnits.il 07/13/12.17:53:47 1.1
    
    */
    
    /****************************************************************
    *                                                               *
    *                   (abSetXUnits wave units)                    *
    *                                                               *
    * Sets the units on a waveform, or all the members of a family. *
    * If it is just a value, pass straight through (can't set units *
    *                         on a number).                         *
    *                                                               *
    ****************************************************************/
    
    (defun abSetXUnits (wave units)
      (cond 
        ((drIsWaveform wave)
         (putpropq (drGetWaveformXVec wave) units units)
         wave
         )
        ((famIsFamily wave)
         (famMap 'abSetXUnits wave units)
         )
        )
      )
    
    /***************************************************************
    *                                                              *
    *                   (abCreateSetXUnitsForm)                    *
    *                                                              *
    *  Set up a form for the special function on the calculator,   *
    *  which gives choices for the units. It needs to be cyclic,   *
    *   because if it's a type in field, quotes don't get added    *
    *                      around the units.                       *
    *                                                              *
    ***************************************************************/
    
    (defun abCreateSetXUnitsForm ()
      (let (units)
        (setq units (ahiCreateCyclicField
                      ?name 'units
                      ?prompt "Units"
                      ?choices '("V" "A" "s" "W" "dB" "Wb" "C" "Hz")
                      ?value "s"
                      ))
        (calCreateSpecialFunctionsForm
          'abSetXUnitsForm
          (list 
            (list units 0:0  180:20 140)
            )
          )
        ))
    
    /*****************************************************************
    *                                                                *
    *                (abSetXUnitsSpecialFunctionCB)                  *
    *                                                                *
    *       Callback for the abSetXUnits special function, which     *
    *       constructs the buffer input from the form and stack.     *
    *                                                                *
    *****************************************************************/
    
    (defun abSetXUnitsSpecialFunctionCB ()
      (calCreateSpecialFunction
       ?formSym 'abSetXUnitsForm
       ?formInitProc 'abCreateSetXUnitsForm
       ?formTitle "Set Units"
       ?formCallback 
       "(calSpecialFunctionInput 'abSetXUnits '(units))"
       ))
    
    
    /***************************************************************
    *                                                              *
    *               (abRegSetXUnitsSpecialFunction)                *
    *                                                              *
    *                Register the special function                 *
    *                                                              *
    ***************************************************************/
    
    (defun abRegSetXUnitsSpecialFunction ()
      (calRegisterSpecialFunction
       (list "abSetXUnits..." 'abSetXUnitsSpecialFunctionCB))
      t
      )

     

    And for your side topic - you can do this using an OCEAN script measurement in ADE XL. If instead of adding an expression to the output pane, you can add an OCEAN script. In this ocean script you can call the function  axlAddOutputs() at the top to define which outputs your script will output (it can output several), and call axlOutputResult() to output a specific result - you can call this through your script - so you can write a long script and just periodically output the things you want.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MicheleA
    MicheleA over 13 years ago

    Hi Andrew,

     thanks for the SKILL code! I will try and see how it works but since I am not SKILL-ed I decided to tackle the side topic first.

    I did add my small script as a measurement, as you suggested, and basically it works!. However, I have a couple of comments on this I'd like to share, namely:

     

    • the so created definition file does not get reloaded by ADE XL, neither when you tick/untick its plot enable box (as it happens for other expression that you can have available just by enabling them in the Outputs Setup pane and then going to the Results pane and click the curve button), nor if you re-run the simulation. I think this is quite dangerous. I actually had a bug in the first version of the script, which I solved, but it kept giving me errors until I found out that the software wasn't using the newer version on the disk...I use gedit as text editor and I also observed that the edit function doesn't necessarily lead to correct refresh of the file...But maybe I'm doing something unintended? The only sure fire way I've found to force a reload is to give the file path again...Tedious :)
    • As you pointed, I had to use axlAddOutputs() and axlOutputResult()...However I find the concept a little awkward, probably because I'm looking from the wrong perspective? The way I understood the workings of this is
      • start w/ axlAddOutputs() and create a list of labels
      • define my own expressions...and for this I also use "labels", like in vtank=VF(" /node")...vtank is a label, right?
      • finish w/ axlOutputResult() where I join my expressions with the list of labels given to axlAddOutputs()

    Now, this procedure looks like I have to come up with two names for everything I want to calculate AND to output so it is not exactly efficient in my view...Am I just doing it wrong?

     

    I look forward to testing your function and really thanks for your fast response!

    Regards,

    Michele 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    The reason why you think it's not being reloaded is because you're editing the wrong file, I suspect. When you first give the path to the file in ADE XL it copies it into the ADE XL data structure so that it will be design managed along with the rest of the adexl view. You can tell ADE XL not to do this copying, but then the ocean script won't get checked in along with the ade xl view. So you should hit the Edit button in the ADE XL outputs pane alongside the OCEAN script to maintain it. The cdsenv setting which controls the copying is:

     adexl.gui copyMeasurementScripts boolean t

    In the script, if you have axlAddOutputs('("outName1" "outName2" "outName3")) at the top, it is declaring which outputs the script produces. This allows ADE XL to quickly find out what the script will output so that it can add rows into the outputs pane, and for each one you can add specification limits and so on. The lines in the script where you are doing vtank=VF("/node") are just assigning SKILL variables - these are not assigning "labels" or "output names". You can do that with:

    axlOutputResult(vtank "vtank")

    or even:

    axlOutputResult(ymax(db20(VF("/out"))) "max db out")

    if you directly want to output the result. The point is that you might have 30 variable assignments, but only want to output 2 of them to ADE XL - you don't want it to see every single intermediate result along the way. So axlOutputResult() allows you to mark which results you wish to "publish" from your script. It's really not that onerous...

    Regards,

    Andrew. 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MicheleA
    MicheleA over 13 years ago

    Hi Andrew,

    many thanks for your clarifications! Indeed even after clicking on the Edit button on the ADE XL Outputs pane it didn't seem to work. However, after reading your reply I tried again and I now see it updates the output labels if I change their name so it is working somehow.

    I keep getting an error in the CIW and I think it is probably connected with the somewhat fuzzy behaviour I observe. The message I get is:

    *Error*   Evaluating expression (ocnEval("/workspaces/[..]MonteCarlo:1_active/outputsScriptsDir/Q_calculations.ocn")). 

    INFO (ADEXL-2328): Following error occurred while re-evaluating output ocnMeasure_0 : 

    Error* load: error while loading file - "/workspaces/mancis/[..]MonteCarlo:1_active/outputsScriptsDir/Q_calculations.ocn" at line 7

    Now, the thing is...I've stripped the OCEAN file to the bare minimum...It has 6 lines only! There's no line 7!!

    Although I can't trace this to anything, I do believe this error to be at the root of some weird behaviour, like that although I scraped some variables/outputs from the script, the results pane still shows them, as well as showing "eval error" in the value box next to the OCEAN file itself.

    Here are the contents of my extremely elaborated script:

    axlAddOutputs('("test_out_lbl" "test_2_out_lbl"))

    test_out = 3245

    test_2_out = 4730

    test3 = 24

    axlOutputResult(test_out "test_out_lbl")

    axlOutputResult(8*test_2_out "test_2_out_lbl")

    axlOutputResult(8*test3 "test3") 

    And still there is some bug in it...I have also tried "direct labeling" thru axlOutputResult() in the last line and it works perfectly..Thanks again!

    Regards,

    Michele 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MicheleA
    MicheleA over 13 years ago

    ..and a quick update. I just tried with a new testbench and the OCEAN script approach is working perfectly. Part of the previous issue was that I did not delete the other outputs from the pane, so that there were some conflicts for names.

    Thinking about the original main point, assigning units to waveforms, where shall I put/load the skill code you provided? I can probably start with a "load" command from the CIW but there's a more appropriate way for sure...

    Thanks,

     Michele

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    Hi Michele,

    Just doing a "load" from the CIW would allow them to be available in that session, but wouldn't allow them to be used in the ADE XL outputs (because the evaluation of expressions is done in the background "icrp" processes). So the "right" thing to do is to load the code from your .cdsinit file using:

    load("abSetXUnits.il")
    load("abSetUnits.il")
    ; add them into the Calculator as User Defined SKILL Functions
    abRegSetXUnitsSpecialFunction()
    abRegSetUnitsSpecialFunction()

    Regards,

    Andrew.

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MicheleA
    MicheleA over 13 years ago

    Hi Andrew,

    thanks again, I did as instructed and it works just fine. Nice tip for the user defined functions in the Calc (yes...I'm a newbie in all that).

    There is still a detail I don't quite get, however. Referring to the variables I defined as pasted in the opening post, the curve "cap" for instance is plotted as follows (after passing through abSetUnits())

     

    ...so instead of saying "cap (fF)" in the Y axis, or C(fF), somehow the software sees this curve as of type "freq".

    Since you said - at the beginning - that the units do get preserved, even if not reduced, I don't understand what is going on:

    vtank is a (complex) voltage

    icap is a (complex) current

    Zcap is a complex impedance 

    runfreq is a frequency

    twoPi is a number

    cap= 1/(twoPi*runfreq*Imag(Zcap))

    cannot be a "freq", because runfreq is at the denominator... 

    Can you explain me how that comes, what am I doing incorrectly? I don't want to bother you too much...If you want to point me to a specific part of the (sea of) manuals, I'd be glad to do some homework to show my good will ;-)

     Regards,

    Michele 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    Hi Michele,

    Looks as though I was not paying enough attention to the picture. The freq is the axis name not the units. I don't quite understand how the name ended up as freq - my experiments (I didn't do exactly the same as you) didn't end up with freq as the name - I'm guessing that it's coming from the xval() - the y-axis in that case would have a name of freq but I don't see how that would propagate through - normally the axis name doesn't persist through calculations as it would almost always be wrong otherwise.

    Anyway, rather than me writing an abSetName() function - actually it would be tricky to register this with the calculator because presumably you'd want freeform entry for the axis name rather than a cyclic field of predefined units, and if I use this way of registering the function it wouldn't surround the typed in name with quotation marks - not impossible to sort out, but I'm a bit pushed for time - I can show you how to set the attribute directly.

    drSetWaveformYVec(cap)->name=nil  ; erases the name, or you could use:
    drSetWaveformYVec(cap)->name="Cap"

    BTW, looking at your original code, I see you're calculating 2*pi as 44.0/7. I know that's only a 0.04% error, but you can do instead:

    defMathConstants('const)
    twoPi=2*const.PI 

    That's accurate to about 14 digits...  which is probably sufficient!

    It would probably be worth submitting a testcase to customer support so we can investigate (probably one of my colleagues, since I'll be on vacation after the end of this week) why the axis name is ending up as "freq", since it does seem a bit strange to me.

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MicheleA
    MicheleA over 13 years ago

    Hi Andrew,

     I think you were paying attention, the main thing was about the measurement units.

    I tended to ignore that little "freq" myself, in the beginning, and turned to it only when the other issue was solved.

    I tried however to use drSetWaveformYVec but it says "error eval: undefined function" both if I use the CIW and writing it on the OCEAN script...

    I will submit the test case I posted at beginning to the customer support later next week, I guess :)

     Michele

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

     Hi Michele,

    * hangs head in shame * - sorry, it should have been drGetWaveformYVec() - Get not Set. Sorry about that!

    Andrew.

    • 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