MUX
Function Name |
MUX |
---|---|
Description |
The MUX function outputs the same number as one of its inputs. The input that is chosen is dependent on the value of the K input. The MUX function has a K input and 2 or more other inputs. The unnamed inputs are recognized as being 0 for the first (top) input, 1 for the second input, 2 for the third input, 3 for the fourth input and so on. The number of the K input is used to identify which of the other inputs has the value that is to be used as the output. |
Arguments |
K {ANY_INT}. The number for the K input is used to identify the input that is to be used as the output for the MUX function. Input 0 - Input n {ANY} Each input is identified by a number, with the first (top) input being 0, the second being 1, the third being 2 and so on. For more information on the data types for the inputs and outputs, see Data Type Hierarchy. |
Returns |
Output {ANY} The K input is a number. This number is used to identify the input that has the value that is to be used as the output. The output value is of the same type as the value provided by the designated input. |
Example:
Function Block Diagram - MUX:
In this example, the K value is provided by a tag that represents the CurrentValueFormatted property of a point named 'FlowPresent'. As the 'FlowPresent' point is a digital, it provides a Boolean value and this has to be converted into an integer by using a BOOL_TO_INT conversion. The other inputs are provided by constant values, with Input 0 being 4 and Input 1 being 5.
As the current value of the 'FlowPresent' is True, the integer value for the K input is 1. This means that the value for the MUX output is the same as the value for Input 1 which is 5.
ST Program - MUX:
The syntax for a MUX function in an ST Program is:
- Output := MUX (K, Input 0, Input n);
Where Output, K, Input 0 and Input n are defined as variables earlier in the ST program.