Detect crossing point
Simulink / Discontinuities
Simulink / Messages & Events
HDL Coder / Discontinuities
SimEvents
The Hit Crossing block detects when the input reaches the Hit crossing offset parameter value in the direction specified by the Hit crossing direction property.
You can configure the block to output a 1
or 0
signal,
a SimEvents® message, or a function-call event. See Output
for more information.
Port_1
— Input signalInput signal that the block detects when it reaches the offset in the specified direction.
Data Types: double
Port_1
— Output signalOutput indicating if the input signal crossed the hit offset. This port is visible only when you select the Show output port parameter check box.
Signal Output
If you select the Show output port check box and set the
Output type parameter to
Signal
, the block output indicates when
the crossing occurs.
If the input signal is exactly the value of the offset value after the hit crossing is detected in the specified direction, the block continues to output a value of 1.
If the input signals at two adjacent points brackets the offset value, the block outputs a value of 1 at the second time step.
If the Show output port check box is not selected, the block ensures that the simulation finds the crossing point but does not generate output.
If the initial signal is equal to the offset value, the
block outputs 1 only if the Hit crossing
direction property is set to
either
.
If Boolean logic signals are enabled, then the output is a
Boolean
.
SimEvents Message Output
The Hit Crossing block can also output a SimEvents message when the Output type
parameter is set to Message
.
If the input signal crosses the offset value in the specified direction, the block outputs a message.
If the input signal reaches the offset value in the specified direction and remains there, block outputs one message at the hit time and one message when the signal leaves the offset value.
If the initial input signal is equal to the offset value,
the block outputs a message with Crossing
Type
value None
only if the
Hit crossing direction is set to
either
.
The SimEvents message output signal is a struct
with
four fields.
Function-Call Output
The Hit Crossing block can also output a function-call event when the
Output type parameter is set to
Function-Call
.
Each time the input signal crosses the offset value in the specified direction, the block outputs a single function-call event.
The function-call event can be sent to the function-call input port of a function-call subsystem or function-call model.
The output is equivalent to the output of a Function-Call
Generator block at each time step with the
Number of iterations parameter of
that block set to 1
.
CrossingType
— Direction of zero-crossingNone
| NegativeToPositive
| NegativeToZero
| ZeroToPositive
| PositiveToNegative
| PositiveToZero
| ZeroToNegative
This field shows the direction in which the signal crosses
the Hit crossing offset value.
Negative, Zero, and Positive are defined relative to the
offset value.
The
data type is slHitCrossingType
which is
an enumerated data type. See Use Enumerated Data in Simulink Models for more
information. For example, if
HitCrossingOffset
is set to 2, a
rising signal crossing this offset value would be recorded
as a NegativeToPositive
hit crossing.
Note
A hit crossing is recorded based on the
Hit crossing direction
setting. In other words, if you set Hit
crossing direction to detect a
falling
hit crossing, a
NegativeToPositive
hit is not
recorded.
Note
In a SimEvents block, if the Crossing
Type
of an entity is a
NegativeToPositive
hitcrossing
then entity.CrossingType ==
slHitCrossingType.NegativeToPositive
returns logical 1 (true)
.
If the signal reaches the
HitCrossingOffset
value and holds it,
a single NegativeToZero
or
PositiveToZero
, depending on the
direction, hit is registered at the time of the hit
crossing.
Data Types: slHitCrossingType
Index
— Index of the input signal at which the hit crossing event occursFor n signals being passed to the Hit Crossing block, this field denotes which signal had a hit crossing event. For a matrix input, this field follows MATLAB® linear indexing. See Array Indexing.
Data Types: uint32
Time
— Time of hit crossing eventTime T of the hit crossing event.
Data Types: double
Offset
— Hit crossing value for detection0
(default) | real valuesHit crossing offset value as specified by the Hit crossing offset parameter.
Data Types: double
Data Types: double
| Boolean
| struct
Note
If the SimEvents message output signal crosses model reference boundaries or is used as an input to a Stateflow® chart, you need to create a bus object for the message. See Tips.
Hit crossing offset
— Hit crossing value for detection0
(default) | real valuesSpecify the value the block detects when the input crosses in the direction specified by Hit crossing direction.
Block Parameter:
HitCrossingOffset |
Type: character vector |
Values: real values |
Default:
'0' |
Hit crossing direction
— Input signal direction to hit crossingeither
(default) | falling
| rising
Direction from which the input signal approaches the hit crossing offset for a crossing to be detected.
When set to either
, the block serves as an
almost equal block, useful in working around
limitations in finite mathematics and computer precision. Used for these
reasons, this block might be more convenient than adding logic to your model
to detect this condition.
When the Hit crossing direction property is set to
either
and the model uses a fixed-step
solver, the block has the following behavior. If the output signal is 1, the
block sets the output signal to 0 at the next time step, unless the input
signal equals the offset value.
Block Parameter:
HitCrossingDirection |
Type: character vector |
Values:
'either' | 'rising'
|'falling' |
Default:
'either' |
Show output port
— Display an output portoff
(default) | on
If selected, create an output port on the block icon.
Block Parameter:
ShowOutputPort |
Type: character vector |
Values:
'off' | 'on' |
Default:
'on' |
Output type
— Choose signal, message, or function-call outputSignal
(default for Simulink®) | Message
(default for SimEvents) | Function-Call
When Output type is set to
Signal
, the output signal is set to one
whenever the input signal crosses the Hit crossing
offset value in the Hit crossing
direction and is zero at other times.
When the Output type is set to
Message
, the output signal becomes a
SimEvents message.
When Output type is set to Function-Call
,
the output signal becomes a function-call event.
Block Parameter:
HitCrossingOutputType |
Type: character vector |
Values:
'Signal' | 'Message' |
'Function-Call' |
Default:
'Signal' |
Enable zero-crossing detection
— Enable zero-crossing detectionon
(default) | off
Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.
Parameter:
ZeroCross |
Type: character vector, string |
Values:
'on' | 'off' |
Default:
'on' |
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
If the Hit Crossing block is configured to output a SimEvents message and the output signal:
Crosses into or out of a referenced model
Is fed to the input of a Stateflow chart
then you need to create a bus object for the message signal. In the
MATLAB Command Window, run Simulink.createHitCrossMessage
to
check for and, if needed, create a hit crossing message bus object in the base
workspace.
Set the data type of the corresponding port to Bus:
HitCrossMessage
.
Not recommended for production code.
Does not support non-floating data type for ert targets.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has a single, default HDL architecture.
ConstrainedOutputPipeline | Number of registers to place at
the outputs by moving existing delays within your design. Distributed
pipelining does not redistribute these registers. The default 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 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 is
|
The Hit crossing direction must be rising
or
falling
.
HDL code generation is not supported when the Output Type
is set to
Message
.