LGF_ScaleLinear (FC / V3.0.1)

Overview

Author: Siemens Digital Industry Support

Short description

This function scales an input variable (LReal) via a linear straight-line equation.

Block Interface

LGF_ScaleLinear (FC)
LReal  x Ret_Val  LReal
    
LReal  x1 error  Bool
    
LReal  y1 status  Word
    
LReal  x2   
    
LReal  y2   
    
LReal  yMin   
    
LReal  yMax   
    
   

Input parameter

IdentifierData type Description
xLReal Input value `x` to be scaled.
x1LReal Point 1 (P1) -`x` coordinate of the linear function.
y1LReal Point 1 (P1) -`y` coordinate of the linear function.
x2LReal Point 2 (P2) -`x` coordinate of the linear function.
y2LReal Point 2 (P2) -`y` coordinate of the linear function.
yMinLReal Lower limit value of the output.
yMaxLReal High limit value of the output.

Output parameter

IdentifierData type Description
Ret_ValLReal Scaled output value `y`
errorBool FALSE: No error
TRUE: An error occurred during the execution of the FB
statusWord 16#0000-16#7FFF: Status of the FB
16#8000-16#FFFF: Error identification (see following Table)

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_FINISHED_NO_ERROR
Status: Execution finished without errors.
16#6001WARN_Y_LIMITED_TO_YMIN
Warning: Output value limited to `yMin`
16#6002WARN_Y_LIMITED_TO_YMAX
Warning: Output value limited to `yMax`
16#8200ERR_LOW_LIM_OVER_UP_LIM
Error: Lower limit value `yMin` is greater than high limit value `yMax`.

Functional description

The function linearly scales an input variable (e.g. an analog input value) to a specific output variable (e.g. level).

To determine the output variable, the following linear equation is used in the function:

x = \frac{y_2 - y_1}{x_2 - x_1} * (x - x_1) + y_1

The straight line is described by the two points, P1 and P2. You specify the points as a Cartesian coordinate system using x and y coordinates.

Note
If the values of the parameters x1 and x2 are the same, the value of y1 is output on output y.

By specifying yMin and yMax you can restrict the calculated value of y to a range limited at top and bottom. Thus, you avoid override and underride ranges.

Figure: Graphical representation

LGF_ScaleLinear - Principle of operation

Example

A signal from 4 to 20mA is applied on an analog input module. This signal is converted to the CPU internal value from 0 to 27648 to measure a level. 0 corresponds to a level of 0.0m and 27648 to a level of 1.7m.

The block must then be parameterized as follows:

Change log

Version & DateChange description
01.00.00Siemens Industry Online Support
27.01.2017First released version
01.00.01Siemens Industry Online Support
17.08.2018Upgrade: TIA V15 Update 2
01.00.02Siemens Industry Online Support
23.11.2018Upgrade: TIA V15.1
02.00.00Simatic Systems Support
25.01.2019Data type changed from Variant to LReal
02.00.01Simatic Systems Support
25.06.2019Standard header and block parameters update, status parameter added
LReal value comparison added
Result parameter changed to return value of FC for use in SCL
Warning number changed to range of 16#6xxx
refactor variable handling and extract returns in between the code
add ENO handling
03.00.00Simatic Systems Support
23.04.2020Set version to V3.0.0
harmonize the version of the whole library
03.00.01Simatic Systems Support
12.11.2020Insert documentation
Move to folder "Math operations"