×
Siemens Industry Online Support
Siemens AG
Entry type: Application example Entry ID: 8803015, Entry date: 10/15/2001
(3)
Rate

interpolating measured values with polygon and output of function values

  • Entry
  • Associated product(s)

QUESTION:
How can I realize a block in STEP 7, which executes a linear interpolation via measured values and outputs new function values based on this polygon?

ANSWER:
The blocks presented here meet the above-mentioned demands. The individual straight lines are specified by interpolation points.
The interpolation points are specified for function block FB50 as actual parameters and for function FC50 they are specified in a separate data block. The data block for the FC50 contains 2 real values (first x, then y) per interpolation point starting with the smallest x value. The actual x value is transferred to the FC/FB.

Note:
The interpolation points (x, y) must therefore be entered in ascending order of x values for both blocks.

If the value transferred is less than the smallest interpolation point x value, then the first straight line is used for the calculation; if however it is greater than the greatest interpolation point x value, then the last straight line is used for the calculation.

The function block FB50 manage a maximum of 10 interpolation points, function FC50 can manage any number (limited by the number of points that fit into a DB - for 64Kbytes = 8192 points).

Function of the block:

  1. Determine the interpolation points between which the input value is located.
  2. Do the calculation on the relevant equation of a straight line

In the figure the input value x is between interpolation points 2 and 3. Therefore the straight line defined by the points (x2,y2) and (x3,y3) is used for calculating the output value.

The formula:

y = (x-x2) / (x3-x2) * (y3-y2) + y2

Call parameters of block FB50:

Declaration

Name

Type

Comment

in

x1

REAL

Actual parameter for the first x interpolation point value

in

y1

REAL

Actual parameter for the first y interpolation point value

...

...

...

And so on to...

in

x10

REAL

Actual parameter for the tenth x interpolation point value (maximum)

in

y10

REAL

Actual parameter for the tenth y interpolation point value (maximum)

in

x

REAL

x value

in

n

INT

Number of points to be used

out

y

REAL

Result

out

error

BOOL

Remains "false" if calculation is correct

Note:
Note that the function block FB50 needs 104 bytes of temporary data, because the arrays are created in the local data area.

Call parameters of block FC50:

Declaration

Name

Type

Comment

in

Point_DB

BLOCK_DB

Value pairs are in the DB

in

x

REAL

x value

in

n

INT

Number of points to be used

out

y

REAL

Result

out

Straight line

INT

Indicates the x interpolation point value after which the x value is located

out

error

BOOL

Remains "false" if calculation is correct

The download contains the function block FB50 and the function FC50 described above.
It also includes the SCL sources as well as a sample project with a data block DB10 as instance data block for the function block FB50 and a sample call from the organization block OB1.

  polygonfb_fc_proj.exe

Copy the "polygonfb_fc_proj.exe" file into a separate directory and then start the file with a double-click. The STEP 7 V5 project then unpacks automatically with all the associated subdirectories. You can then use the SIMATIC Manager to open and process the unpacked project.

Keywords:
Approximate values, Mathematical functions

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.