10.06.2016 Views

eldo_user

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Post-Processing Library<br />

Macro-Like Usage of User Defined Functions<br />

Macro-Like Usage of User Defined Functions<br />

An example is provided to demonstrate how two resistors obtain their values directly from a<br />

UDF function or through a parameter (the files are realvalue.cir and realvalue.tcl). This<br />

example demonstrates the use of a simple Tcl function returning a real value.<br />

File realvalue.tcl listing:<br />

proc GETVALUE { rname rval } {<br />

# Use native Tcl syntax for expression calculation<br />

set newvalue [expr 2*$rval + log($rval)]<br />

}<br />

puts "The value of resistor $rname is $newvalue"<br />

return $newvalue<br />

Note<br />

The name of the function must be in uppercase in this example otherwise Eldo will not be<br />

able to identify it, because it is not called from a .CALL_TCL command.<br />

File realvalue.cir listing:<br />

* Simple Tcl function returning a real value<br />

.use_tcl realvalue.tcl<br />

.param p1={GETVALUE("R1",TEMPER)}<br />

.param p2=1<br />

v1 1 0 sin(0 2 1g)<br />

r1 1 2 p1<br />

r2 2 0 {GETVALUE("R2",p2)}<br />

.tran 1n 10n<br />

.plot tran i(r1)<br />

.end<br />

Except for the dump of the value, the Tcl function GETVALUE is equivalent to:<br />

.defmac GETVALUE(val) = 2*val+log(val)<br />

UDF parameters can be real values, strings, waves, macros, UDF or keywords (see “Keyword<br />

Parameters” on page 1142). It is important to note that for this kind of use, the UDF may be<br />

called for each timestep. Thus wave parameters are not passed to the UDF as objects but as real<br />

values.<br />

The example files samphold.cir and samphold.tcl contain another example of UDF. The<br />

function uses a Tcl namespace to keep the previous value of a wave, and is called inside a<br />

.DEFWAVE to create a sampled representation of the input wave.<br />

Eldo® User's Manual, 15.3 1141

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!