Main Content

Configure Blocks with Fixed-Point Parameters

Certain Simulink® blocks allow you to specify fixed-point numbers as the values of parameters used to compute the block's output, for example, the Gain parameter of a Gain block.

Note

S-functions and the Stateflow® Chart block do not support fixed-point parameters.

You can specify a fixed-point parameter value either directly by setting the value of the parameter to an expression that evaluates to a fi object, or indirectly by setting the value of the parameter to an expression that refers to a fixed-point Simulink.Parameter object.

Note

Simulating or performing data type override on a model with fi objects requires a Fixed-Point Designer™ software license. See Sharing Fixed-Point Models for more information.

Specify Fixed-Point Values Directly

You can specify fixed-point values for block parameters using fi objects. In the block dialog's parameter field, enter the name of a fi object or an expression that includes the fi constructor function.

For example, entering the expression

fi(3.3,1,8,3)

as the Constant value parameter for the Constant block specifies a signed fixed-point value of 3.3, with a word length of 8 bits and a fraction length of 3 bits. The Constant block's output data type is set to Inherit from 'Constant value' by default, so the fixed-point type of the fi object will be inherited and used by the block.

In general, if you use a fi object as a block parameter, Simulink uses only the numeric value of the fi object. The fi object's type is only used if the block has a data type setting which allows you to inherit types from parameter values, like Inherit from 'Constant value' in the Constant block. Otherwise, any fimath settings, data type override settings, and math modes associated with the fi object will not be used. These settings will be controlled instead by the block’s data type rules and the model’s hardware implementation settings.

Use fi objects as block parameters only when you want the block to inherit the parameter’s fixed-point type and the block supports this behavior.

Specify Fixed-Point Values via Parameter Objects

You can specify fixed-point parameter objects for block parameters using instances of the Simulink.Parameter class. To create a fixed-point parameter object, either specify a fi object as the parameter object's Value property, or specify the relevant fixed-point data type for the parameter object's DataType property.

For example, suppose that you want to create a fixed-point constant in your model. You could do this using a fixed-point parameter object and a Constant block as follows:

  1. Enter the following command at the MATLAB® prompt to create an instance of the Simulink.Parameter class:

    my_fixpt_param = Simulink.Parameter
  2. Specify either the name of a fi object or an expression that includes the fi constructor function as the parameter object's Value property:

    my_fixpt_param.Value = fi(3.3,1,8,3)

    Alternatively, you can set the parameter object's Value and DataType properties separately. In this case, specify the relevant fixed-point data type using a Simulink.AliasType object, a Simulink.NumericType object, or a fixdt expression. For example, the following commands independently set the parameter object's value and data type, using a fixdt expression as the DataType:

    my_fixpt_param.Value = 3.3;
    my_fixpt_param.DataType = 'fixdt(1,8,2^-3,0)'
  3. Specify the parameter object as the value of a block's parameter. For example, my_fixpt_param specifies the Constant value parameter for the Constant block in the following model:

    The Constant block outputs a signed fixed-point value of 3.3, with a word length of 8 bits and a fraction length of 3 bits.

See Also

Topics