====== Simatic S7 SCL reference: Conversion operations ====== Back to reference overview: [[de:s7:scl_reference|Simatic S7 SCL reference with examples]] ===== ROUND: Round numerical value ===== {{anchor:round}} Round numerical value. See: [[de:s7:scl_reference#conversions|conversions]] [[de:s7:tia_knowhow#fc|_FC_]] Result := **ROUND** (Value); Value: function input ([[de:s7:tia_datatypes#fpn|floating-point numbers]])\\ Result: the return value of the function ([[de:s7:tia_datatypes#integers|integers]], [[de:s7:tia_datatypes#fpn|floating-point numbers]])\\ {{:de:s7:round_example.png|ROUND}} A yellow underline in the code indicates that the result of the function is not completely accurate for [[de:s7:tia_datatypes#int|INT]] types. For [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]] type, precision is complete. ==== ROUND_x ==== On the TIA portal, you can specify the type of variable used for the function by entering ROUND_:[[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]]. ===== CEIL: Generate next higher integer from floating-point number ===== {{anchor:ceil}} Generate next higher integer from floating-point number. See: [[de:s7:scl_reference#conversions|conversions]] [[de:s7:tia_knowhow#fc|_FC_]] Result := **CEIL** (Value); Value: function input ([[de:s7:tia_datatypes#fpn|floating-point numbers]])\\ Result: the return value of the function ([[de:s7:tia_datatypes#integers|integers]], [[de:s7:tia_datatypes#fpn|floating-point numbers]])\\ {{:de:s7:ceil_example.png|CEIL}} A yellow underline in the code indicates that the result of the function is not completely accurate for [[de:s7:tia_datatypes#int|INT]] types. For [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]] type, precision is complete. ==== CEIL_x ==== On the TIA portal, you can specify the type of variable used for the function by entering CEIL_:[[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]]. ===== FLOOR: Generate next lower integer from floating-point number ===== {{anchor:floor}} Generate next lower integer from floating-point number. See: [[de:s7:scl_reference#conversions|conversions]] [[de:s7:tia_knowhow#fc|_FC_]] Result := **FLOOR** (Value); Value: function input ([[de:s7:tia_datatypes#fpn|floating-point numbers]])\\ Result: the return value of the function ([[de:s7:tia_datatypes#integers|integers]], [[de:s7:tia_datatypes#fpn|floating-point numbers]])\\ {{:de:s7:floor_example.png|FLOOR}} A yellow underline in the code indicates that the result of the function is not completely accurate for [[de:s7:tia_datatypes#int|INT]] types. For [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]] type, precision is complete. ==== FLOOR_x ==== On the TIA portal, you can specify the type of variable used for the function by entering FLOOR_:[[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]]. ===== TRUNC: Truncate numerical value ===== {{anchor:trunc}} Truncate numerical value. See: [[de:s7:scl_reference#conversions|conversions]] [[de:s7:tia_knowhow#fc|_FC_]] Result := **TRUNC** (Value); Value: function input ([[de:s7:tia_datatypes#fpn|floating-point numbers]])\\ Result: the return value of the function ([[de:s7:tia_datatypes#integers|integers]], [[de:s7:tia_datatypes#fpn|floating-point numbers]]), Default: [[de:s7:tia_datatypes#dint|DINT]]\\ {{:de:s7:trunc_example.png|TRUNC}} A yellow underline in the code indicates that the result of the function is not completely accurate for [[de:s7:tia_datatypes#int|INT]] types. For [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]] type, precision is complete. ==== TRUNC_x ==== On the TIA portal, you can specify the type of variable used for the function by entering TRUNC_:[[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]]. ===== SCALE_X: Scale ===== {{anchor:scale_x}} Use the "Scale" instruction to scale a floating-point number by mapping it to a specific value range. You specify the value range with the MIN and MAX parameters. The result of the scaling is an integer. The inverse of the scale function is the norm ([[#norm_x|NORM_X]]) function. See: [[de:s7:scl_reference#conversions|conversions]] [[de:s7:tia_knowhow#fc|_FC_]] Result := **SCALE_X** (MIN := minimum value, VALUE:= act. value, MAX := maximal value); MIN: function input, low limit of range ([[de:s7:tia_datatypes#integers|integers]],[[de:s7:tia_datatypes#fpn|floating-point numbers]]) \\ MAX: function input, high limit of range ([[de:s7:tia_datatypes#integers|integers]],[[de:s7:tia_datatypes#fpn|floating-point numbers]]) \\ VALUE: function input, value to scale ([[de:s7:tia_datatypes#fpn|floating-point numbers]]) \\ Result: the return value of the function ([[de:s7:tia_datatypes#integers|integers]], [[de:s7:tia_datatypes#fpn|floating-point numbers]]), Default: [[de:s7:tia_datatypes#int|INT]]\\ {{:de:s7:scale_example.png|SCALE_X}} ==== SCALE_X_x ==== On the TIA portal, you can specify the type of variable used for the function by entering SCALE_X_:[[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]]. ===== NORM_X: Normalize ===== {{anchor:norm_x}} You can use the instruction "Normalize" to normalize the value of the tag at the VALUE input by mapping it to a linear scale. You can use the MIN and MAX parameters to define the limits of a value range that is applied to the scale. The result at the OUT output is calculated and stored as a floating-point number depending on the location of the value to be normalized within this value range. If the value to be normalized equals the value at input MIN, the instruction returns the result "0.0". If the value to be normalized equals the value at input MAX, the instruction returns the result "1.0". The inverse of the scale function is the scale ([[#scale_x|SCALE_X]]) function. See: [[de:s7:scl_reference#conversions|conversions]] [[de:s7:tia_knowhow#fc|_FC_]] Result := **NORM_X** (MIN := minimum range value, VALUE:= value to be normalized, MAX := maximal range value); MIN: function input, low limit of range ([[de:s7:tia_datatypes#integers|integers]],[[de:s7:tia_datatypes#fpn|floating-point numbers]]) \\ MAX: function input, high limit of range ([[de:s7:tia_datatypes#integers|integers]],[[de:s7:tia_datatypes#fpn|floating-point numbers]]) \\ VALUE: function input, value to be normalized ([[de:s7:tia_datatypes#fpn|floating-point numbers]]) \\ Result: the return value of the function ([[de:s7:tia_datatypes#integers|integers]], [[de:s7:tia_datatypes#fpn|floating-point numbers]]), Default: [[de:s7:tia_datatypes#real|REAL]]\\ {{:de:s7:norm_example.png|NORM_X}} ==== NORM_X_x ==== On the TIA portal, you can specify the type of variable used for the function by entering NORM_X_:[[de:s7:tia_datatypes#int|INT]], [[de:s7:tia_datatypes#dint|DINT]], [[de:s7:tia_datatypes#sint|SINT]], [[de:s7:tia_datatypes#lint|LINT]], [[de:s7:tia_datatypes#real|REAL]], [[de:s7:tia_datatypes#lreal|LREAL]]. ===== SCALE: Scale ===== {{anchor:scale}} Use the "Scale" instruction to convert the integer at the IN parameter into a floating-point number that can be scaled in physical units between a low limit value and a high limit value. You can 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 logic: {{:de:s7:scale_bipolar.png|SCALE / BIPOLAR}} See: [[de:s7:scl_reference#conversions|conversions]] [[de:s7:tia_knowhow#fc|_FC_]] RET_VAL := **SCALE** (IN := value to be scaled, HI_LIM:= maximal range value, LO_LIM := minimal range value, BIPOLAR := bipolar/unipolar, OUT => result); IN: function input, value to be scaled ([[de:s7:tia_datatypes#int|INT]]) \\ HI_LIM: function input, high limit of range ([[de:s7:tia_datatypes#real|REAL]]) \\ LO_LIM: function input, low limit of range ([[de:s7:tia_datatypes#real|REAL]]) \\ BIPOLAR: create bipolar/unipolar field ([[de:s7:tia_datatypes#bool|BOOL]]) \\ OUT: function output, result ([[de:s7:tia_datatypes#real|REAL]]) \\ RET_VAL: functionstate (error / ok) 0: no error ([[de:s7:tia_datatypes#word|WORD]]\\ {{:de:s7:scale2_example.png|SCALE}}