Description
The instruction "Encode" is used to read the bit number of the lowest bit in the input value and output it to the output OUT.
The "Encode" instruction selects the least significant bit of the value at the IN input and writes its bit number to the tag in the OUT output. If the IN input has the value DW#16#00000001 or DW#16#00000000, the value "0" is output at the OUT output.
Parameters
The following table shows the parameters of the "Encode" instruction:
|
Parameters |
Declaration |
Data type |
Memory area |
Description |
|
|---|---|---|---|---|---|
|
S7-1200 |
S7-1500 |
||||
|
EN |
Input |
BOOL |
I, Q, M, D, L or constant |
I, Q, M, D, L, T, C or constant |
Enable input |
|
ENO |
Output |
BOOL |
I, Q, M, D, L |
I, Q, M, D, L |
Enable output |
|
IN |
Input |
Bit strings |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
Input value |
|
OUT |
Output |
INT |
I, Q, M, D, L, P |
I, Q, M, D, L, P |
Output value |
You can select the data type of the instruction from the "???" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following figure shows how the instruction works using specific operand values:
If the "TagIn" operand has signal state "1", the instruction is executed. The instruction selects bit position "3" as the least significant bit at input "TagIn_Value" and writes the value "3" to the tag at the output "TagOut_Value.
If the instruction is executed without errors, the ENO enable output has the signal state "1" and the "TagOut" output is set.