Main Content

Constant

Generate constant value

  • Constant block

Libraries:
Simulink / Commonly Used Blocks
Simulink / Sources
DSP System Toolbox / Sources
HDL Coder / Commonly Used Blocks
HDL Coder / Sources

Description

The Constant block generates a real or complex constant value signal. Use this block to provide a constant signal input. The block generates scalar, vector, or matrix output, depending on:

  • The dimensionality of the Constant value parameter

  • The setting of the Interpret vector parameters as 1-D parameter

The output of the block has the same dimensions and elements as the Constant value parameter. If you specify for this parameter a vector that you want the block to interpret as a vector, select the Interpret vector parameters as 1-D check box. Otherwise, if you specify a vector for the Constant value parameter, the block treats that vector as a matrix.

Tip

To output a constant enumerated value, consider using the Enumerated Constant block instead. The Constant block provides block parameters that do not apply to enumerated types, such as Output minimum and Output maximum.

Using Bus Objects as the Output Data Type

The Constant block supports nonvirtual buses as the output data type. Using a bus object as the output data type can help simplify your model. If you use a bus object as the output data type, set the Constant value to 0 or to a MATLAB® structure that matches the bus object.

Using Structures for the Constant Value of a Bus

The structure you specify must contain a value for every element of the bus represented by the bus object. The block output is a nonvirtual bus signal.

You can use the Simulink.Bus.createMATLABStruct to create a full structure that corresponds to a bus.

You can use Simulink.Bus.createObject to create a bus object from a MATLAB structure.

If the signal elements in the output bus use numeric data types other than double, you can specify the structure fields by using typed expressions such as uint16(37) or untyped expressions such as 37. To control the field data types, you can use the bus object as the data type of a Simulink.Parameter object. To decide whether to use typed or untyped expressions, see Control Data Types of Initial Condition Structure Fields.

Setting Configuration Parameters to Support Using a Bus Object Data Type

To enable the use of a bus object as an output data type, before you start a simulation, set Configuration Parameters > Diagnostics > Data Validity > Advanced parameters > Underspecified initialization detection to Simplified. For more information, see Underspecified initialization detection.

Ports

Output

expand all

Constant value, specified as a real or complex valued scalar, vector, matrix, or N-D array. By default, the Constant block outputs a signal whose dimensions, data type, and complexity are the same as those of the Constant value parameter. However, you can specify the output to be any data type that Simulink® supports, including fixed-point and enumerated data types.

Note

If you specify a bus object as the data type for this block, do not set the maximum value for bus data on the block. Simulink ignores this setting. Instead, set the maximum values for bus elements of the bus object specified as the data type. For more information, see Simulink.BusElement.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Main

Specify the constant value output of the block.

  • You can enter any expression that MATLAB evaluates as a matrix, including the Boolean keywords true and false.

  • If you set the Output data type to be a bus object, you can specify one of these options:

    • A full MATLAB structure corresponding to the bus object

    • 0 to indicate a structure corresponding to the ground value of the bus object

    For details, see Using Bus Objects as the Output Data Type.

  • For nonbus data types, Simulink converts this parameter from its value data type to the specified output data type offline, using a rounding method of nearest and overflow action of saturate.

Programmatic Use

Block Parameter: Value
Type: character vector
Value: scalar | vector | matrix | N-D array
Default: '1'

Select this check box to output a vector of length N if the Constant value parameter evaluates to an N-element row or column vector.

  • When you select this check box, the block outputs a vector of length N, provided the Constant value parameter evaluates to an N-element row or column vector.

  • When you clear this check box, the block outputs a matrix of dimension 1-by-N or N-by-1, provided the Constant value parameter evaluates to an N-element row or column vector. For example, the block outputs a matrix of dimension 1-by-N or N-by-1.

Programmatic Use

Block Parameter: VectorParams1D
Type: character vector
Values: 'on' | 'off'
Default: 'on'

Specify the interval between times that the Constant block output can change during simulation (for example, due to tuning the Constant value parameter).

The default value of inf indicates that the block output can never change. This setting speeds simulation and generated code by avoiding the need to recompute the block output.

See Specify Sample Time for more information.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar | vector
Default: 'inf'

Signal Attributes

