Determining an algorithm's identity (alg_num), Calling user defined functions – VXI VT1422A User Manual

Page 195

Advertising
background image

Creating and Running Algorithms 193

Chapter 6

Determining An

Algorithm's Identity

(ALG_NUM)

When an algorithm is defined with the ALG:DEF 'ALGn',... command, the
VT1422A's driver makes available to the algorithm the constant
ALG_NUM. ALG_NUM has the value n from "ALGn." For instance, an
algorithm is defined with <alg_name> equal to "ALG3", then ALG_NUM
within that algorithm would have the value 3.

What can be done with this value? A short example of the code that uses
ALG_NUM is provided to illustrate:

writecvt ( inp_channel, (ALG_NUM * 10) + 0 );
writecvt ( Error, (ALG_NUM * 10) + 1 );
writecvt ( outp_channel, (ALG_NUM * 10) + 2 );
writecvt ( Status, (ALG_NUM * 10) + 3 );

This code writes algorithm values into CVT elements 10 through 13 for
ALG1, CVT elements 20 through 23 for ALG2, CVT elements 30 through
33 for ALG3, etc.

Using ALG_NUM allows identical code to be written that can take different
actions depending on the name it was given when defined.

Calling User

Defined Functions

Access to user defined functions is provided to avoid complex equation
calculation within an algorithm. Essentially, what is provided with the
VT1422A is a method to pre-compute user function values outside of
algorithm execution and place these values in tables, one for each user
function. Each function table element contains a slope and offset to calculate
an mx+b over the interval (x is the value provided to the function). This
allows the DSP to linearly interpolate the table for a given input value and
return the function's value much faster than if a transcendental function’s
equation were arithmetically evaluated using a power series expansion.

User functions are defined by downloading function table values with the
ALG:FUNC:DEF command and can take any name that is a valid 'C'
identifier like 'haversine', 'sqr', 'log10', etc. To find out how to generate table
values from a function equation, see "Generating User Defined Functions"
in Appendix F page 487. For details on the ALG:FUNC:DEF command, see
page 249 in the Command Reference.

User defined functions are global in scope. A user function defined with
ALG:FUNC:DEF is available to all defined algorithms. Up to 32 functions
can be defined in the VT1422A. The function can be called with the syntax
<func_name>(<expression>). Example:

for user function pre-defined as square root with name 'sqrt'

O108 = sqrt( I100); /* channel 8 outputs square root of input channel 0's value */

NOTE

A user function must be defined (ALG:FUNC:DEF) before any algorithm is
defined (ALG:DEF) that references it.

A VXIplug&play program that shows the use of a user defined function is
supplied on the driver disc ("tri_sine.cpp"). The program is on the CD
supplied with the instrument. View the readme.txt file provided with the
VXIplug&play driver for example program file location.

Advertising
This manual is related to the following products: