← All exercises

Mux 4 with Fallback

medium

4-channel multiplexer with an out-of-range selector fallback and fault indication.

What it teaches

Defensive routing — real selector values come from HMIs and networks and can be garbage. In range, route like Mux 4; out of range, route the configured fallback value and raise a fault flag instead of acting on a stale or random source. The validate-then-act guard that wraps every external command in production code.

Inputs and outputs

TagTypeDefaultDescription
In_SelectDINTSelector index
In_Source0REAL5First input value
In_Source1REAL10Second input value
In_Source2REAL20Third input value
In_Source3REAL30Fourth input value
Cfg_FallbackREAL-99Safe default value routed when selector is out of range
Out_SelectedREALRouted value
Sts_FaultBOOLOut of range fault flag

Required behavior

  • Out_Selected equals In_Source0 when In_Select is 0.
  • Out_Selected equals In_Source1 when In_Select is 1.
  • Out_Selected equals In_Source2 when In_Select is 2.
  • Out_Selected equals In_Source3 when In_Select is 3.
  • Out_Selected equals Cfg_Fallback when In_Select is less than 0 or greater than 3.
  • Sts_Fault is 1 when In_Select is less than 0 or greater than 3.
  • Sts_Fault is 0 when In_Select is between 0 and 3 inclusive.