Parameters, Parameters -33 – National Instruments AutoCode NI MATRIX User Manual

Page 141

Advertising
background image

Chapter 5

Generated Code Architecture

© National Instruments Corporation

5-33

AutoCode Reference

Parameters

Parameters represent data that can be used to provide data to tune the
algorithm by representing coefficients in equations or persistent data
somewhat like states. Parameters are implemented as persistent data when
generated into code. Parameters can be initialized with hard-coded values
or initialized using a %var as specified from the block dialog within the
SuperBlock Editor.

Caution

Parameters are designed for read-only data. Do not update a parameter in a

continuous model. It is impossible to predict the number of times a block will be executed
in a continuous system due to multiple calls of the Init, Output, or State phases. Therefore,
it is not known when to update the parameter value. For a continuous system, use the states
mechanism or use an input and output of the block connected to a Variable Block to provide
persistent data.

Using Parameters Instead of States in a Discrete
Model

Although parameters are intended to be read-only data, it is possible within
a discrete model to update a parameter because the execution of a block is
known, that is, a block will be called only once for the Init phase, once for
the Output phase at each time point, and once for the State phase (if it has
states) at each time point.

The benefits of using parameters for persistent data instead of states are
purely code generation related, specifically, reduced amount of code and
reduced amount of data by over 50% as compared to using states. However,
you must change the way the algorithm is coded to properly handle the
parameter update.

Note

National Instruments does not recommend that you replace all uses of states with

parameters. Rather, this section points out a special-case method to code a BlockScript
block to produce more efficient code for simple cases of persistent data.

The proper updating of a parameter value is a matter of guarding when the
update of the parameter occurs. For most cases, you will only want to
update the parameter in the Output phase. Thus, the BlockScript code
reflects this as in Example 5-14.

Advertising