Generated reference › Hit Crossing — Control Systems/Discontinuities
kind: generated#block#control-systems-discontinuities

Hit Crossing — Control Systems/Discontinuities

Control_Systems/Discontinuities/Hit_Crossing · 1 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

Hit Crossing

Control Systems / Discontinuities

Reports the sample at which the input reaches or crosses an offset. With d = u − offset and d' the previous sample's value of d, the output is 1 on a hit and 0 otherwise:

  • d = 0 → hit, in every direction mode – the signal is sitting exactly on the offset.
  • rising → hit when d' < 0 and d > 0.
  • falling → hit when d' > 0 and d < 0.
  • either → hit when d'·d < 0.

A reported hit leaves the block on the offset: d' for the next sample is 0, not the value that carried the signal across. A crossing is therefore reported once, and two hits can never land on consecutive samples – the same rule as "leaving the offset is not a hit" below, applied to every hit rather than only to an exact landing. Under rising and falling this changes nothing (a hit already forces d to the side that forbids an immediate repeat); under either it is the difference between reporting every sign change and reporting every crossing.

Applied entry by entry, so a matrix signal is treated element for element and each entry carries its own history.

Ports

  • Input – the watched signal u, of any size [m,n].
  • Output – the hit indicator, of the SAME size [m,n], carrying 1 or 0 per entry. The block never reshapes a signal.

Parameters

  • Hit Crossing Offset – scalar, the level being watched. Defaults to 0, as in Simulink.
  • Hit Crossing Direction – which crossings count:
    • either – any sign change of d. The default.
    • rising – only upward crossings.
    • falling – only downward crossings.
    The d = 0 rule fires in all three, which is the block's own behaviour and not a simplification.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

The offset is a scalar; a per-entry offset sized like the input is not implemented and is reported rather than broadcast from its first entry.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. The offset is baked in as a constant at export time, and the direction selects which comparison is emitted rather than being tested at run time, so the generated core carries no mode branch at all. The exported state is the previous value, one per entry – the previous input, or the offset where that sample was a hit – together with the first-sample flag that keeps a run from inventing a crossing before it has any history. Every target writes that state from inside the hit branch, so the generated code cannot report a crossing twice any more than the block can.

Simulink bridge

Import and export, mapped to simulink/Discontinuities/Hit Crossing. "Hit Crossing Offset" to HitCrossingOffset as a plain pass-through value; "Hit Crossing Direction" to HitCrossingDirection through a 1:1 table (either / rising / falling), so the round trip is lossless. The block is always exported showing its output port and emitting a signal rather than a message or function call – ShowOutputPort is fixed to on and HitCrossingOutputType to Signal, because ICore has no counterpart for the other two. "Sampling Time (s)" goes to SampleTime, as on every block.

Notes

  • Stateful: one previous value per entry – the previous input, or the offset when that sample was a hit. The first sample has no predecessor, so it can only report a hit through the d = 0 rule.
  • Leaving the offset is not a hit: with d' = 0 and d ≠ 0 the block reports 0, having already reported the arrival on the previous sample. Because a hit stores the offset, this covers the sample after every hit, not only the ones that landed exactly on it.
  • Discrete by nature – the test compares consecutive samples, so the block always runs at its own rate rather than being pushed through a continuous solver's stages.
  • Not linear, and so deliberately carries no state space – the output is a boolean event, which no A/B/C/D can express.

Code facts#

FactValue
registered typeControl_Systems/Discontinuities/Hit_Crossing
familyControl_Systems/Discontinuities
solver environment classICoreBlock_0_Control_Systems_1_Discontinuities_2_Hit_Crossing
sourcesrc/ICoreSDK/ICoreBlockLibrary/Blocks/Control_Systems/Discontinuities/Hit_Crossing/ICoreBlock_0_Control_Systems_1_Discontinuities_2_Hit_Crossing.cpp
headersrc/ICoreSDK/ICoreBlockLibrary/Blocks/Control_Systems/Discontinuities/Hit_Crossing/ICoreBlock_0_Control_Systems_1_Discontinuities_2_Hit_Crossing.h
default size on canvas70 × 70 px
ports at insert1 in, 1 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDouble
2outICoreDouble

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Hit Crossing Offset0HitCrossingOffset
Hit Crossing Directioneither%~%rising%~%falling~~eitherHitCrossingDirection

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::Both
Simulink pathsimulink/Discontinuities/Hit \nCrossing
port-count rulePortsParam::None
SampleTime parameteryes
always setShowOutputPort = on, HitCrossingOutputType = Signal
ICore configSimulink parameterValue translation
Hit Crossing OffsetHitCrossingOffsetpasses through
Hit Crossing DirectionHitCrossingDirectioneithereither, risingrising, fallingfalling

Catalog contract: src/ICoreSDK/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

File banner (developer view)#

The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).

Hit Crossing block — reports the sample at which the input reaches or crosses an offset d = u - offset. A hit is d == 0 (sitting exactly on the offset, in every direction mode), or a strict sign change of the kind the direction selects. Output is 1 on a hit, 0 otherwise, entry by entry, so the output keeps the input's size.

Stateful: the previous input IS the state, seeded on the first sample with the current input so no crossing can be manufactured out of nothing. On a HIT the state is set to the OFFSET rather than to the input: the crossing has been reported, so the next sample starts from d' = 0 and cannot report the same transition twice. Two hits on consecutive samples are therefore impossible, which is what Simulink does -- and only "either" can see it, since rising and falling each leave d on the side that forbids an immediate repeat. Same per-language state contract as Backlash. Discrete by nature -- the comparison is between consecutive samples.

Code export: the offset and the direction are inlined as export-time constants, and the direction picks the emitted comparison rather than being tested at run time.

Sample results#

Hit Crossing — Step: 0 -> 1 at t = 1 sHit Crossing — Step: 0 -> 1 at t = 1 s00.51012345t (s)in ICoreDouble-Out-0out ICoreDouble-Out-0

The same rig also ran:

StimulusWhat it isOutput range
impulseImpulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair)0 … 1
rampRamp: slope 1 from t = 00 … 1
sineSine Wave: amplitude 1, 2 rad/s, no phase, no bias0 … 1
tableRepeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample0 … 1

Plotted: step — Step: 0 -> 1 at t = 1 s

Category dynamic · sample time 0.1 · 60 steps · commit ccf005c8 · produced by docsSample --out <folder> --steps 60 · data docs/generated/samples/Control_Systems__Discontinuities__Hit_Crossing.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).