Compare To Constant
R2026bDetermine how signal compares to specified constant
Compare To Constant block
To add a block to a model, double-click the canvas and start typing the block name. Then, select the block from the list.
Libraries:
Simulink /
Logic and Bit Operations
HDL Coder /
Logic and Bit Operations
Description
The Compare To Constant block compares an input signal to a constant. Specify the constant in the Constant value parameter. Specify how the input is compared to the constant value with the Operator parameter.
Examples
Exploring Law of Large Numbers Using MATLAB System Block
Use MATLAB System blocks to illustrate the law of large numbers in Simulink.
Ports
Input
Input signal, specified as a scalar, vector, or matrix, is compared with constant. The block first converts its Constant value parameter to the input data type, and then performs the specified operation.
Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus
Output
The output is 0 if the comparison is false, and
1 if it is true.
Data Types: uint8 | Boolean
Parameters
This parameter can have these values:
==— Determine whether the input is equal to the specified constant.~
=— Determine whether the input is not equal to the specified constant.<— Determine whether the input is less than the specified constant.<=— Determine whether the input is less than or equal to the specified constant.>— Determine whether the input is greater than the specified constant.>=— Determine whether the input is greater than or equal to the specified constant.
Programmatic Use
Block Parameter:
relop |
| Type: character vector |
Values: '=='
| '~='| '<'
|'<='| '>='|
'>' |
Default:
'<=' |
Specify the constant value to which the input is compared.
Programmatic Use
Block Parameter:
const |
| Type: character vector |
| Value: scalar | vector | matrix | N-D array |
Default:
'3.0' |
Specify the data type of the output, boolean or
uint8.
Programmatic Use
Block Parameter:
OutDataTypeStr |
| Type: character vector |
Values:'boolean' |
'uint8'
|
Default:
'boolean' |
Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.
Programmatic Use
Block Parameter:
ZeroCross |
| Type: character vector |
Values:
'off' | 'on' |
Default:
'on' |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
More About
If you have a Simulink® Coverage™ license, the Compare To Constant block receives condition coverage.
Condition coverage measures:
The number of times that the comparison between the input and the specified constant is true
The number of times that the comparison between the input and the specified constant is false
If you select the Relational boundary (Simulink Coverage) coverage metric, the Compare To Constant block receives relational boundary coverage. For more information, see Relational Boundary Coverage (Simulink Coverage).
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has one default HDL architecture.
General
| HDL Property | Description |
|---|---|
| ConstrainedOutputPipeline | Number of registers to place at
the outputs by moving existing delays in the design. Distributed pipelining
does not redistribute these registers. The default value is
|
| InputPipeline | Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default value is
|
| OutputPipeline | Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default value is
|
| SynthesisAttributes |
Specifies the synthesis attributes for the blocks and block output signals in the model. The generated HDL code contains these attributes. For more information, see SynthesisAttributes (HDL Coder). |
This table lists the data types that the input port supports for HDL code generation:
| Input Port | Dimensions | Fixed-Point Values | Floating-Point Values | Built-in Integers | Bus Signals | Boolean Values | Complex Values |
|---|---|---|---|---|---|---|---|
| Port_1 | Scalar Vector Matrices up to two dimensions | Yes | Half Single Double | Yes | No | No | Yes |
The output port outputs data type uint8 or
boolean, depending on the value of the Output
data type parameter.
To generate HDL code when using native floating-point input data types, open the HDL Code Generation > Floating-Point pane in the Configuration Parameters dialog box and select the Use floating-point parameter. For more information, see Generate Target-Independent HDL Code with Native Floating-Point (HDL Coder).
When you use half, single, or
double data types as inputs to the block, you can use the
Latency Strategy (HDL Coder) model configuration parameter to
specify whether the blocks latency maps to minimum or maximum latency values
when using native floating-point libraries. The block supports these native
floating-point latency values:
| Floating-Point Data Type | Latency Strategy Setting | Latency Cycles | Custom Latency Support |
|---|---|---|---|
double | MIN | 1 | No |
MAX | 3 | ||
single | MIN | 1 | No |
MAX | 3 | ||
half | MIN | 1 | No |
MAX | 2 |
The block uses multicycle implementations to introduce additional latency in the generated code. To see the added latency, view the generated model or validation model. See Generated Model and Validation Model (HDL Coder).
You can use these HDL Coder optimizations to optimize the speed, area, and I/Os.
Area Optimization
| Optimization | Description |
|---|---|
| Resource Sharing (HDL Coder) | Resource sharing is an area optimization in which HDL Coder identifies multiple functionally equivalent resources and replaces them with a single resource. |
| Streaming (HDL Coder) | Streaming is an area optimization in which HDL Coder transforms a vector data path to a scalar data path or to several smaller-sized vector data paths. |
Speed Optimization
| Optimization | Description |
|---|---|
| Specify Distributed Pipelining Settings (HDL Coder) | Distributed pipelining, or register retiming, is a speed optimization that moves existing delays in a design to reduce the critical path while preserving functional behavior. |
| Clock-Rate Pipelining (HDL Coder) | Clock-rate pipelining is an optimization framework that allows other speed and area optimizations to introduce latency at the clock rate. |
| Specify Adaptive Pipelining Settings (HDL Coder) | Adaptive pipelining optimization creates patterns or combination of blocks with registers that can improve the achievable clock frequency and reduce the area usage on the FPGA boards by inserting pipeline registers to the blocks in your design. |
| Critical Path Estimation (HDL Coder) | To quickly identify the most likely critical path in your design, use critical path estimation. Critical path estimation speeds up the iterative process of finding the critical path. To know blocks that are characterized in critical path estimation, see Characterized Blocks (HDL 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 R2006aYou can now generate synthesizable HDL code for the Compare To
Constant block when using native floating-point data types, including
half, single, or
double.
You can also use various HDL optimizations, such as distributed pipelining, hierarchy flattening, or delay balancing to generate optimized HDL code for the block.
Use the SynthesisAttributes HDL block property to specify the synthesis attributes for the block and its output signals. HDL Coder includes these attributes in the generated HDL code.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
