• 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. ocean script if statement not workiing

Stats

  • Locked Locked
  • Replies 11
  • Subscribers 65
  • Views 10713
  • 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 script if statement not workiing

NewScreenName
NewScreenName over 2 years ago

Hi all,

I am new in the use of ocean script, but I would like to perform the following task: use ADE assembler calculator cross() function on a signal, but when a certain design variable A has value 0, then the cross() function should return 0 (rather than nil, 0*nil would still evaluate to nil, so I cannot just multiply them).

I thought to approach this by an IF statement, I tried to look at an ocean documentation, so I created a file called myFile.ocn, loaded it in the outputs setup and its content is:

if (VAR("A")==0 0 cross(vtime('tran "/mySignal") (0.5 * VAR("vsupply")) 1 "rising" nil nil nil))

But that returns eval err. In the ocean reference it is stated that:

"if if( g_condition g_thenExpression [g_elseExpression] ) => g_result Description Evaluates g_condition, typically a relational expression, and runs g_thenExpression if the condition is true (that is, its value is non-nil); otherwise, runs g_elseExpression. The value returned by if is the value of the corresponding expression evaluated.

What am I doing wrong? ADE shows an eval err (it is the case even when I replace the cross() function from the IF with just a number)

Thank you very much

Best regards

  • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago

    Dear NewScreenName,

    NewScreenName said:

    I tried to look at an ocean documentation, so I created a file called myFile.ocn, loaded it in the outputs setup and its content is:

    if (VAR("A")==0 0 cross(vtime('tran "/mySignal") (0.5 * VAR("vsupply")) 1 "rising" nil nil nil))

    But that returns eval err. In the ocean reference it is stated that:

    A couple of suggestions if I may NewScreenName,

    1. Whenever I use the cross() function in an ocean script, I include in a conditional expression to guarantee that the desired result be a non-nil value. For example, to determine the first crossing time of a signal vsig2 to the threshold of 0.50 with a rising edge, my variable tcross_vsig2_1 is defined as:

    tcross_vsig2_1 = if(cross(vsig2_norm 0.5 1 "rising" nil nil) cross(vsig2_norm 0.5 1 "rising" nil nil) ERR_VALUE)

    If the cross() function evaluates to nil, the variable tcross_vsig2_1 takes on the value of ERR_VALUE.

    2. Are you sure the error is an error with the conditional expression and not with the cross() function? I don't know your exact error nor the nature of your simulation. Maybe it is evaluating that statement for some cases where VAR("A") is not equal to zero and the cross() function is returning nil?

    3. Might I also suggest for coding clarity, you consider the use of the conditional expression in the following form (explicity includes "then" and "else"):

    if(strcmp(rising_or_falling "rising") == 0
    then
    tend = if(cross(vsig_norm 0.9 -1 "rising" nil nil) cross(vsig_norm 0.9 -1 "rising" nil nil) 0.0)
    else
    tend = if(cross(vsig_norm 0.1 -1 "falling" nil nil) cross(vsig_norm 0.1 -1 "falling" nil nil) 0.0)

    This code snippet is from one of my functions.

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • NewScreenName
    NewScreenName over 2 years ago in reply to ShawnLogan

    Dear Shawn,

    Thank very much you for your hints. As I am a beginner with ocean, I have tried to reproduce very simply what you suggest as a first step, i.e. : 

    1. I defined an output to be vtime('tran "/mySignal") and called it vsig2_norm to follow your example

    2. From ADE assembler I refer to an ocean script giving its location in the "Details" column of the outputs tab

    3. The content of the script is almost identical to what you suggest: tcross_vsig2_1 = if(cross(vsig2_norm 0.5 1 "rising" nil nil) cross(vsig2_norm 0.5 1 "rising" nil nil) 0.1)

    Still I get an eval err. Is there maybe some other piece of code I should add in the ocean script to get it working, or the ocean script should be in a specific location?

    Best regards

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to NewScreenName

    Dear NewScreenName,

    No problem with the added questions - we are all beginners at something!

    NewScreenName said:
    Still I get an eval err. Is there maybe some other piece of code I should add in the ocean script to get it working, or the ocean script should be in a specific location?

    and

    NewScreenName said:
    I defined an output to be vtime('tran "/mySignal") and called it vsig2_norm to follow your example

    The syntax for your definition of vsig2_norm does not look quite right to me as vtime() is not an ocean function I am familiar with. To access a signal with ocean from a spectre simulation, the most general access function in ocean is the getData() command. You can also use the functions in the Calculator VT() - but let me show you the syntax for getData().

    vsig2_norm = getData("/mySignal" ?result "tran" ?resultsDir <path_to_results>)

    If you include this getData() command in ADE Assembler, it will know the path to the simulation results, so you can use the shortened syntax:

    vsig2_norm = getData("/mySignal" ?result "tran")

    With this syntax for vsig2_norm, your ocean command:

    NewScreenName said:
    tcross_vsig2_1 = if(cross(vsig2_norm 0.5 1 "rising" nil nil) cross(vsig2_norm 0.5 1 "rising" nil nil) 0.1)

    looks fine. 

    If it is of any help, I did provide an example of using an ocean script in Assembler to print some output data to a file in a Forum post at URL:

    https://community.cadence.com/cadence_technology_forums/f/custom-ic-design/48506/how-to-get-values-of-sampling-points

    if it is of any interest or use to you.

    Let 

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • NewScreenName
    NewScreenName over 2 years ago in reply to ShawnLogan

    Dear Shawn,

    Thank you very much for following up. I have read the link you provided and tried to replicate my setup accordingly, in particular as you can see:

    I reference an ocean script "prova.ocn" whose content is just the line tcross_vsig2_1 = if(cross(vsig2_norm 0.5 1 "rising" nil nil) cross(vsig2_norm 0.5 1 "rising" nil nil) 0.1)

    I define vsig2_norm accordingly to your suggestion. However in the results tab I still get an error:

    According to the error message apparently the problem lies in the loading of the script:


    Opening the log file the message does not seem ti be more explanatory about what would be the issue in loading the script:

    Do you have an idea of what I am doing wrong? Have I missed some steps?

    Thank you again and best regards

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to NewScreenName

    Dear NewScreenName,

    NewScreenName said:
    and tried to replicate my setup accordingly, in particular as you can see:

    Good work so far! You are making progress, albeit I am sure it is frustrating to you!

    NewScreenName said:
    Do you have an idea of what I am doing wrong? Have I missed some steps?

    I believe I am responsible for wasting your time on this - my sincere apologies! There is a new procedure to allow access to the Assembler data and allow executing an ocean script.

    It is documented at URL:

    https://support.cadence.com/apex/ArticleAttachmentPortal?id=a1Od0000000nXTvEAM&pageName=ArticleContent

    In short, there is a line which must be added at the beginning of your script and a second line that is added at its end to return its value.

    I think if you add the following to your "prova.ocn" file, it will work with Assembler:

    axlAddOutputs( list("tcross_vsig2_1"))
    selectResults('tran)
    vsig2_norm = VT("/estimator_mode")
    tcross_vsig2_1 = if(cross(vsig2_norm 0.5 1 "rising" nil nil) cross(vsig2_norm 0.5 1 "rising" nil nil) 0.1)
    axlOutputResult( tcross_vsig2_1 "tcross_vsig2_1")

    I think your could also use:

    axlAddOutputs( list("tcross_vsig2_1"))
    vsig2_norm = getData("/estimator_mode" ?result "tran")
    tcross_vsig2_1 = if(cross(vsig2_norm 0.5 1 "rising" nil nil) cross(vsig2_norm 0.5 1 "rising" nil nil) 0.1)
    axlOutputResult( tcross_vsig2_1 "tcross_vsig2_1")

    Shawn

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • NewScreenName
    NewScreenName over 2 years ago in reply to ShawnLogan

    You have saved me a lot of time with these hints instead, it is working now, Thank you very much Shawn!

    Best regards

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to NewScreenName

    Dear NewScreenName,

    NewScreenName said:
    it is working now,

    Wonderful!! I am very happy to read this! I am sorry about the initial suggestion.  I was not able to access the Cadence tools to verify my initial suggestion and should have mentioned it. 

    Great news and thanks for letting us know!

    Shawn 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • NewScreenName
    NewScreenName over 2 years ago in reply to ShawnLogan

    Dear Shawn,

    I am back on a similar topic as I tried to further elaborate the ocean script I was working with, and there are some new things which are not clear for me:

    after I add the axlAddOutputs at the beginning and axlOutputResult at the end, with all the outputs that I want to inspect, I define the following time point t_strtp_begin:

    t_strtp_begin = if(cross(v_cal_done (0.5*VAR("vdd1p8")) 1 "rising" nil nil) cross(v_cal_done (0.5*VAR("vdd1p8")) 1 "rising" nil nil) if(VAR("cal")==0 then 0 else "error: cal_done did not rise"))

    and so far it works properly.

    Then I need a new expression containing a signal from t_strtp_begin  and the end of the simulation, time VAR("pT_SIM"), so I define:
    v_en_smpl_after_cal = clip(VT("/en_smpl") t_strtp_begin VAR("pT_SIM"))

    And that is returning an eval err, however if I write instead v_en_smpl_after_cal = clip(VT("/en_smpl") 20n VAR("pT_SIM")) it will work properly. But if after the simulation I press the re-evaluate results I will get an eval err again. Instead it would always work properly if I wrote instead v_en_smpl_after_cal = clip(VT("/en_smpl") 20e-9 VAR("pT_SIM")).

    So I wonder what is the correct way to pass to the clip function a variable defined within the ocean script?

    And what would be the correct syntax to pass numbers with the multiplier such as 20n instead of 20e-9 in such a way that even after re-evaluation the result does not cause an eval err?

    Side note:

    - I am using ICADVM20.1

    - I already tried to do v_en_smpl_after_cal = clip( v( "/en_smpl" ) t_strtp_begin VAR("pT_SIM") ) as suggested in the Help section within virtuoso

    - the same help section would suggest to insert the time boundaries as 2m 3m for example, however as I mentioned this works for the first run, but does not if I try to re-evaluate the results after the run is complete

    -using t_strtp_begin  would not only get an eval err for the axlOutputResult( v_en_smpl_after_cal "v_en_smpl_after_cal") but also for all the other outputs that would otherwise be correctly computed (e.g. axlOutputResult( t_strtp_begin "t_strtp_begin") would return the correct value if v_en_smpl_after_cal is commented in the code.

    Thank you a lot

    Best regards

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ShawnLogan
    ShawnLogan over 2 years ago in reply to NewScreenName

    Dear NewScreenName,

    I've read your Forum post a couple of times. I think I understand the various issues you are observing. I can not explain everything you are observing, but do have a couple of comments.

    NewScreenName said:

    Then I need a new expression containing a signal from t_strtp_begin  and the end of the simulation, time VAR("pT_SIM"), so I define:
    v_en_smpl_after_cal = clip(VT("/en_smpl") t_strtp_begin VAR("pT_SIM"))

    And that is returning an eval err,

    I might suggest that the clip() expression will fail is your variable t_strtp_begin returns its value of "error: cal_done did not rise". This is non-numeric and hence an invalid argument to the clip() function. If you look at the syntax I used in my conditional statement with the cross() function, I defined a variable ERR_VAL whose value is numeric. In your case, since the cross() function expects its third argument to be greater or equal to its first argument, you might consider changing your nil response from "error: cal_done did not rise" to some value less than or equal to VAR("pT_SIM"). I think that will allow the expression for v_en_smpl_after_cal to evaluate without a error.

    NewScreenName said:

    if I write instead v_en_smpl_after_cal = clip(VT("/en_smpl") 20n VAR("pT_SIM")) it will work properly. But if after the simulation I press the re-evaluate results I will get an eval err again. Instead it would always work properly if I wrote instead v_en_smpl_after_cal = clip(VT("/en_smpl") 20e-9 VAR("pT_SIM")).

    So I wonder what is the correct way to pass to the clip function a variable defined within the ocean script?

    I do not understand why using the syntax 20n does not work when re-evaluating results while using 20e-09 does. Are you doing an incremental re-evaluation or a complete re-evaluation? 

    As I mentioned above, I think if you modify your expression for t_strpt_begin to always produce a numeric argument that is less than or equal to VAR("pT_SIM"), the clip function will evaluate correctly.

    NewScreenName said:
    And what would be the correct syntax to pass numbers with the multiplier such as 20n instead of 20e-9 in such a way that even after re-evaluation the result does not cause an eval err?

    As I mentioned, this puzzles me as I've never had an issue using suffix notation for numeric arguments with ocean nor Assembler/Explorer. I do not have any access to any CCRs that may apply to your version of the software, so I am unable to provide any information was to whether this is known issue for your version.

    NewScreenName said:
    -using t_strtp_begin  would not only get an eval err for the axlOutputResult( v_en_smpl_after_cal "v_en_smpl_after_cal") but also for all the other outputs that would otherwise be correctly computed (e.g. axlOutputResult( t_strtp_begin "t_strtp_begin") would return the correct value if v_en_smpl_after_cal is commented in the code.

    I apologize, but I don't understand what you are trying to explain in this section of your Forum post - sorry!

    But, I think many of your issues will be resolved if you make sure t_strip_begin always returns a numeric value less than or equal to VAR("pT_SIM").

    Shawn

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • NewScreenName
    NewScreenName over 2 years ago in reply to ShawnLogan

    Dear Shawn,

    Thank you, there was indeed a syntax error in how I formulated the nested second if which should have prevented returning nil in my simulation, but did not.

    For the numerical issue, not clear yet, but it is possible to work around it.

    Best regards

    • 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