The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Simulators >> Circuit Simulators >> How to define my own functions in calculator?
https://designers-guide.org/forum/YaBB.pl?num=1079644139

Message started by stephen on Mar 18th, 2004, 1:08pm

Title: How to define my own functions in calculator?
Post by stephen on Mar 18th, 2004, 1:08pm

How to define my own special functions in the calculator? I know from the manual that it involves writing skill code. But I don't see where I shall put the skill code. Anybody knows?

Thanks.

Title: Re: How to define my own functions in calculator?
Post by Andrew Beckett on Mar 21st, 2004, 12:51pm

Here's a simple example:


Code:

(procedure (abCalcDoubleCB)
 (calSpecialFunctionInput 'abCalcDouble nil))

(procedure (abIndepVarCB)
 (calSpecialFunctionInput 'abIndepVar nil))

(procedure (abCalcRegister)
 /* register my own functions */
 (calRegisterSpecialFunction
  (list "double" 'abCalcDoubleCB))
 (calRegisterSpecialFunction
  (list "indepVar" 'abIndepVarCB))
 t)

; now call the registration function
(abCalcRegister)


The code should be in a file, when you can then load
from the  .cdsinit file (see documentation on that file)
using:


Code:
(load "/path/to/the/above/file.il")


Regards,

Andrew.


Title: Re: How to define my own functions in calculator?
Post by stephen on Mar 21st, 2004, 11:32pm

Thanks for your reply. I suppose I still have to write a file to put the code for function abCalcDouble, right? When I test this code, cadence complaint that this function is undefined.

So where shall I put the code the function abCalcDouble?

What I actually need is an enhancement to the rms function. The rms function doesn't subtract the DC value first. So I need sth like rms(x-average(x)). Since I do this many times a day, I want to define a special function for it. I don't understand the syntax of skill code very much. It looks like a rule definition language instead of a programming language like C. Can you possibly offer a code example for the RMS function that I need?

Thanks again


Andrew Beckett wrote on Mar 21st, 2004, 12:51pm:
Here's a simple example:


Code:
(procedure (abCalcDoubleCB)
 (calSpecialFunctionInput 'abCalcDouble nil))

(procedure (abIndepVarCB)
 (calSpecialFunctionInput 'abIndepVar nil))

(procedure (abCalcRegister)
 /* register my own functions */
 (calRegisterSpecialFunction
  (list "double" 'abCalcDoubleCB))
 (calRegisterSpecialFunction
  (list "indepVar" 'abIndepVarCB))
 t)

; now call the registration function
(abCalcRegister)


The code should be in a file, when you can then load
from the  .cdsinit file (see documentation on that file)
using:


Code:
(load "/path/to/the/above/file.il")


Regards,

Andrew.


Title: Re: How to define my own functions in calculator?
Post by Andrew Beckett on Mar 22nd, 2004, 1:35am

Stephen,

Whoops, in cut and pasting the code, I missed out one of the
functions in my example. Here it is:


Code:

(procedure (abCalcDouble arg1)
 (times arg1 2))


SKILL is a full-featured programming language. Essentially it is LISP, although it can be written with a C-like syntax. The above examples were all written with a LISP-like syntax (that's my personal preference, but it makes no difference to how the code works)

To write it in C-like syntax, you could do:


Code:

procedure(MYrms(x)
 rms(x-average(x))
)

procedure(MYrmsCB()
 calSpecialFunctionInput('MYrms nil)
)

procedure(MYregisterCalcFuncs()
 calRegisterSpecialFunction(
   list("MYrms" 'MYrmsCB)
 )
)

; call the function to register the MYrms func:
MYregisterCalcFuncs()


In fact all the calculator does is build a SKILL expression - you'll see that the definition of MYrms() above uses exactly the expression you mentioned.

More information can be found on SKILL by reading the SKILL Language User Guide in cdsdoc - this is written in the style of a book on a programming language, much as you'd find in a bookshop.

Regards,

Andrew.


Title: Re: How to define my own functions in calculator?
Post by monglebest on May 16th, 2018, 11:57am

I am reading the
Cadence SKILL Language User Guide
Product Version 6.1.6 January 2015
but cannot find any keyword starting with calRegisterSpecialFunction, calSpecialFunctionInput, calCreateSpecialFunction or related with calculator.

I also checked
Virtuoso Design Environment SKILL Reference
Product Version 6.1.6 January 2015

Am I refer to something wrongly?

Title: Re: How to define my own functions in calculator?
Post by Andrew Beckett on May 19th, 2018, 12:46am

That's because it's in the Virtuoso Visualization and Analysis XL SKILL Reference manual.

If you had just run "cdnshelp" from the command line or use Help->search box at the top in the CIW, or Help->User Guide (say) and then use View->Show Navigation and then search there, you'd find it.

Note that in IC617 there's no longer a need to register functions this way - you can use the "fx" button in the function panel in the ViVA calculator to add your own functions - all you need is a file with the main code that does the work - the UI and registration is handled within the calculator itself.

Regards,

Andrew.

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.