Specify the lower value of the output range that Simulink checks as a finite, real, double, scalar value.

Note

If you specify a bus object as the data type for this block, do not set the minimum value for bus data on the block. Simulink ignores this setting. Instead, set the minimum values for bus elements of the bus object specified as the data type. For information on the Minimum parameter for a bus element, see Simulink.BusElement.

Simulink uses the minimum to perform:

Note

Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

Block Parameter: OutMin
Type: character vector
Values: scalar
Default: '[ ]'

Specify the upper value of the output range that Simulink checks as a finite, real, double, scalar value.

Note

If you specify a bus object as the data type for this block, do not set the maximum value for bus data on the block. Simulink ignores this setting. Instead, set the maximum values for bus elements of the bus object specified as the data type. For information on the Maximum parameter for a bus element, see Simulink.BusElement.

Simulink uses the maximum value to perform:

Note

Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

Block Parameter: OutMax
Type: character vector
Values: scalar
Default: '[ ]'

Specify the output data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit from 'Constant value'' | 'Inherit: Inherit via back propagation' | 'double' | 'single' | 'half' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'boolean' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | 'Enum: <class name>' | 'Bus: <object name>'
Default: 'Inherit: Inherit from 'Constant value''

Select this parameter to prevent the fixed-point tools from overriding the Output data type you specify on the block. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

Block Parameter: LockScale
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Select the category of data to specify.

Inherit

Inheritance rules for data types. Selecting Inherit enables a second menu/text box to the right. Select one of the following choices:

  • Inherit from 'Constant value' (default)

  • Inherit via back propagation

Built in

Built-in data types. Selecting Built in enables a second menu/text box to the right. Select one of the following choices:

  • double (default)

  • single

  • int8

  • uint8

  • int16

  • uint16

  • int32

  • uint32

  • boolean

Fixed point

Fixed-point data types.

Enumerated

Enumerated data types. Selecting Enumerated enables a second menu/text box to the right, where you can enter the class name.

Bus object

Bus object. Selecting Bus enables a Bus object parameter to the right, where you enter the name of a bus object that you want to use to define the structure of the bus. If you need to create or change a bus object, click Edit to the right of the Bus object field to open the Simulink Type Editor. For details, see Create and Specify Simulink.Bus Objects.

Expression

Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right, where you can enter the expression.

Do not specify a bus object as the expression.

Select the data type override mode for this signal.

  • When you select Inherit, Simulink inherits the data type override setting from its context, that is, from the block, Simulink.Signal object or Stateflow® chart in Simulink that is using the signal.

  • When you select Off, Simulink ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.

For more information, see Specify Data Types Using Data Type Assistant in the Simulink documentation.

Dependencies

To enable this parameter, click the Show data type assistant button, and set the Mode to Built in or Fixed point.

Tips

The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.

Specify whether the fixed-point data is signed or unsigned. Signed data can represent positive and negative values, but unsigned data represents positive values only.

  • Signed, specifies the fixed-point data as signed.

  • Unsigned, specifies the fixed-point data as unsigned.

For more information, see Specify Data Types Using Data Type Assistant.

Dependencies

To enable this parameter, set the Mode to Fixed point.

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. For more information, see Specifying a Fixed-Point Data Type.

Dependencies

To enable this parameter, set Mode to Fixed point.

Setting Scaling to Binary point enables:

  • Fraction length

  • Calculate Best-Precision Scaling

Setting Scaling to Slope and bias enables:

  • Slope

  • Bias

  • Calculate Best-Precision Scaling

Specify the bit size of the word that holds the quantized integer. For more information, see Specifying a Fixed-Point Data Type.

Dependencies

To enable this parameter, set Mode to Fixed point.

Specify fraction length for fixed-point data type as a positive or negative integer. For more information, see Specifying a Fixed-Point Data Type.

Dependencies

To enable this parameter, set Scaling to Binary point.

Specify slope for the fixed-point data type. For more information, see Specifying a Fixed-Point Data Type.

Dependencies

To enable this parameter, set Scaling to Slope and bias.

Specify bias for the fixed-point data type as any real number. For more information, see Specifying a Fixed-Point Data Type.

Dependencies

To enable this parameter, set Scaling to Slope and bias.

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point | half | integer | single

Direct Feedthrough

no

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a