Hit Crossing

Detect crossing point

  • Library:
  • Simulink / Discontinuities

    HDL Coder / Discontinuities

    SimEvents

Description

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 or a SimEvents® message. See Output for more information.

Ports

Input

expand all

Input signal that the block detects when it reaches the offset in the specified direction.

Data Types: double

Output

expand all

Output indicating if the input signal crossed the hit offset. This port is only visible 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 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.

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

For 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 (MATLAB).

Data Types: uint32

Time T of the hit crossing event.

Data Types: double

Hit 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.

Parameters

expand all

Specify the value the block detects when the input crosses in the direction specified by Hit crossing direction.

Programmatic Use

Block Parameter: HitCrossingOffset
Type: character vector
Values: real values
Default: '0'

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.

Programmatic Use

Block Parameter: HitCrossingDirection
Type: character vector
Values: 'either' | 'rising' |'falling'
Default: 'either'

If selected, create an output port on the block icon.

Programmatic Use

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

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.

Programmatic Use

Block Parameter: HitCrossingOutputType
Type: character vector
Values: 'Signal' | 'Message'
Default: 'Signal'

Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.

Programmatic Use

Block Parameter: ZeroCross
Type: character vector, string
Values: 'off' | 'on'
Default: 'on'

Specify the sample time as a value other than -1. For more information, see Specify Sample Time.

Dependencies

This parameter is not visible unless it is explicitly set to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar
Default: '-1'

Block Characteristics

Data Types

double

Direct Feedthrough

yes

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

yes

Tips

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.

Extended Capabilities

Introduced before R2006a