The algorithm execution environment, The main function, How user algorithms fit in – VXI VT1422A User Manual

Page 186: The main function how user algorithms fit in

Advertising
background image

184 Creating and Running Algorithms

Chapter 6

Example 2;

/*** same function as example 1 above but shows a different approach ***/
static float max_output = .020;

/* 20 mA max output */

static float min_output = .004;

/* 4 mA min output */

/* following lines input, limit output between min and max_output and outputs. */
/* output is split to two current output channels wired in parallel to provide 20 mA */
/* write cvt is just to show access to remote channel
O116 = max( min_output, min( max_output, (12.5 * I108) / 2 ) );
O117 = max( min_output, min( max_output, (12.5 * I108) / 2 ) );
writecvt(I14001,501);

The Algorithm Execution Environment

This section describes the execution environment that the VT1422A
provides for algorithms. Here, the relationship of algorithms to the main()
function that calls it is described.

The Main Function

All 'C' language programs consist of one or more functions. A 'C' program
must have a function called main(). In the VT1422A, the main() function is
usually generated automatically by the driver when the INIT command is
executed. The main() function executes each time the module is triggered
and controls execution of algorithm functions. See Figure 6-1 for a partial
listing of main().

How User

Algorithms Fit In

When the module is INITiated, a set of control variables and a function
calling sequence are created for all algorithms defined. The value of variable
"State_n" is set with the ALGorithm:STATe command and determines
whether an algorithm will be called. The value of "Ratio_n" is set with the
ALGorithm:SCAN:RATio command and determines how often an
algorithm will be called (relative to trigger events).

Since the function-calling interface to an algorithms is fixed in the main()
function, the "header" of an algorithm function is also pre-defined. This
means that, unlike standard 'C' language programming, an algorithm
program (a function) need not (must not) include the function declaration
header, opening brace "{" and closing brace "}". Only the "body" of the
function is supplied; the VT1422A's driver supplies the rest.

Think of the program space in the VT1422A in the form of a source file with
any global variables first, then the main() function followed by as many
algorithms as defined. Of course, what is really contained in the VT1422A's
algorithm memory are executable codes that have been translated from the
downloaded source code. While not an exact representation of an algorithm
execution environment, Figure 6-1 shows the relationship between a normal
'C' program and two VT1422A algorithms.

Advertising
This manual is related to the following products: