logic

Logic Gate

Logic
Run the live example Free · no sign-up · runs in your browser

The LogicGate block implements standard combinatorial Boolean logic operations across multiple incoming signals. It supports four fundamental operations—AND, OR, NOT, and XOR—with a configurable number of inputs. Input values are interpreted in accordance with standard engineering logic conventions (zero is false, any non-zero value is true), and the block outputs a clean discrete binary signal (11 for true, 00 for false). It is widely used in supervisory control, safety interlock chains, fault detection alarms, and digital state machines.

Mathematical Model

Incoming scalar signals uk(t)∈Ru_k(t) \in \mathbb{R} are converted into Boolean values bk(t)∈{0,1}b_k(t) \in \{0, 1\} using non-zero thresholding:

bk(t)={1,uk(t)≠00,uk(t)=0b_k(t) = \begin{cases} 1, & u_k(t) \ne 0 \\ 0, & u_k(t) = 0 \end{cases}

The output y(t)∈{0,1}y(t) \in \{0, 1\} is evaluated across MM inputs (M=numInputsM = \text{numInputs}) based on the selected operation:

  • AND: Output is 11 if all inputs are non-zero:

```latex

y(t) = \bigwedge_{k=1}^M b_k(t) = \prod_{k=1}^M b_k(t)

```

  • OR: Output is 11 if at least one input is non-zero:

```latex

y(t) = \bigvee_{k=1}^M b_k(t) = 1 - \prod_{k=1}^M (1 - b_k(t))

```

  • NOT: Output inverts the primary input signal (M=1M = 1):

```latex

y(t) = \neg b_1(t) = 1 - b_1(t)

```

  • XOR: Output is 11 if an odd number of inputs are non-zero:

```latex

y(t) = \left( \sum_{k=1}^M b_k(t) \right) \bmod 2

```

Inputs & Outputs

Direction ID Label Type Status
→ In in Input number Required
← Out out Output boolean Output

Parameters

Parameters Label Type Default Description
operation Operation select AND
numInputs Number of Inputs number 2

Usage Examples

Example 1: Redundant Dual-Sensor Safety Interlock

In an industrial furnace burner management system, fuel flow is only permitted if both flame ionization sensors detect an active pilot flame. Routing the two sensor threshold comparator outputs into a LogicGate with operation = "AND" and numInputs = 2 ensures the fuel solenoid valve is energised only when both sensors register active flame status simultaneously.

Example 2: Multi-Zone Fire Alarm OR Detection

Connecting three independent temperature alarm comparator flags to a single LogicGate configured with operation = "OR" and numInputs = 3. If any zone detects an over-temperature condition (T>75∘CT > 75^\circ\text{C}), the output immediately switches to 1.01.0, commanding emergency building ventilation and audible alarms.

Remarks & Best Practices

  • Non-Zero Truth Value Convention: Any numerical value not equal to zero (u≠0u \ne 0, including negative numbers) is treated as boolean true (11). Only exact zero (u=0.0u = 0.0) evaluates to false (00).
  • Clean Boolean Output: The block strictly outputs normalized values of 1.01.0 (true) or 0.00.0 (false), making it directly compatible with the control ports of Switch, Relay, and Timer blocks.
  • NOT Operation Input Count: Selecting operation = "NOT" automatically overrides the input count to 11, ignoring the numInputs setting.
  • Zero Execution Latency: Combinatorial logic is evaluated directly as native WebAssembly boolean operations without internal state delays or iteration loops.

Related Components

  • Comparator: Evaluates relational inequalities (u1≥u2u_1 \ge u_2, u1>u2u_1 > u_2) to produce boolean signals.
  • IntervalTest: Tests whether a continuous signal lies within a bounded interval [L,U][L, U].
  • Switch: Selects between two signals based on a boolean control condition.
  • Relay: Hysteresis switching element for on-off control.