← 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.

Parameters

TagDirectionTypeDefaultDescription
In_SelectInputDINT0Selector index
In_Source0InputREAL5First input value
In_Source1InputREAL10Second input value
In_Source2InputREAL20Third input value
In_Source3InputREAL30Fourth input value
Cfg_FallbackInputREAL-99Safe default value routed when selector is out of range
Out_SelectedOutputREAL0Routed value
Sts_FaultOutputBOOL0Out of range fault flag

Required behavior