Description
Use the "Scale" instruction to convert the integer in the IN parameter into a floating-point number, which can be scaled in physical units between a low limit value and a high limit value. You use the LO_LIM and HI_LIM parameters to specify the low limit and high limit of the value range to which the input value is scaled. The result of the instruction is output at the OUT parameter.
The "Scale" instruction works with the following equation:
OUT = [((FLOAT (IN) – K1)/(K2–K1)) ∗ (HI_LIM–LO_LIM)] + LO_LIM
The values of the constants "K1" and "K2" are determined by the signal state of the BIPOLAR parameter. The following signal states are possible in the BIPOLAR parameter:
-
Signal state "1": It is assumed that the value at the IN parameter is bipolar and in a value range between -27648 and 27648. In this case, the constant "K1" has the value -27648.0 and the constant "K2" the value +27648.0.
-
Signal state "0": It is assumed that the value at the IN parameter is unipolar and in a value range between 0 and 27648. In this case, the constant "K1" has the value 0.0 and the constant "K2" the value +27648.0.
When the value at the IN parameter is greater than the value of the constant "K2", the result of the instruction is set to the value of the high limit (HI_LIM) and an error is output.
When the value at the IN parameter is less than the value of the constant "K1", the result of the instruction is set to the value of the low limit value (LO_LIM) and an error is output.
When the indicated low limit value is greater than the high limit value (LO_LIM > HI_LIM), the result is scaled in reverse proportion to the input value.
Parameters
The following table shows the parameters of the "Scale" 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 |
INT |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
Input value to be scaled. |
|
HI_LIM |
Input |
REAL |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
High limit |
|
LO_LIM |
Input |
REAL |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
Low limit |
|
BIPOLAR |
Input |
BOOL |
I, Q, M, D, L or constant |
I, Q, M, D, L or constant |
Indicates if the value at IN parameter is to be interpreted as bipolar or unipolar. The parameter can assume the following values: 1: Bipolar 0: Unipolar |
|
OUT |
Output |
REAL |
I, Q, M, D, L, P |
I, Q, M, D, L, P |
Result of the instruction |
|
RET_VAL |
Output |
WORD |
I, Q, M, D, L, P |
I, Q, M, D, L, P |
Error information |
Parameter RET_VAL
The following table shows the meaning of the values of the RET_VAL parameter:
|
Error code* |
Explanation |
|---|---|
|
0000 |
No error |
|
0008 |
The value of the IN parameter is greater than the value of the "K2" constant or less than the value of the "K1" constant. |
|
General error information |
See also: "GET_ERR_ID: Get error ID locally" |
|
*The error codes can be displayed as integer or hexadecimal values in the program editor. You will find information on changing display formats in "See also". |
|
Example
The following example shows how the instruction works:
The following table shows how the instruction works using concrete operand values:
|
Parameters |
Operand |
Value |
|---|---|---|
|
IN |
Tag_InputValue |
22 |
|
HI_LIM |
Tag_HighLimit |
100.0 |
|
LO_LIM |
Tag_LowLimit |
0.0 |
|
BIPOLAR |
Tag_Bipolar |
1 |
|
OUT |
Tag_OutputValue |
50.03978588 |
|
RET_VAL |
Tag_ErrorCode |
W#16#0000 |