← 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