Comparator
LogicEvaluates a relational comparison between an incoming input signal and a configurable reference threshold. Supports standard mathematical operators () and flexible output modes (emitting fixed binary constants or passing through the raw input signal). Essential for threshold crossing detection, safety interlocks, over-temperature alarms, driving conditional Switch multiplexers, and converting continuous analog signals into discrete logic flags.
Mathematical Model
The boolean condition is determined by the selected operator and reference threshold :
The output signal is assigned according to the boolean evaluation and the configured output modes:
where:
- equals
trueValuewhentrueResultMode = "constant", or whentrueResultMode = "input". - equals
falseValuewhenfalseResultMode = "constant", or whenfalseResultMode = "input".
For equality (==) and inequality (!=) comparisons on floating-point signals, an internal numerical tolerance () is applied:
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | in |
Input | number | Required |
| ← Out | out |
Output | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
operator |
Operator | select | >= |
|
threshold |
Threshold | number | 0 |
|
trueResultMode |
True Output | select | constant |
|
trueValue |
True Constant | number | 1 |
|
falseResultMode |
False Output | select | constant |
|
falseValue |
False Constant | number | 0 |
Usage Examples
Example 1: Critical Over-Temperature Alarm and Safety Interlock
In battery energy storage systems (BESS), monitoring lithium-ion cell temperature requires an emergency trip when temperature exceeds . Configuring a Comparator with operator = ">=", threshold = 55.0, trueValue = 1.0, and falseValue = 0.0 generates a clean binary shutdown flag () that directly commands contactor disconnection and cooling boost pumps.
Example 2: Piecewise Squelch Passthrough (Signal Gating)
To pass an analog acoustic sensor signal only when it exceeds an ambient background noise floor () and mute it to zero otherwise, configure the Comparator with operator = ">", threshold = 1.5, trueResultMode = "input", and falseResultMode = "constant" with falseValue = 0.0. Transients above pass through unattenuated, while baseline background noise is completely suppressed.
Remarks & Best Practices
- Floating-Point Equality Tolerance: Direct equality (
==) and inequality (!=) checks incorporate an internal tolerance band (), preventing false negative drops caused by floating-point representation limits. - Zero-Latency Combinatorial Logic: Evaluated as an instantaneous algebraic operator with zero state memory or transport delay within the current simulation step.
- Zero-Crossing Solver Synchronization: Abrupt state changes across the threshold trigger zero-crossing events, prompting adaptive solvers (such as RK45) to bisect step sizes and locate the exact boundary crossing timestamp.
- Driving Conditional Logic: Commonly combined with
Switchblocks andLogicGateelements (AND,OR,NOT) to construct multi-stage safety interlocks and finite state machines.
Related Components
- Switch: Multiplexes between two continuous signals using a selector threshold.
- Relay: Hysteretic two-state threshold switching that eliminates chatter on noisy inputs.
- LogicGate: Evaluates boolean operations (
AND,OR,XOR,NOT) on digital signals. - DeadZone: Suppresses signals within an insensitivity region around zero.