Edge Detect
LogicThe EdgeDetect block monitors an incoming continuous or discrete signal and emits a boolean pulse ( or ) whenever the signal crosses a specified threshold or changes state. It supports detection of rising transitions (crossing from below to at or above threshold), falling transitions (crossing from above to below threshold), or bidirectional threshold crossings.
The output pulse remains asserted for exactly one simulation time step () upon detection of an edge, making it an indispensable trigger block for event counters, state machines, latch resets, and sample-and-hold circuits.
Mathematical Model
Let be the input sample at discrete step , and let represent the boolean threshold state relative to threshold :
The output pulse is generated based on the selected detection mode:
At the initial simulation time step , the preceding state is initialized to the configured initialState parameter.
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | in |
In | number | Required |
| ← Out | out |
Out | boolean | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
mode |
Detection Mode | select | rising |
|
threshold |
Threshold | number | 0.5 |
Signal level separating low from high. An edge is a crossing of this level; move it outside the noise band to avoid spurious edges. |
initialState |
Initial State | number | 0 |
Usage Examples
Example 1: Optical Encoder Pulse Edge Detection
Detecting transitions from an optical rotary encoder output to drive an incrementing pulse counter. Setting mode = "rising" and threshold = 2.5 V on a 0–5 V digital signal generates a clean one-step pulse every time the encoder flag passes the sensor.
Example 2: Zero-Crossing Detector for AC Phase Synchronization
Detecting zero-crossings of an AC sinusoidal voltage signal. Setting threshold = 0.0 and mode = "either" triggers a pulse at every half-period crossing, allowing downstream logic to measure grid frequency or synchronize thyristor firing angles.
Remarks & Best Practices
- Single-Step Pulse Duration: Output is asserted to for exactly one simulation time step per detected crossing before returning to .
- Noise Sensitivity: In the presence of noisy analog signals near
threshold, rapid chattering or spurious edge triggers can occur. Pre-filter the signal with aDigitalFilterorDeadZoneblock if noise immunity is required. - Initial Step Response: Setting
initialStateproperly prevents or enforces an edge trigger on the very first simulation step when the initial signal value is non-zero. - Signal Compatibility: Works transparently with both continuous analog signals and discrete boolean signals.
Related Components
- Comparator: Continuous-time two-level comparator without one-shot pulse behavior.
- IntervalTest: Tests whether a signal lies inside or outside a specified numeric range.
- Relay: Switching element featuring a configurable hysteresis band.
- UnitDelay: Single-step delay for discrete state tracking.