129
Library of General Functions (LGF) for S7-1200/1500 STEP 7 (TIA Portal) V14 SP1 https://support.industry.siemens.com/cs/ww/en/view/109479728 Siemens Industry Online Support

Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

Library of General Functions (LGF) for S7-1200/1500

STEP 7 (TIA Portal) V14 SP1

https://support.industry.siemens.com/cs/ww/en/view/109479728

Siemens Industry Online Support

Page 2: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

Warranty and Liability

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Warranty and Liability

Note The Application Examples are not binding and do not claim to be complete with regard to configuration, equipment or any contingencies. The Application Examples do not represent customer-specific solutions. They are only intended to provide support for typical applications. You are responsible for the correct operation of the described products. These Application Examples do not relieve you of the responsibility of safely and professionally using, installing, operating and servicing equipment. When using these Application Examples, you recognize that we cannot be made liable for any damage/claims beyond the liability clause described. We reserve the right to make changes to these Application Examples at any time and without prior notice. If there are any deviations between the recommendations provided in this Application Example and other Siemens publications – e. g. catalogs – the contents of the other documents shall have priority.

We do not accept any liability for the information contained in this document. Any claims against us – based on whatever legal reason – resulting from the use of the examples, information, programs, engineering and performance data etc., described in this Application Example shall be excluded. Such an exclusion shall not apply in the case of mandatory liability, e. g. under the German Product Liability Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life, body or health, guarantee for the quality of a product, fraudulent concealment of a deficiency or breach of fundamental contractual obligations (“wesentliche Vertragspflichten”). The compensation for damages due to a breach of a fundamental contractual obligation is, however, limited to the foreseeable damage, typical for the type of contract, except in the event of intent or gross negligence or injury to life, body or health. The above provisions do not imply a change of the burden of proof to your detriment. Any form of duplication or distribution of these Application Examples or excerpts hereof is prohibited without the expressed consent of Siemens AG.

Security informa-

tion

Siemens provides products and solutions with Industrial Security functions that support the secure operation of plants, systems, machines and networks.

In order to secure plants, systems, machines and networks against cyber threats, it is necessary to implement (and to maintain continuously) a holistic, state-of-the-art Industrial Security concept. With this in mind, Siemens’ products and solutions are only part of such a concept.

It is the client’s responsibility to prevent unauthorized access to his plants, systems, machines and networks. Systems, machines and components should only be connected with the company’s network or the Internet, when and insofar as this is required and the appropriate protective measures (for example, use of firewalls and network segmentation) have been taken.

In addition, the recommendations by Siemens regarding the respective protective measures have to be observed. For more information on Industrial Security, visit http://www.siemens.com/industrialsecurity.

Siemens’ products and solutions undergo continuous development to make them even more secure. Siemens explicitly recommends to carry out updates as soon as the respective updates are available and always only to use the current product versions. Use of product versions that are no longer supported, and failure to apply latest updates may increase customer’s exposure to cyber threats.

In order to always be informed about product updates, subscribe to the Siemens Industrial Security RSS Feed at http://www.siemens.com/industrialsecurity.

Page 3: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

Table of Contents

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 3

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Table of Contents Warranty and Liability ................................................................................................. 2

1 Library Overview ................................................................................................ 5

1.1 General ................................................................................................. 5 1.2 Hardware and software requirements .................................................. 5 1.3 Library resources .................................................................................. 6

2 Working with the Library................................................................................... 8

2.1 General ................................................................................................. 8 2.2 Simulatability with SIMATIC S7-PLCSIM Advanced (NEW) ................ 9

3 Explanation of the Blocks ............................................................................... 11

3.0 Bit logic operations ............................................................................. 12 3.0.1 FB LGF_PulseRelay ........................................................................... 12 3.1 Date and timer operations .................................................................. 14 3.1.1 FB LGF_Astro (correction) ................................................................. 14 3.1.2 FB LGF_SetTime ............................................................................... 18 3.1.3 FB LGF_TimerSwitch (correction) ...................................................... 21 3.1.4 FC LGF_CalendarDayWeek .............................................................. 24 3.1.5 FC LGF_GermanHoliday (NEW) ........................................................ 26 3.2 Counter operations ............................................................................. 28 3.2.1 FC LGF_CountFalInDWord ................................................................ 28 3.2.2 FC LGF_CountRisInDWord................................................................ 30 3.3 Comparator operations ....................................................................... 32 3.3.1 FC LGF_CompareVariant .................................................................. 32 3.3.2 FC LGF_CompareReal ...................................................................... 34 3.4 Math operations .................................................................................. 36 3.4.1 FC LGF_AverageAndDeviation .......................................................... 36 3.4.2 FB LGF_FloatingAverage................................................................... 38 3.4.3 FC LGF_MatrixAddition ...................................................................... 40 3.4.4 FC LGF_MatrixInverse ....................................................................... 42 3.4.5 FC LGF_MatrixMultiplication .............................................................. 44 3.4.6 FC LGF_MatrixSubtraction................................................................. 46 3.4.7 FC LGF_MatrixTranspose .................................................................. 48 3.4.8 FB LGF_MinMaxHistory ..................................................................... 49 3.4.9 FC LGF_RandomBasic ...................................................................... 50 3.4.10 FC LGF_RandomINT / LGF_RandomReal ........................................ 51 3.4.11 FC LGF_SearchMinMax ..................................................................... 53 3.4.12 FC LGF_XRoot ................................................................................... 55 3.4.13 FC LGF_HighLowLimit ....................................................................... 56 3.4.14 FB LGF_Integration ............................................................................ 58 3.4.15 FC LGF_Factorial (NEW) ................................................................... 60 3.4.16 FC LGF_Distance (NEW) ................................................................... 61 3.5 Data handling ..................................................................................... 62 3.5.1 FB LGF_FIFO ..................................................................................... 62 3.5.2 FB LGF_LIFO (NEW) ......................................................................... 65 3.5.3 FB LGF_RingBuffer (NEW) ................................................................ 68 3.5.4 FB LGF_ShellSortInt / LGF_ShellSortUInt / LGF_ShellSortReal....... 70 3.5.5 FC LGF_CRC8 (NEW) ....................................................................... 72 3.5.6 FC LGF_CRC8For1Byte (NEW) ........................................................ 73 3.5.7 FC LGF_CRC16 (NEW) ..................................................................... 74 3.5.8 FC LGF_CRC32 (NEW) ..................................................................... 75 3.6 Converter operations .......................................................................... 77 3.6.1 FC LGF_BinaryToGray ...................................................................... 77 3.6.2 FC LGF_GrayToBinary ...................................................................... 78 3.6.3 FC LGF_BitsToWord .......................................................................... 79

Page 4: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

Table of Contents

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 4

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.4 FC LGF_WordToBits .......................................................................... 80 3.6.5 FC LGF_DTLtoString ......................................................................... 81 3.6.6 FC LGF_StringToDTL ........................................................................ 83 3.6.7 FC LGF_TemperatureConvert ........................................................... 85 3.6.8 FC LGF_ScaleLinear .......................................................................... 86 3.6.9 FC LGF_StringToTaddr ...................................................................... 89 3.6.10 FC LGF_TaddrToString ...................................................................... 91 3.6.11 FC LGF_IntToString (NEW) ............................................................... 92 3.6.12 FC LGF_TimeToString (NEW) ........................................................... 93 3.7 Signal generators ............................................................................... 94 3.7.1 FB LGF_Frequency ............................................................................ 94 3.7.2 FB LGF_Impulse ................................................................................ 96 3.7.3 FB LGF_SawTooth ............................................................................. 97 3.7.4 FB LGF_SawToothCI (NEW) ............................................................. 99 3.7.5 FB LGF_TriangleCI (NEW) .............................................................. 101 3.7.6 FB LGF_RectangleCI (NEW) ........................................................... 103 3.7.7 FB LGF_SinusCI (NEW) .................................................................. 105 3.7.8 FB LGF_CosinusCI (NEW) .............................................................. 107 3.8 Technology operations ..................................................................... 109 3.8.1 FB LGF_LimRateOfChangeBasic .................................................... 109 3.8.2 FB LGF_LimRateOfChangeAdvanced ............................................. 112 3.8.3 FB LGF_Ramp ................................................................................. 117 3.8.4 FB LGF_NonLin ............................................................................... 122 3.8.5 Closed-Loop Control of Simulated Controlled Systems ................... 124

4 Links & Literature .......................................................................................... 125

5 History............................................................................................................. 126

5.1 Library versioning ............................................................................. 126 5.2 Change log ....................................................................................... 127

Page 5: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

1 Library Overview

1.1 General

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 5

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

1 Library Overview

1.1 General

TIA Portal includes a vast number of "ready-to-use" instructions (mathematical functions, times, counters etc.). Moreover, it offers other useful basic functions.

These functions are provided as a library and can be used freely. The ready-to-use functions are freely adjustable and thus can be used universally.

The library described here is versioned and continuously expanded. Information on the version system can be found in chapter 5.1 Library versioning.

1.2 Hardware and software requirements

Requirements for this library

To make use of the full functionality of the library described here, the hardware and software requirements listed below must be met.

Hardware

All blocks (FB, FC, DB,…) in the library can be used universally with the following controllers:

S7-1200 and S7-1200 F product families

S7-1500 and S7-1500 F product families

Simulation with S7-PLCSIM (as of V14)

Software

STEP 7 (TIA Portal) Basic or Professional as of V14

Note In general, it is possible to open a library using STEP 7 Basic, although elements of STEP 7 Professional (e. g. S7-1500 controllers) are included. In this case, you will be informed via a message when opening the library.

All elements (types and master copies) can be used if they are supported by the hardware installed in TIA Portal.

If you try to copy elements with STEP 7 Basic from the library that are not supported (e. g. S7-1500 controllers), an error message will be displayed.

Page 6: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

1 Library Overview

1.3 Library resources

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 6

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

1.3 Library resources

The following section gives you an overview of the space of the load and main memory used by the library blocks.

Assignment of memory space to the individual blocks

Table 1-1: Memory assignment (CPU 1212 DC/DC/DC V4.2, CPU 1511-1 PN V2.0)

Block CPU 1212 assignment (bytes)

CPU 1511 assignment (bytes)

Load memory

Main memory

Load memory

Main memory

Bit logic operations

FB LGF_PulseRelay V1.0.2 7295 201 7367 302

Date and timer operations

FB LGF_Astro V1.1.5 49620 3593 49752 3672

FB LGF_SetTime V1.0.2 26835 2231 27040 2301

FB LGF_TimerSwitch V1.1.3 38012 4525 38055 4635

FC LGF_CalendarDayWeekV1.0.0 21867 1751 22071 1826

FC LGF_GermanHoliday V1.0.0 18024 956 18009 1020

Counter operations

FC LGF_CountFalInDWord V1.0.1 14890 1124 14896 1188

FC LGF_CountRisInDWord V1.0.1 14759 1124 14766 1188

Comparator operations

FC LGF_CompareVariant V1.0.2 10955 620 10966 684

FC LGF_CompareReal V1.0.0 6281 118 6302 182

Math operations

FC LGF_AverageAndDeviation V1.0.2 29602 3194 29614 3258

FB LGF_FloatingAverage V1.1.0 16590 748 16506 830

FC LGF_MatrixAddition V2.0.0 11514 489 11556 553

FC LGF_MatrixInverse V2.0.0 15936 1017 15976 1081

FC LGF_MatrixMultiplication V2.0.0 12172 546 12213 610

FC LGF_MatrixSubtraction V2.0.0 11545 489 11590 553

FC LGF_MatrixTranspose V2.0.0 9971 383 10010 447

FB LGF_MinMaxHistory V1.0.1 6150 114 6144 178

FC LGF_RandomBasic V1.0.0 6844 191 6868 255

FC LGF_RandomInt V1.0.1 9104 241 9115 305

FB LGF_RandomReal V1.0.2 9528 281 9550 345

FC LGF_SearchMinMax V1.0.1 36145 4642 36195 4706

FC LGF_XRoot V1.0.1 4688 49 4693 113

FC LGF_HighLowLimit V1.0.0 8978 262 9015 334

FC LGF_Integration V1.0.0 11058 323 11073 393

FC LGF_Factorial V1.0.0 6280 145 6293 209

FC LGF_Distance V1.0.0 5226 75 5171 127

Page 7: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

1 Library Overview

1.3 Library resources

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 7

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Block CPU 1212 assignment (bytes)

CPU 1511 assignment (bytes)

Load memory

Main memory

Load memory

Main memory

Data handling

FB LGF_FIFO V1.0.2 20681 1688 20773 1784

FB LGF_LIFO V1.0.0 18620 1547 18713 1639

FB LGF_RingBuffer V1.0.2 9477 345 9564 417

FB LGF_ShellSortInt V1.1.1 18458 1458 18526 1540

FB LGF_ShellSortUint V1.1.1 18563 1458 18637 1540

FB LGF_ShellSortReal V1.1.1 18484 1458 18530 1540

FC LGF_CRC8 V1.0.0 7173 202 7205 266

FC LGF_CRC8For1Byte V1.0.0 5655 103 5652 167

FC LGF_CRC16 V1.0.0 7525 221 7506 285

FC LGF_CRC32 V1.0.0 15939 855 15867 919

Converter operations

FC LGF_BinaryToGray V1.0.2 4327 36 4335 100

FC LGF_GrayToBinary V1.0.2 11803 872 11809 936

FC LGF_BitsToWord V1.0.0 6052 186 6079 250

FC LGF_WordToBits V1.0.0 6226 175 6250 239

FC LGF_DTLtoString V1.0.1 16403 876 16395 935

FC LGF_StringToDTL V1.0.1 19911 1116 19886 1139

FC LGF_TemperatureConvert V1.0.1 6644 242 6624 306

FC LGF_ScaleLinear V1.0.0 29123 4443 29144 4507

FC LGF_StringToTaddr V1.0.0 21707 883 21715 941

FC LGF_TaddrToString V1.0.0 10780 388 10825 447

FC LGF_IntToString V1.0.0 6137 146 6133 205

FC LGF_TimeToString V1.0.0 13676 1064 13687 1123

Signal generators

FB LGF_Frequency V1.1.2 10878 345 10871 412

FB LGF_Impulse V1.2.0 7730 131 7719 200

FB LGF_SawTooth V1.0.2 10137 249 10179 320

FB LGF_SawToothCI V1.0.0 9912 276 9903 347

FB LGF_TriangleCI V1.0.0 10541 364 10656 435

FB LGF_RectangleCI V1.0.0 9841 260 9915 331

FB LGF_SinusCI V1.0.0 10080 286 10123 357

FB LGF_CosinusCI V1.0.0 10157 286 10168 357

Technology operations

FB LGF_LimRateOfChangeBasic V1.0.1 11985 357 12022 430

FB LGF_LimRateOfChangeAdvanced V1.0.1 24401 1474 24704 1706

FB LGF_Ramp V1.0.1 27084 1440 27144 1517

FB LGF_NonLin V1.0.0 12901 564 13014 640

Page 8: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

2 Working with the Library

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 8

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

2 Working with the Library

2.1 General

All blocks in the "LGF" library are unrestricted in connection with S7-1200 and S7-1500 controllers.

Most of the blocks are stored in the library as types. Thus, the blocks are versioned and thus can benefit from all advantages.

Central update function of library elements

Versioning of library elements

Note Information on how to work with libraries is available in the Guideline on Library Handling

https://support.industry.siemens.com/cs/ww/en/view/109747503

and in the “Programming Guideline for S7-1200/1500” in chapter “Libraries”.

https://support.industry.siemens.com/cs/ww/en/view/81318674

Note All blocks in the LGF have been created according to the Programming Styleguide.

https://support.industry.siemens.com/cs/ww/en/view/81318674

Further information on libraries in TIA Portal:

Topic page libraries https://support.industry.siemens.com/cs/ww/en/view/109738702

How can I open libraries in STEP 7 (TIA Portal)? https://support.industry.siemens.com/cs/ww/en/view/37364723

Automation Tasks in 10 minutes or less TIA Portal: Time Savers – Global Libraries https://support.industry.siemens.com/cs/ww/en/view/78529894

Which elements of STEP 7 (TIA Portal) can you store in a library as Type or as Master Copy? https://support.industry.siemens.com/cs/ww/en/view/109476862

When starting TIA Portal V13 onwards, how do you get a global library to open automatically and use it as corporate library, for example? https://support.industry.siemens.com/cs/ww/en/view/100451450

Page 9: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

2 Working with the Library

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 9

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

2.2 Simulatability with SIMATIC S7-PLCSIM Advanced (NEW)

To make sure that the blocks can be simulated with SIMATIC S7-PLCSIM Advanced after compiling, proceed as follows:

1. Open the properties of your project, go to the “Protection” tab and enable the option "Support simulation during block compilation”.

2. In your project, right-click a block (e. g. “LGF_FIFO”) in the project library and select "Edit type”.

A new version of the block is created,

3. Compile the project.

Page 10: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

2 Working with the Library

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 10

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

In the properties of the block (e. g. “LGF_FIFO”), the option "Can be simulated with SIMATIC S7-PLCSIM (Advanced)” is enabled automatically.

4. After loading, the block can be simulated with SIMATIC S7-PLCSIM Advanced.

5. In the project library, right-click the new version “[in test]”.

– If, after simulation, you want to keep the original version, select "Discard changes and delete version". Thus, you stay compatible with the LGF library.

– If, nevertheless, you want to keep the new version, select "Release version".

Note Blocks with enabled simulatability require more memory space in the PLC.

Page 11: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 11

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3 Explanation of the Blocks The following chapters list all blocks of the "Library of General Functions" library. The chapters are structured similarly to the library itself.

All blocks are divided into areas of application or categories:

Bit logic operations

Date and timer operations

Counter operations

Comparator operations

Math operations

Data handling

Converter operations

Signal generators

Technology operations

Figure 3-1: Global library (LGF)

Page 12: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.0 Bit logic operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 12

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.0 Bit logic operations

3.0.1 FB LGF_PulseRelay

Short description

This block corresponds to a current surge relay or a toggle flip-flop including set and reset input.

Block

Figure 3-2: FB LGF_PulseRelay

FB LGF_PulseRelay

BOOL trigger out BOOL

BOOL set

BOOL reset

Input parameters

Table 3-1: Input parameters

Parameter Data type Description

trigger BOOL Every rising edge changes the Boolean value of the output “out”.

set BOOL Every rising edge sets the Boolean value of the output “out” to “TRUE”.

reset BOOL Every rising edge sets the Boolean value of the output “out” to “FALSE”.

Output parameters

Table 3-2: Output parameters

Parameter Data type Description

out BOOL Signal output

Page 13: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.0 Bit logic operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 13

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

Figure 3-3: LGF_PulseRelay signal diagram

trigger

1 1

set

2

reset

3 4

out

Time

1. Every rising edge of the input “trigger” changes the Boolean value of the output “out”.

2. Every rising edge of the input “set” sets the Boolean value of the output “out” to “TRUE”.

3. Every rising edge of the input “reset” sets the Boolean value of the output “out” to “FALSE”.

4. If the inputs “set” and “reset” are set in the same cycle, the “reset” input has priority.

The block can also be used as frequency divider. If the input “trigger” is supplied with a fixed frequency, the output “out” provides half the frequency.

Page 14: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 14

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.1 Date and timer operations

3.1.1 FB LGF_Astro (correction)

Short description

This block calculates the times of sunrise and sunset for a specific place on earth. The exact position is transferred to the block as geographical coordinates (longitude and latitude).

Figure 3-4: Earth with lines of longitude and latitude

North poleLongitude

60°

120° 60° 0°Zero meridian

60° 120°30°

North (+)

South (-)

Equator LatitudeWest (-) East (+)

30°

60°South pole

Information regarding the “Time synchronization” topic is available in the following entry: https://support.industry.siemens.com/cs/ww/en/view/86535497

Block

Figure 3-5: FB LGF_Astro

FB LGF_Astro

REAL latitudeDD sunrise DTL

REAL longitudeDD sunset DTL

BOOL modeDMS daytime BOOL

LGF_typeAstroDMS latitudeDMS actSystemTime DTL

LGF_typeAstroDMS longitudeDMS actLocalTime DTL

TIME offsetSunrise error BOOL

TIME offsetSunset statusID UINT

status WORD

Page 15: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 15

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Input parameters

Table 3-3: Input parameters

Parameter Data type Description

latitudeDD REAL Latitude in degrees with decimal places (unit: degrees decimal),

valid range of values [-90.00000..+90.00000]°

This is a common coordinate format in GPX files (GPS).

longitudeDD REAL Longitude in degrees with decimal places (unit: degrees decimal)

1,

valid range of values [-180.0000..+180.0000]°

modeDMS BOOL 1. Transfer format of the position in “degrees decimal" via the formal parameters "latitudeDD" and "longitudeDD"

1. Transfer format of the position in direction, degrees, minutes and seconds via the formal parameters “latitudeDMS" and “longitudeDMS"

latitudeDMS LGF_typeAstroDMS Latitude in compass direction; degrees; minutes and seconds in the PLC data type "LGF_typeAstroDMS". valid parameter values [N, S]; [0..90]; [0..59]; [0..59] valid range of values (total of parameter values) [N, S, n, s]; [0..90]°

This is a common coordinate format for navigation with maps.

longitudeDMS LGF_typeAstroDMS Longitude in direction; degrees; minutes and seconds in the PLC data type "LGF_typeAstroDMS". valid parameter values [E, W]; [0..180]; [0..59]; [0..59] valid range of values (total of parameter values) [E, W, e, w]; [0..180]°

“E” (East) is the international abbreviation for the East.

offsetSunrise TIME Offset of the switch-on time for "daytime"

offsetSunset TIME Offset of the switch-off time for "daytime"

Output parameters

Table 3-4: Output parameters

Parameter Data type

Description

sunrise DTL Sunrise at the specified location taking into account the "offsetSunrise"

sunset DTL Sunset at the specified location taking into account the “offsetSunset"

daytime BOOL If the local time of the controller is between "sunrise" and "sunset", "daytime" provides the value "TRUE".

actSystemTime DTL Current system time (UTC)

actLocalTime DTL Current local time

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Page 16: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 16

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-5: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8200 Wrong direction displayed at input "latitudeDMS.dir"

Only the following letters are allowed: N, n, S, s, W, w, E, e

1 16#8201 Wrong values for "latitudeDMS" Check the values for

"latitudeDMS.deg"

"latitudeDMS.min"

"latitudeDMS.sec"

1 16#8202 Wrong direction displayed for "longitudeDMS.dir"

Only the following letters are allowed: N, n, S, s, W, w, E, e

1 16#8203 Wrong values for “longitudeDMS" Check the values for

"longitudeDMS.deg"

"longitudeDMS.min"

"longitudeDMS.sec"

1 16#8204 Wrong value at input "latitudeDD" Check the actual value at the input.

1 16#8205 Wrong value at input “longitudeDD" Check the actual value at the input.

2 - Error/status of subordinate block "RD_SYS_T".

-

3 - Error/status of subordinate block “RD_LOC_T".

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

If processes shall be automated depending on the change between day and night, the function of an astronomic clock is required. This applies e. g. to switching on/off an outdoor lighting or opening/closing roller shutters.

If these processes shall be carried out with a time delay, i. e. at a defined time before or after sunrise or sunset, an offset will be required additionally.

Note For this function being carried out precisely, it has to be ensured that the system time and the local time of the SIMATIC controller are set correctly.

The block calculates the times for sunrise and sunset based on the system time/local time of the SIMATIC controller and the set coordinates. The offset times are added to the sunrise and sunset and are output at the outputs "sunrise" and "sunset". If the system time of the SIMATIC controller is between these values, the output "daytime" will be set to the value "TRUE".

Page 17: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 17

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Note As the times for sunrise and sunset are changing every day, it might be that the output "daytime" remains set to "TRUE" or "FALSE" for a longer period of time:

in case of correspondingly high offset values

for locations beyond the polar circle

The coordinates can be entered in the format "DMS" (with PLC data type "LGF_typeAstroDMS") or “Degree.Decimal".

You can use the formal parameter "modeDMS" to define which format is active (see Table 3-3).

The coordinate values entered are checked for valid values. In case of invalid values, a corresponding error code is output to "status" (see Table 3-5).

If an invalid coordinate value is present at a formal parameter and this formal parameter has been activated via "modeDMS", the outputs "sunrise" and "sunset" will be set to the value DTL#1970-01-01-00:00:00.

Example

The following example illustrates the function principle of the block.

Table 3-6: Geographic coordinates for Nuremberg-Moorenbrunn, date and system time

Longitude: + 11.07675° or E 11° 4' 36''

Latitude: + 49.45203° or N 49° 27' 7''

Date: 07/07/2016 Local time:

09:20 AM

Figure 3-6: FB LGF_Astro, monitoring the block online using the parameters as well as the actual parameters via the watch table

Page 18: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 18

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.1.2 FB LGF_SetTime

Short description

This block combines the functions System time, Local time and Set time zone.

Block

Figure 3-7: FB LGF_SetTime

FB LGF_SetTime

BOOL setSystemTimeUTC actSystemTime DTL

DTL systemTimeUTC actLocalTime DTL

BOOL setLocalTime lastSetTimeZone STRING

DTL localTime error BOOL

BOOL setTimeZone statusID UINT

INT timeZone status WORD

BOOL daylightSavingTime

Input parameters

Table 3-7: Input parameters

Parameter Data type Description

setSystemTimeUTC BOOL Rising edge sets the defined system time at the input "systemTimeUTC"

systemTimeUTC DTL Defined system time, corresponds to UTC (Coordinated Universal Time)

setLocalTime BOOL Rising edge takes on the defined local time at the input "localTime"

localTime DTL Defined local time

setTimeZone BOOL Rising edge takes on

the value at the input "timeZone"

the value at the input "daylightSavingTime"

timeZone INT Defined time zone (format [+-HHMM]

Examples:

UTC -12:00 [-1200]

UTC -03:30 [-330]

UTC [0]

UTC +13:00 [1300]

daylightSavingTime BOOL TRUE: Daylight saving time switchover activated (local time + 60 min)

– from last Sunday in March at 02:00 a.m.

– to last Sunday in October at 03:00 a.m.

FALSE: no daylight saving time switchover

Page 19: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 19

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-8: Output parameters

Parameter Data type Description

systemTime DTL Current system time (UTC)

localTime DTL Current local time

lastSetTimeZone STRING Time zone last set by the block

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-9: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8200 No valid time zone has been transferred at the input "timeZone".

Use allowed values only (see function principle).

2 - Error/status of subordinate block “SET_TIMEZONE".

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

This block combines the functions System time, Local time and Set time zone.

The following time zones can be set at the input "timeZone".

Input "timeZone"

Time zone

-1200 (UTC -12:00) Eniwetok, Kwajalein

-1100 (UTC -11:00) Midway Island

-1000 (UTC -10:00) Hawaii

-930 (UTC -09:30) (French) Polynesia

-900 (UTC -09:00) Alaska

-800 (UTC -08:00) Tijuana, Los Angeles, Seattle, Vancouver

-700 (UTC -07:00) Arizona, Denver, Salt Lake City, Calgary

-600 (UTC -06:00) Chicago, Dallas, Kansas City, Winnipeg

-500 (UTC -05:00) Eastern Time (USA & Canada)

-400 (UTC -04:00) La Paz, Georgetown

Page 20: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 20

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Input "timeZone"

Time zone

-330 (UTC -03:30) Newfoundland

-300 (UTC -03:00) Brasilia, Buenos Aires

-200 (UTC -02:00) Mid-Atlantic

-100 (UTC -01:00) Azores, Cape Verde Is.

0 (UTC) Dublin, Edinburgh, Lisbon, London

100 (UTC +01:00) Berlin, Bern, Brussels, Rome, Stockholm, Vienna

200 (UTC +02:00) Athens, Istanbul, Minsk, Bucharest

300 (UTC +03:00) Baghdad, Kuwait, Riyadh

330 (UTC +03:30) Iran

400 (UTC +04:00) Moscow, St. Petersburg, Volgograd, Abu Dhabi, Muscat

430 (UTC +04:30) Afghanistan

500 (UTC +05:00) Islamabad, Karachi, Tashkent

530 (UTC +05:30) India, Sri Lanka

545 (UTC +05:45) India, Sri Lanka

600 (UTC +06:00) Astana, Almaty, Dhaka, Colombo

630 (UTC +06:30) Coco Island, Myanmar

700 (UTC +07:00) Bangkok, Hanoi, Jakarta

800 (UTC +08:00) Beijing, Chongqing, Hong Kong, Urumqi

830 (UTC +08:30) North Korea

900 (UTC +09:00) Yakutsk, Osaka, Sapporo, Tokyo, Seoul

930 (UTC +09:30) Australia: Northern Territory, South Australia

1000 (UTC +10:00) Brisbane, Canberra, Melbourne, Sydney

1030 (UTC +10:30) Australia: Lord Howe Island

1100 (UTC +11:00) Vladivostok, Magadan, Solomon Is., New Caledonia

1200 (UTC +12:00) Auckland, Wellington

1245 (UTC +12:45) Chatham Islands

1300 (UTC +13:00) Kiribati

Note Daylight saving time/standard time

The parameters (time difference, start of daylight saving time, start of standard time) can be adjusted in the static tag "statTimeZone".

Default values of the static tag "statTimeZone":

Time difference: 60 min

Start of daylight saving time: Last Sunday in March, 02:00 a.m.

Start of standard time: Last Sunday in October, 03:00 a.m.

Page 21: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 21

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.1.3 FB LGF_TimerSwitch (correction)

Short description

This block is a timer. It allows to define daily, weekly, monthly, annual time switch points as well as time switch points for weekdays or weekend days.

Block

Figure 3-8: FB LGF_TimerSwitch

FB LGF_TimerSwitch

USINT onMonth signal BOOL

USINT onDay actLocalTime DTL

USINT onWeekday error BOOL

USINT onWeekOfMonth statusID UINT

USINT onHour status WORD

USINT onMinute

USINT offMonth

USINT offDay

USINT offWeekday

USINT offWeekOfMonth

USINT offHour

USINT offMinute

USINT mode

Input parameters

Table 3-10: Input parameters

Parameter Data type Description

onMonth USINT Month in which the signal is to be set.

onDay USINT Day on which the signal is to be set.

onWeekday USINT Weekday on which the signal is to be set. (Sunday = 1)

onHour USINT Hour in which the signal is to be set.

onMinute USINT Minute in which the signal is to be set.

offMonth USINT Month in which the signal is to be reset.

offDay USINT Day on which the signal is to be reset.

offWeekday USINT Weekday on which the signal is to be reset. (Sunday = 1)

offHour USINT Hour in which the signal is to be reset.

offMinute USINT Minute in which the signal is to be reset.

mode USINT Mode indication (see function principle).

Page 22: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 22

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-11: Output parameters

Parameter Data type Description

signal BOOL Output signal

actLocalTime DTL Current local time

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-12: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8200 No valid actual value has been transferred to the "mode" input.

Allowed values "1", "2", "3" "4", "5", "6"

2 - Error/status of subordinate block “RD_LOC_T"

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

The block offers different types of a timer that can be determined in the parameter "mode":

Daily timer (mode = 1)

Weekly timer (mode = 2)

Monthly timer (mode = 3)

Annual timer (mode = 4)

Weekdays, Monday to Friday (mode = 5)

Weekend, Saturday and Sunday (mode = 6)

Page 23: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 23

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Depending on the mode, the following formal parameters must be interconnected:

Table 3-13: Formal parameters required for the respective mode

Mode Required formal parameters

Daily timer

(mode = 1)

onHour / offHour

onMinute / offMinute

Weekly timer

(mode = 2)

onWeekday / offWeekday

onHour / offHour

onMinute / offMinute

Monthly timer

(mode = 3)

onDay / offDay

onHour / offHour

onMinute / offMinute

Annual timer

(mode = 4)

onMonth / offMonth

onDay / offDay

onHour / offHour

onMinute / offMinute

On workdays (mode = 5)

onHour / offHour

onMinute / offMinute

Weekend (mode = 6)

onHour / offHour

onMinute / offMinute

If the set start time corresponds to the current local time of the controller, the output "signal" will be set to "TRUE". If the set switch-off time corresponds to the current local time of the controller, the output "signal" will be reset.

Hinweis Note that the block in the modes “Monthly timer“ (mode = 3) or “Annual timer“ (mode = 4) is only triggered if the days you assign to the input parameters “onDay” and “offDay” actually exist in that month.

Page 24: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 24

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.1.4 FC LGF_CalendarDayWeek

Short description

This function uses the specified date to calculate the calendar week and the number of days that have passed since the beginning of the year.

Block

Figure 3-9: FC LGF_ CalendarDayWeek

FC LGF_ CalendarDayWeek

DTL inDate daysPassed DINT

BOOL modeEU weekNumber DINT

error BOOL

status WORD

Input parameters

Table 3-14: Input parameters

Parameter Data type Description

inDate DTL Date for calculating the calendar week and the days that have passed since January 1

st.

modeEU BOOL Selection of the counting method for calendar weeks.

0: Counting method for the USA and many other countries

1: Counting method for European countries according to ISO 8601

Output parameters

Table 3-15: Output parameters

Parameter Data type Description

daysPassed DINT Days that have passed since January 1st.

weekNumber DINT Number of the calendar week.

error BOOL Error display

0: No error.

1: Block error, "status" outputs the error code.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-16: Status/error codes

Status Meaning Remedy

16#0000 No errors. -

16#8201 Date at the input "inDate" for below the lower limit.

Select "inDate" greater than 1971-01-01.

16#8202 Date at the input "inDate" for above the upper limit.

Select "inDate" less than 2261-12-31.

Page 25: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 25

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

Two counting methods are available for determining the calendar week for the stated date. Use the input "modeEU" to select the counting method:

modeEU = 0: Counting method for the USA and many other countries

modeEU = 1: Counting method for European countries according to ISO 8601

Counting method for European countries according to ISO 8601

Calendar weeks consist of 7 days, start with a Monday and are numbered consecutively throughout the year.

Calendar week 1 of a year is the week containing the first Thursday.

Every year has 52 or 53 calendar weeks.

A year has 53 calendar weeks if the following properties apply:

– A common year starts on a Thursday and ends on a Thursday.

– A leap year either starts on a Wednesday and ends on a Thursday or starts on a Thursday and ends on a Friday.

December 29th, 30

th and 31

st may already belong to the first calendar week of

the following year.

January 1st, 2

nd and 3

rd may still belong to the last calendar week of the

previous year.

Counting method for the USA and many other countries

Calendar weeks consist of 7 days, start with a Sunday and are numbered consecutively throughout the year.

Calendar week 1 of a year is the week containing January 1st.

Every year has 52 or 53 calendar weeks.

A year has 53 calendar weeks if the following properties apply:

– A common year starts on a Saturday and ends on a Saturday.

– A leap year either starts on a Saturday and ends on a Sunday or starts on a Friday and ends on a Saturday.

The days following the last Thursday in December may already belong to the first calendar week of the following year.

Page 26: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 26

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.1.5 FC LGF_GermanHoliday (NEW)

Short description

The FC LGF_GermanHoliday determines whether a given date is a holiday. All holidays in Germany are taken into account. Holidays that are not uniform throughout Germany can be switched on and off.

Block

Figure 3-10: FB LGF_GermanHoliday

FC LGF_GermanHoliday

DTL date Ret_Val BOOL

BOOL threeKings

BOOL roseMonday

BOOL ascension

BOOL corpusChristi

BOOL augsburgerFriedensfest

BOOL assumptionOfMary

BOOL reformationDay

BOOL allSaintDay

BOOL bussUndBettag

Input parameters

Table-17: Input parameters

Parameter Data type Description

date DTL Date that is checked with regard to a holiday.

threeKings BOOL Epiphany

roseMonday BOOL Rose Monday

ascension BOOL Ascension Day

corpusChristi BOOL Feast of Corpus Christi

augsburgerFriedensfest BOOL “Augsburger Friedensfest”

assumptionOfMary BOOL Assumption Day

reformationDay BOOL Reformation Day

allSaintDay BOOL All Saints’ Day

bussUndBettag BOOL Penance Day

Output parameters

Table 3: Output parameters

Parameter Data type Description

Ret_Val BOOL With TRUE, the date at the input parameter "date" is a holiday.

Page 27: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.1 Date and timer operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 27

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

The block calculates for a given date the holiday calendar of the year and indicates whether the given date is a holiday. Optionally, it is possible to take into account holidays that are not uniform throughout Germany, such as e. g. Epiphany, via the corresponding input parameter of the block.

Page 28: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.2 Counter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 28

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.2 Counter operations

3.2.1 FC LGF_CountFalInDWord

Short description

This block analyzes a tag of the type DWORD and outputs how often a sequence of 1-0 (falling edge) occurs in the tag.

Application example

Extract from the technology module TM Timer DIDQ 16x24V

With the oversampling function, the technology module detects the status of the respective digital input for each application cycle (e. g. OB61) at 32 point in time in a regular time intervals. The 32 status are returned together as a 32-bit value in the feedback interface.

Figure 3-11: Example of an oversampling of DI0 at the TM Timer DIDQ 16x24V

In this case, the block LGF_CountFalInDWord is used for counting how often a falling edge occurs.

SIMATIC ET 200MP/S7-1500 technology module TM Timer DIDQ 16x24V (6ES7552-1AA00-0AB0)

https://support.industry.siemens.com/cs/ww/en/view/95153313

Block

Figure 3-12: FC LGF_CountFalInDWord

FC LGF_CountFalInDWord

DWORD dWordActCycle Ret_Val INT

DWORD dWordPrevCycle

Input parameters

Table 3-18: Input parameters

Parameter Data type Description

dWordActCycle DWORD Double word in which the falling edges are counted

dWordPrevCycle DWORD Double word from the previous cycle

Page 29: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.2 Counter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 29

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-19: Output parameters

Parameter Data type Description

Ret_Val INT Number of falling edges in the double word

Function principle

In a tag of data type DWORD, the block counts the falling edges (1-0 transitions) from left to right. For this, the output "Ret_Val" outputs the number of falling edges.

To ensure that also falling edges at the tag limits are detected, the input "dWordPrevCycle" has to be interconnected with the tag of the previous cycle.

Example

The following example illustrates the function principle of the block. In this case, it is assumed that a signal of unknown length is scanned in the form of double words (DWORD) for each cycle.

Within this signal, the 1-0 sequences (falling edges) shall be counted and output continuously. To ensure that – like in this example – the falling edges at the tag limits are detected, the input "dWordPrevCycle" has to be interconnected with the double word of the previous scan.

Table 3-20: Example

DWORD of previous cycle (dWordPrevCycle)

DWORD of current cycle (dWordActCycle)

1001_0000_0001_1010_1001_0000_0001_1011 0010_1010_0001_1111_0100_0011_1000_0101

Number of 1-0 sequences (falling edges): "Ret_Val" = 8

Page 30: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.2 Counter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 30

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.2.2 FC LGF_CountRisInDWord

Short description

This block analyzes a tag of the type DWORD and outputs how often a sequence of 0-1 (rising edge) occurs in the tag.

Application example:

Extract from the technology module TM Timer DIDQ 16x24V:

With the oversampling function, the technology module detects the status of the respective digital input for each application cycle (e. g. OB61) at 32 point in time in a regular time intervals. The 32 status are returned together as a 32-bit value in the feedback interface.

Figure 3-13: Example of an oversampling of DI0 at the TM Timer DIDQ 16x24V

In this case, the block LGF_CountRisInDWord is used for counting how often a rising edge occurs.

SIMATIC ET 200MP/S7-1500 technology module TM Timer DIDQ 16x24V (6ES7552-1AA00-0AB0)

https://support.industry.siemens.com/cs/ww/en/view/95153313

Block

Figure 3-14: FC LGF_CountRisInDWord

FC LGF_CountRisInDWord

DWORD dWordActCycle Ret_Val INT

DWORD dWordPrevCycle

Input parameters

Table 3-21: Input parameters

Parameter Data type Description

dWordActCycle DWORD Double word in which the rising edges are counted

dWordPrevCycle DWORD Double word from the previous cycle

Page 31: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.2 Counter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 31

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-22: Output parameters

Parameter Data type Description

Ret_Val INT Number of rising edges in the double word

Function principle

In a tag of data type DWORD, the block counts the rising edges (0-1 transitions) from left to right. For this, the output "Ret_Val" outputs the number of rising edges.

To ensure that also rising edges at the tag limits are detected, the input "dWordPrevCycle" has to be interconnected with the tag of the previous cycle.

Example

The following example illustrates the function principle of the block. In this case, it is assumed that a signal of unknown length is scanned in the form of double words (DWORD) for each cycle.

Within this signal, the 0-1 sequences (rising edges) shall be counted and output continuously. To ensure that – like in this example – the rising edges at the tag limits are detected, the input "dWordPrevCycle" has to be interconnected with the double word of the previous scan.

Table 3-23: Example

DWORD of previous cycle (dWordPrevCycle)

DWORD of current cycle (dWordActCycle)

1001_0000_0001_1010_1001_0000_0001_1010 1010_1010_0001_1111_0100_0011_1000_0101

Number of 0-1 sequences (rising edges): "Ret_Val" = 9

Page 32: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.3 Comparator operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 32

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.3 Comparator operations

3.3.1 FC LGF_CompareVariant

Short description

This block compares two structured (array, PLC data type) actual parameters and outputs whether they correspond to the same type and have the same values.

Block

Figure 3-15: FC LGF_CompareVariant

FC LGF_CompareVariant

VARIANT variable1 (InOut) Ret_Val BOOL

VARIANT variable2 (InOut) error BOOL

statusID UINT

status WORD

Input/output parameters (InOut)

Table 3-24: Input/output parameters (InOut)

Parameter Data type Description

variable1 VARIANT Comparator tag with any data type

variable2 VARIANT Comparator tag with any data type

Output parameters

Table 3-25: Output parameters

Parameter Data type Description

Ret_Val BOOL 0: Values of the comparator tags or PLC data types are different.

1: Values of the comparator tags are equal and PLC data types are identical.

error BOOL 0: No errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status (see table below).

status WORD "status" outputs the status/error code (see table below).

Page 33: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.3 Comparator operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 33

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-26: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

Function principle

This block compares two (structured) actual parameters and outputs whether they correspond to the same value.

Note The following differences cannot be detected using the comparison method (byte level):

It is not possible to compare tags of the data type "Struct".

For strings, there might be differences between the actual length and the maximum length.

For REAL numbers in the structure, an inequality might be indicated even for “equal” tags.

Tags of the type "ARRAY of BOOL" cannot be checked for equality using this function, as the used instruction "CountOfElements" also counts the filling elements (e. g. 8 is returned for an ARRAY[0..1] of BOOL).

Page 34: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.3 Comparator operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 34

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.3.2 FC LGF_CompareReal

Short description

This function uses an approximation formula to check whether two REAL numbers are equal.

Block

Figure 3-16: FC LGF_CompareReal

FC LGF_CompareReal

REAL valueA Ret_Val BOOL

REAL valueB error BOOL

status WORD

Input parameters

Table 3-27: Input parameters

Parameter Data type Description

valueA REAL Number to be compared.

valueB REAL Number to be compared.

Output parameters

Table 3-28: Output parameters

Parameter Data type Description

Ret_Val BOOL 0: unequal

1: equal

error BOOL Error display

0: No error.

1: Block error, "status" outputs the error code.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-29: Status/error codes

Status Meaning Remedy

16#0000 No errors. -

16#8601 |valueA|+|valueB| exceeds the maximum range of values of a REAL number.

|valueA|+|valueB| has to be

less than +3,402823 ∗ 1038.

Function principle

An approximation formula is intended to check whether two REAL numbers "valueA" and "valueB" are equal. To ensure that the comparison works independently of the size of the numbers, the ratio of the two numbers is checked.

Approximation formula

|𝑣𝑎𝑙𝑢𝑒𝐴 − 𝑣𝑎𝑙𝑢𝑒𝐵|

|𝑣𝑎𝑙𝑢𝑒𝐴| + |𝑣𝑎𝑙𝑢𝑒𝐵|≤ 𝐸𝑃𝑆𝐼𝐿𝑂𝑁

Page 35: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.3 Comparator operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 35

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Two REAL numbers are considered to be equal if the ratio of the difference to the

total of the two numbers is less than or equal to 𝐸𝑃𝑆𝐼𝐿𝑂𝑁.

The value of 𝐸𝑃𝑆𝐼𝐿𝑂𝑁 specifies the accuracy with which the two numbers are

considered to be equal. In the function, 𝐸𝑃𝑆𝐼𝐿𝑂𝑁 is defined as a constant with the

value 1.0 ∙ 10−6.

To avoid a division by zero, the approximation formula is changed in the function:

|𝑣𝑎𝑙𝑢𝑒𝐴 − 𝑣𝑎𝑙𝑢𝑒𝐵| ≤ 𝐸𝑃𝑆𝐼𝐿𝑂𝑁 ∗ (|𝑣𝑎𝑙𝑢𝑒𝐴| + |𝑣𝑎𝑙𝑢𝑒𝐵|)

The following table shows two examples to illustrate the function principle.

Table 3-30

Example 1 Example 2

|𝑣𝑎𝑙𝑢𝑒𝐴| + |𝑣𝑎𝑙𝑢𝑒𝐵| 5 5.000.000

𝐸𝑃𝑆𝐼𝐿𝑂𝑁 1.0 ∙ 10−6

Maximum difference of "𝑣𝑎𝑙𝑢𝑒𝐴" and "𝑣𝑎𝑙𝑢𝑒𝐵" for which the two numbers are still considered to be equal.

0.000005 5

Note If for your application you need a different accuracy for evaluating the ratio of the numbers, adapt the constant 𝐸𝑃𝑆𝐼𝐿𝑂𝑁 in the function to your requirements.

Page 36: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 36

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4 Math operations

3.4.1 FC LGF_AverageAndDeviation

Short description

This block determines the arithmetic average and the standard deviation from a series of numbers.

Block

Figure 3-17: FC LGF_AverageAndDeviation

FC LGF_AverageAndDeviation

VARIANT variableArray arithmeticAverage REAL

standardDeviation REAL

error BOOL

statusID UINT

status WORD

Input parameters

Table 3-31: Input parameters

Parameter Data type Description

variableArray VARIANT Number series to be used for calculating

Output parameters

Table 3-32: Output parameters

Parameter Data type Description

arithmeticAverage REAL Arithmetic average

standardDeviation REAL Standard deviation

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Page 37: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 37

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-33: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8200 At the input "variableArray", the actual parameter is not an array.

-

1 16#8201 The data type of the array elements is not supported (see function principle).

-

2 - Error/status of subordinate block "MOVE_BLK_VARIANT".

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

An array of any size is connected via the input "variableArray". Following a data type request in the block, the values are used to calculate the arithmetic average as well as the standard deviation and both are output.

Note An array with too many elements might lead to the cycle monitoring time being exceeded.

Note Note: Only the data types Int, UInt, DInt, UDInt, USInt, SInt and Real are supported.

Page 38: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 38

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.2 FB LGF_FloatingAverage

Short description

This block calculates a floating arithmetic average from REAL values. This method can be applied for smoothing of data series. The values can be read in cyclically or in a triggered way.

Block

Figure 3-18: LGF_FloatingAverage

FB LGF_FloatingAverage

REAL value average LREAL

INT mode windowSizeReached BOOL

INT windowSize error BOOL

BOOL trigger status WORD

BOOL reset

Input parameters

Table 3-34: Input parameters

Parameter Data type Description

value REAL Values from which the floating average is to be determined

mode INT Mode selection (see function principle); Default value: mode=1.

windowsSize INT Window length for the floating average in the range of 1..100

The default value is 100.

trigger BOOL Trigger tag, pulse

reset BOOL The block is reset and calculation starts again.

Note The block "LGF_FloatingAverage" does not carry out any data type requests for the input parameter "value". For other data types than REAL, either an implicit conversion is carries out automatically or a compiling error is generated.

For more information, please refer to the chapter “Overview of data type conversion” in the TIA Portal Online Help or at:

https://support.industry.siemens.com/cs/ww/en/view/109011420/58427923211

Page 39: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 39

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-35: Output parameters

Parameter Data type Description

average LREAL Floating average

windowSizeReached BOOL 0: maximum window size not reached yet

1: maximum window size reached

error BOOL 0: no errors

1: Block error

status WORD Status/error code (see table below)

Status and error displays

Table 3-36: Status/error codes

status Meaning Remedy / notes

16#0000 No errors -

16#8201 No mode selected Select a mode (1 or 2).

16#8202 No correct window size Set a value between 1 and 100.

Function principle

The block calculates the (floating) average by means of the set window size. The window size specifies the maximum number of the values last read. After the maximum number of values has been read, the output "windowSizeReached" is set and every new value read replaces the respective oldest value (FIFO principle).

For reading the values, two modes are available that can be defined using the parameter "mode".

mode = 1: Reading with every pulse at the input "trigger"

mode = 2: Cyclic read

The block will be enabled as soon as you have selected a mode. It is possible to change the modes during operation.

Page 40: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 40

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.3 FC LGF_MatrixAddition

Short description

This block adds two matrices of equal size of the data type ARRAY of REAL.

Block

Figure 3-19: FC LGF_MatrixAddition

FC LGF_MatrixAddition

ARRAY of REAL matrix1 matrixResult ARRAY of REAL

ARRAY of REAL matrix2 error BOOL

statusID UINT

status WORD

Input parameters

Table 3-37: Input parameters

Parameter Data type Description

matrix1 ARRAY of REAL First summand (matrix)

matrix2 ARRAY of REAL Second summand (matrix)

Output parameters

Table 3-38: Output parameters

Parameter Data type Description

matrixResult ARRAY of REAL Total (matrix)

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-39: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 No errors -

1 16#8200 Lower limits of the arrays are different. All arrays must have the same lower limit, e. g.: Array[0..2, 0..2] of Real

1 16#8201 Upper limits of the arrays are different. All arrays must have the same upper limit, e. g.: Array[0..2, 0..2] of Real

Function principle

The block adds two matrices of equal size. The individual fields of the two incoming matrices are read, added and then output in the matrix "matrixResult".

Page 41: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 41

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Note Please note that all input and output matrices must have the same lower and upper limits and thus the same number of columns and rows.

Page 42: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 42

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.4 FC LGF_MatrixInverse

Short description

This block inverts a square matrix of the data type ARRAY of REAL.

Block

Figure 3-20: FC LGF_MatrixInverse

FC LGF_MatrixInverse

ARRAY of REAL matrix matrixResult ARRAY of REAL

error BOOL

statusID UINT

status WORD

Input parameters

Table 3-40: Input parameters

Parameter Data type Description

matrix ARRAY of REAL Input matrix

Output parameters

Table 3-41: Output parameters

Parameter Data type Description

matrixResult ARRAY of REAL Inverted matrix

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-42: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 No errors -

1 16#8200 Lower limits of the arrays are different. All arrays must have the same lower limit, e. g.: Array[0..2, 0..2] of Real

1 16#8201 Upper limits of the arrays are different. All arrays must have the same upper limit, e. g.: Array[0..2, 0..2] of Real

1 16#8202 Input matrix is not square. The number of rows must be equal to the number of columns.

1 16#8203 Algorithm cannot be applied to the input matrix.

The first element (a1,1) of the input matrix must not be zero.

Function principle

The block inverts a square matrix of any size according to the Shipley-Coleman method.

Page 43: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 43

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Note Please note that the input matrix must be square. This means that the number of rows must be equal to the number of columns.

The output matrix must have the same size and the same array limits as the input matrix.

Page 44: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 44

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.5 FC LGF_MatrixMultiplication

Short description

This block multiplies two matrices of the data type ARRAY of REAL.

Block

Figure 3-21: FC LGF_MatrixMultiplication

FC LGF_MatrixMultiplication

ARRAY of REAL matrix1 matrixResult ARRAY of REAL

ARRAY of REAL matrix2 error BOOL

statusID UINT

status WORD

Input parameters

Table 3-43: Input parameters

Parameter Data type Description

matrix1 ARRAY of REAL First factor: Matrix to be multiplied

matrix2 ARRAY of REAL Second factor: Matrix to be multiplied

Note New as of V2.0.0 The input parameters "rows1", "columns1", "rows2" und "columns2" are no longer required for this version of the block, because here the variable limits of Array[*,*] are queried via the instructions "LOWER_BOUND" and "UPPER_BOUND".

Output parameters

Table 3-44: Output parameters

Parameter Data type Description

matrixResult ARRAY of REAL Product: The resulting matrix

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Page 45: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 45

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-45: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 No errors -

1 16#8200 The number of columns of the first matrix does not correspond to the number of rows of the second matrix.

The limits of the array must also be identical.

1 16#8201 The size of the output matrix (m x n) does not correspond to the number of rows (m) of "matrix1" and the number of columns (n) of "matrix2".

The limits of the array must also be identical.

Function principle

The block multiplies two matrices of variable size. The individual elements of the two incoming matrices are read, multiplied and then output in the matrix "matrixResult".

Note Please note that the number of columns of the first matrix must be equal to the number of rows of the second matrix.

The size of the output matrix (m * n) results from the number of rows (m) of "matrix1" and the number of columns (n) of "matrix2".

Page 46: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 46

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.6 FC LGF_MatrixSubtraction

Short description

This block subtracts a matrix of the data type ARRAY of REAL from another one.

Block

Figure 3-22: FC LGF_MatrixSubtraction

FC LGF_MatrixSubtraction

ARRAY of REAL matrix1 matrixResult ARRAY of REAL

ARRAY of REAL matrix2 error BOOL

statusID UINT

status WORD

Input parameters

Table 3-46: Input parameters

Parameter Data type Description

matrix1 ARRAY of REAL Minuend: "matrix2" is subtracted from this matrix.

matrix2 ARRAY of REAL Subtrahend: This matrix is subtracted from "matrix1".

Output parameters

Table 3-47: Output parameters

Parameter Data type Description

matrixResult ARRAY of REAL Difference: The resulting matrix

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-48: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 No errors -

1 16#8200 Lower limits of the arrays are different. All arrays must have the same lower limit, e. g.: Array[0..2, 0..2] of Real

1 16#8201 Upper limits of the arrays are different. All arrays must have the same upper limit, e. g.: Array[0..2, 0..2] of Real

Function principle

The block subtracts two matrices of variable size. The individual fields of the two matrices are read, subtracted and then output in the matrix "matrixResult".

Page 47: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 47

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Note Please note that all input and output matrices must have the same number of columns and rows.

Page 48: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 48

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.7 FC LGF_MatrixTranspose

Short description

This block transposes a matrix of the data type ARRAY of REAL.

Condition: Input matrix (m x n) = output matrix (n x m)

Block

Figure 3-23: FC LGF_MatrixTranspose

FC LGF_MatrixTranspose

ARRAY of REAL matrix matrixResult ARRAY of REAL

error BOOL

statusID UINT

status WORD

Input parameters

Table 3-49: Input parameters

Parameter Data type Description

matrix ARRAY of REAL Matrix to be transposed

Note New as of V2.0.0 The input parameters "rows" and "columns" are no longer required for this version of the block, because here the variable limits of Array[*,*] are queried via the instructions "LOWER_BOUND" and "UPPER_BOUND".

Output parameters

Table 3-50: Output parameters

Parameter Data type Description

matrixResult ARRAY of REAL resulting matrix

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-51: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 No errors -

1 16#8200 Lower limits of the arrays are different. All arrays must have the same lower limit, e. g.: Array[0..2, 0..2] of Real

1 16#8201 Upper limits of the arrays are different. All arrays must have the same upper limit, e. g.: Array[0..2, 0..2] of Real

Page 49: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 49

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.8 FB LGF_MinMaxHistory

Short description

Every time it is called, this block reads in the value of a tag and outputs the maximum and minimum values that have been read in since the first call.

If necessary, the evaluation can be reset. The block supports the data type LREAL.

Block

Figure 3-24: FB LGF_MinMaxHistory

FB LGF_MinMaxHistory

LREAL variable minValue LREAL

BOOL reset maxValue LREAL

Input parameters

Table 3-52: Input parameters

Parameter Data type Description

variable LREAL Tag the value of which is checked for maximum and minimum.

reset BOOL The block is reset and evaluation starts again.

Output parameters

Table 3-53: Output parameters

Parameter Data type Description

minValue LREAL Minimum value since first call or since the input "reset" has been enabled.

maxValue LREAL Maximum value since first call or since the input "reset" has been enabled.

Page 50: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 50

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.9 FC LGF_RandomBasic

Short description

Every time it is called, this function generated a random value between 0.0 and 1.0. The random number is of data type REAL.

Block

Figure 3-25: FC LGF_RandomBasic

FC LGF_RandomBasic

Ret_Val REAL

Output parameters

Table 3-54: Output parameters

Parameter Data type Description

Ret_Val REAL Random number

Function principle

The function generates random values in the range of 0.0 ≤ Ret_Val ≤ 1.0.

Background information

The random value is calculated from the nanoseconds of the current system time of the CPU. For this, the byte order of this value is inverted and then converted to a standardized floating-point number.

Page 51: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 51

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.10 FC LGF_RandomINT / LGF_RandomReal

Short description

For each call, this block generates a “random” value between a defined maximum and minimum value. The random number is of data type INT / REAL.

Block

Figure 3-26: FC LGF_RandomINT / FC LGF_RandomReal

FC LGF_Random…

INT / REAL maxValue Ret_Val INT / REAL

INT / REAL minValue error BOOL

statusID UINT

status WORD

Input parameters

Table 3-55: Input parameters

Parameter Data type Description

maxValue INT / REAL Defines the upper limit of the random number.

minValue INT / REAL Defines the lower limit of the random number.

Output parameters

Table 3-56: Output parameters

Parameter Data type Description

Ret_Val INT / REAL Random number

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-57: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8200 "minValue" is greater than "maxValue".

-

2 - Error/status of subordinate block "RD_SYS_T".

-

Page 52: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 52

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

The block generates random values lying between the specified "minValue" and "maxValue". This random value is output via "Ret_Val".

Background information

The random value is calculated from the nanoseconds of the current system time of the CPU. For this, the byte order of this value is inverted and then converted to a standardized floating-point number.

Note If no maximum and minimum value (= 0) is specified, the block outputs random values over the entire range of values of INT / REAL.

Page 53: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 53

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.11 FC LGF_SearchMinMax

Short description

This block searches for the maximum and minimum value in an array as well as the respective index in the array.

The following data types of the array elements are supported: Int, DInt, UInt, UDInt, USInt, SInt and Real.

Block

Figure 3-27: FC LGF_SearchMinMax

FC LGF_SearchMinMax

VARIANT variableArray min VARIANT

minArrayIndex INT

max VARIANT

maxArrayIndex INT

error BOOL

statusID UINT

status WORD

Input parameters

Table 3-58: Input parameters

Parameter Data type Description

variableArray VARIANT Array in the fields of which the maximum and minimum values are searched for.

Output parameters

Table 3-59: Output parameters

Parameter Data type Description

minValue VARIANT Lowest value found.

minArrayIndex INT The start index of the array plus minArrayIndex results in the array index of the lowest value. The index starts with 0.

maxValue VARIANT Highest value found.

maxArrayIndex INT Start index of the array plus maxArrayIndex results in the array index of the highest value. The index starts with 0.

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Page 54: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 54

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-60: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8200 At the input "variableArray", the actual parameter is not an array.

-

1 16#8201 The data type of the array elements is not supported.

Only the data types Int, UInt, DInt, UDInt, USInt, SInt and Real are supported.

1 16#8202 The elements of the array do not have the same data type as the outputs "minValue" and "maxValue".

-

2 - Error/status of subordinate block "MOVE_BLK_VARIANT".

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

An array of any size is connected via the input "variableArray". After a data type request in the block, the elements are copied one by one into a tag of the corresponding type and compared. The lowest and the highest value as well as their corresponding index in the array are output.

Note In case of several identical minimum or maximum values, the index of the first minimum or maximum value is output.

Page 55: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 55

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.12 FC LGF_XRoot

Short description

This block calculates the xth root of a numerical tag.

Block

Figure 3-28: FC LGF_Random

FC LGF_XRoot

REAL variable Ret_Val REAL

REAL root

Input parameters

Table 3-61: Input parameters

Parameter Data type Description

variable REAL Tag from which the root is to be calculated.

root REAL Root (e. g. 3 as 3rd

root)

Output parameters

Table 3-62: Output parameters

Parameter Data type Description

Ret_Val REAL Output of the result

Function principle

This block calculates the nth

root of a number. To implement this function, the following formula is expanded.

𝑛𝑢𝑚𝑏𝑒𝑟 = 𝑒𝑙𝑜𝑔𝑒(𝑛𝑢𝑚𝑏𝑒𝑟)

This results in:

𝑅𝑒𝑡_𝑉𝑎𝑙 = √𝑛𝑢𝑚𝑏𝑒𝑟𝑟𝑜𝑜𝑡

= 𝑛𝑢𝑚𝑏𝑒𝑟1

𝑟𝑜𝑜𝑡 = (𝑒𝑙𝑜𝑔𝑒(𝑛𝑢𝑚𝑏𝑒𝑟))1

𝑟𝑜𝑜𝑡 = 𝑒ln(𝑛𝑢𝑚𝑏𝑒𝑟)∗

1𝑟𝑜𝑜𝑡

In STEP 7 (TIA Portal), the function "EXP" corresponds to e(…)

and the function "LN" corresponds to ln(…).

This results in the following formula:

𝑅𝑒𝑡_𝑉𝑎𝑙 = 𝐸𝑋𝑃((1 𝑟𝑜𝑜𝑡⁄ ) ∗ LN(𝑛𝑢𝑚𝑏𝑒𝑟))

Page 56: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 56

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.13 FC LGF_HighLowLimit

Short description

This function checks whether a value is within a defined range of values. The range of values is defined with a setpoint and a dead band around this setpoint. The function calculates the lower and upper limit of the range of values.

Block

Figure 3-29: FC LGF_HighLowLimit

FC LGF_HighLowLimit

REAL value valueInRange BOOL

REAL setpoint highLimitExceeded BOOL

REAL deadband lowLimitExceeded BOOL

error BOOL

status WORD

Input parameters

Table 3-63: Input parameters

Parameter Data type Description

value INT / REAL Value to be checked with regard to whether it is within the defined range of values

setpoint INT / REAL Setpoint

deadband INT / REAL Dead band

Output parameters

Table 3-64: Output parameters

Parameter Data type Description

valueInRange BOOL "TRUE" if "value" is within the range of values (dead band around the setpoint).

valueOverHighLimit BOOL "TRUE" if "value" is higher than the upper limit ("setpoint" + 0.5 * "deadband").

valueUnderLowLimit BOOL "TRUE" if "value" is lower than the lower limit ("setpoint" - 0.5 * "deadband").

error BOOL "FALSE": no errors

"TRUE": Block error

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-65: Status/error codes

Status Meaning Remedy / notes

16#0000 No errors -

16#8101 Wrong range of values "highValue" -

16#8102 Wrong range of values "lowValue" -

Page 57: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 57

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status Meaning Remedy / notes

16#8200 "lowValue" is higher than "highValue". -

Function principle

The tags "setpoint" and "deadband" define a range of values. The function checks whether the value "value" is below, within or above the range of values. The outputs "valueUnderLowLimit", "valueInRange" or "valueOverHighLimit" output where the value "value" is.

Figure 3-30: Function principle

value

deadband

deadband * 0,5 deadband * 0,5

valueUnderLowLimit valueOverHighLimit

setpoint

valueInRange

Page 58: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 58

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.14 FB LGF_Integration

Short description

This block approximately calculates the area below a function trend. The function trend is transferred as analog value (REAL) that varies over time. At the output, the integral value is output.

Block

Figure 3-31: FB LGF_Integration

FB LGF_Integration

REAL value integral REAL

BOOL enable error BOOL

BOOL reset statusID UINT

status WORD

Input parameters

Table 3-66: Input parameters

Parameter Data type Description

value REAL Analog value of the continuous function trend

enable BOOL Enabling the integral calculation If this input is given the value "FALSE", integral calculation will be stopped and the output "integral" indicates the last calculated value.

reset BOOL Sets the output "integral" to "0.0".

Output parameters

Table 3-67: Output parameters

Parameter Data type Description

integral LREAL Integrated value

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-68: Status/error codes

statusID Status Meaning Remedy / notes

0 16#0000 No errors -

2 - Error/status of subordinate block "RD_SYS_T".

-

Page 59: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 59

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

The integral calculation includes adding all those trapezoid areas spanned between the last two function values at the input "value" and the time. The elapsed time is calculated using the system time of the CPU. This trapezoid area is identical to the product of the average of the two process values and the time interval.

𝐴 = 1

2∗ (𝐹(𝑡1) + 𝐹(𝑡0)) ∗ (𝑡1 − 𝑡0) +

1

2∗ (𝐹(𝑡2) + 𝐹(𝑡1)) ∗ (𝑡2 − 𝑡1) + ⋯)

Figure 3-32: Function principle

To start the integral calculation for the input value of the parameter "value", you have to

set the parameter "enable" to the value "TRUE",

set the parameter "reset" to the value "FALSE".

If the parameter "enable" is set to the value "FALSE", integral calculation will be stopped and the output "integral" outputs the last calculated value.

If the parameter "reset" is set to the value "TRUE", the output "integral" will be reset to "0.0".

Page 60: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 60

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.15 FC LGF_Factorial (NEW)

Short description

This function calculates the factorial of a natural number.

Block

Figure 3-33: LGF_Factorial

FC LGF_Factorial

INT n Ret_Val DINT

error BOOL

status WORD

Input parameters

Table 3-69: Input parameters

Parameter Data type Description

n INT Natural number

Output parameters

Table 3-70: Output parameters

Parameter Data type Description

Ret_Val DINT Calculated factorial

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-71: Status/error codes

Status Meaning Remedy / notes

16#0000 No errors -

16#7000 Initial value -

16#8101 Wrong range of values for input parameter "n".

Enter a value between 0 and 12.

Function principle

This function calculates the factorial of a natural number. The permissible range of values for the input parameter "n" is between 0 and 12.

Page 61: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.4 Math operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 61

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.4.16 FC LGF_Distance (NEW)

Short description

This function calculates the distance between two points.

Block

Figure 3-34: FC LGF_Distance

FC LGF_Distance

REAL x1 Ret_Val REAL

REAL y1

REAL x2

REAL y2

Input parameters

Table 3-72: Input parameters

Parameter Data type Description

x1 REAL X-coordinate point 1

y1 REAL Y-coordinate point 1

x2 REAL X-coordinate point 2

y2 REAL Y-coordinate point 2

Output parameters

Table 3-73: Output parameters

Parameter Data type Description

Ret_Val REAL Calculated distance

Function principle

This block calculates the distance between two points in a Cartesian coordinate system.

The distance is calculated using the following formula:

𝑅𝑒𝑡_𝑉𝑎𝑙 = √(𝑥2 − 𝑥1)² + (𝑦2 − 𝑦1)²𝑟𝑜𝑜𝑡

Figure 3-35: Graphic presentation

x1 x2

y1

y2

P1

P2

x

y

Ret_Val

Page 62: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 62

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5 Data handling

3.5.1 FB LGF_FIFO

Short description

This block stores incoming jobs/data and outputs the oldest job that has not yet been processed.

Block

Figure 3-36: FB LGF_FIFO

FB LGF_FIFO

BOOL execute done BOOL

BOOL mode error BOOL

VARIANT initialValue statusID UINT

BOOL resetBuffer status WORD

VARIANT item (InOut)

VARIANT buffer (InOut)

Input parameters

Table 3-74: Input parameters

Parameter Data type Description

execute BOOL Request for a run.

mode BOOL Selecting the mode.

TRUE: Writing the value from "item" into "buffer"

FALSE: Reading the value from "buffer" and output to "item"

initialValue VARIANT Value for initializing the buffer (mostly: 0)

resetBuffer BOOL Clearing and initializing the buffer.

Input/output parameters (InOut)

Table 3-75: Input/output parameters (InOut)

Parameter Data type Description

item VARIANT Value output from the buffer or to be written into the ring buffer.

buffer VARIANT Buffer (Array of …)

Page 63: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 63

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-76: Output parameters

Parameter Data type Description

done BOOL 1: Run completed.

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-77: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8001 The buffer is empty. -

1 16#8002 The buffer is full. -

1 16#8200 No array is present at the input "buffer".

-

1 16#8201 The data type of the InOut parameter "item" does not correspond to the data type of the array elements of the input "buffer".

-

1 16#8202 The data type of the input "initialValue" does not correspond to the data type of the InOut parameter "item".

-

1 16#8601 The tag "nextEmptyItemIndex" is not within the array limits.

-

1 16#8602 The tag "firstItemIndex" is not within the array limits.

-

2 - Error/status of subordinate block "MOVE_BLK_VARIANT".

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

For the block to be started, a positive edge must be recognized at the input "execute".

To request the next read job to be processed, the value "FALSE" must be present at the input "mode". If this is the case, the next job/data to be processed is output at the InOut parameter "item" and this field is replaced in the buffer with the value of the parameter "initialValue".

Page 64: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 64

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

To store a new write job in the buffer, the value "TRUE" must be present at the input "mode". If this is the case, the value or job present at the InOut parameter "item" is stored in the buffer at the next free location.

If the value "TRUE" is present at the input "resetBuffer" during a run, all fields in the buffer will be reset to the value stated at the input "InitialValue". Afterwards, the buffer can be filled with jobs/data again.

Page 65: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 65

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5.2 FB LGF_LIFO (NEW)

Short description

This block stores incoming jobs/data and outputs the newest job/data that has not yet been processed.

Block

Figure 3-37: FB LGF_LIFO

FB LGF_LIFO

BOOL execute done BOOL

BOOL mode error BOOL

VARIANT initialValue statusID UINT

BOOL resetBuffer status WORD

VARIANT item (InOut)

VARIANT buffer (InOut)

Input parameters

Table 3-78: Input parameters

Parameter Data type Description

execute BOOL Request for a run.

mode BOOL Selecting the mode.

TRUE: Writing the value from "item" into "buffer"

FALSE: Reading the value from "buffer" and output to "item"

initialValue VARIANT Value for initializing the buffer (mostly: 0)

resetBuffer BOOL Clearing and initializing the buffer.

Input/output parameters (InOut)

Table 3-79: Input/output parameters (InOut)

Parameter Data type Description

item VARIANT Value output from the buffer or to be written into the ring buffer.

buffer VARIANT Buffer (Array of …)

Page 66: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 66

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-80: Output parameters

Parameter Data type Description

done BOOL 1: Run completed.

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-81: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8001 The buffer is empty. -

1 16#8002 The buffer is full. -

1 16#8200 No array is present at the input "buffer".

-

1 16#8201 The data type of the InOut parameter "item" does not correspond to the data type of the array elements of the input "buffer".

-

1 16#8202 The data type of the input "initialValue" does not correspond to the data type of the InOut parameter "item".

-

2 - Error/status of subordinate block "MOVE_BLK_VARIANT".

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Page 67: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 67

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

For the block to be started, a positive edge must be recognized at the input "execute".

To request the next read job to be processed, the value "FALSE" must be present at the input "mode". If this is the case, the next job/data to be processed is output at the InOut parameter "item" and this field is replaced in the buffer with the value of the parameter "initialValue".

To store a new write job in the buffer, the value "TRUE" must be present at the input "mode". If this is the case, the value or job present at the InOut parameter "item" is stored in the buffer at the next free location.

If the value "TRUE" is present at the input "resetBuffer" during a run, all fields in the buffer will be reset to the value stated at the input "initialValue". Afterwards, the buffer can be filled with jobs/data again.

Page 68: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 68

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5.3 FB LGF_RingBuffer (NEW)

Short description

This block stores data in an array of any size. As soon as all elements in the array have been written on, the oldest element is overwritten. The newest value is always at the first position in the array.

Block

Figure 3-38: FB LGF_RingBuffer

FB LGF_RingBuffer

BOOL write

BOOL resetBuffer

WORD newValue

ARRAY of WORD buffer (InOut)

Input parameters

Table 82: Input parameters

Parameter Data type Description

write BOOL With a rising edge, the value present at "newValue" is written into the ring buffer.

resetBuffer BOOL If the value is TRUE, the ring buffer will be reset.

newValue WORD Value to be written into the ring buffer.

Input/output parameters (InOut)

Table 83: Input/output parameters (InOut)

Parameter Data type Description

buffer ARRAY of WORD Ring buffer into which the values are to be written.

Page 69: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 69

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Note If a data type other than WORD is to be processed, change the data type of "newValue" and "buffer" in the block interface.

Function principle

With a positive edge at the input parameter "write", the value at the input parameter "newValue" is written to the first position of the ring buffer. This ring buffer must be provided in the form of an array at the input/output parameter "buffer". The limits of the array are determined by the block.

Before a value is written into the ring buffer, the previous elements of the ring buffer are moved by one position. If all elements are occupied, the oldest element will be overwritten.

If the value "TRUE" is present at the input "resetBuffer", all fields in the buffer will be reset to the value "0". If "FALSE" is present at "resetBuffer" again, the buffer can be filled with jobs/data again.

Note As the input parameter "write" responds to rising edges only, data can only be stored in the ring buffer every second cycle.

Page 70: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 70

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5.4 FB LGF_ShellSortInt / LGF_ShellSortUInt / LGF_ShellSortReal

Short description

This block sorts an array with any number of elements (max. 1000) in ascending or descending order. The following data types are supported:

Array of type "Int": LGF_ShellSortInt

Array of type "UInt": LGF_ShellSortUInt

Array of type "Real": LGF_ShellSortReal

Block

Figure 3-39: FB LGF_ShellSort…

FB LGF_ShellSort…

BOOL mode done BOOL

error BOOL

VARIANT variantArray (InOut) statusID UINT

status WORD

Input parameters

Table 3-84: Input parameters

Parameter Data type Description

mode BOOL 0: sort in ascending order (default)

1: sort in descending order

Input/output parameters (InOut)

Table 3-85: Input/output parameters (InOut)

Parameter Data type Description

variantArray VARIANT Array to be sorted.

Output parameters

Table 3-86: Output parameters

Parameter Data type Description

done BOOL 1: Sorting completed.

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Page 71: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 71

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-87: Status/error codes

statusID status Meaning Remedy / notes

1 16#7000 Initial value -

1 16#0000 No errors -

1 16#8200 Actual parameter at the input "variantArray" has only one element.

Interconnect at the input "variantArray" an array of at least two elements.

1 16#8201 Actual parameter at the input "variantArray" is not an array.

1 16#8202 Actual parameter at the input "variantArray" does not have a matching data type.

Interconnect at the input "variantArray" an array of the correct data type:

LGF_ShellSortInt: Array of type Int

LGF_ShellSortUInt: Array of type UInt

LGF_ShellSortReal: Array of type Real

1 16#8203 Actual parameter at the input "variantArray" has too many elements.

By default, you can sort an array of up to 1000 elements.

2 - Error/status of subordinate block "MOVE_BLK_VARIANT" when reading the array.

-

3 - Error/status of subordinate block "MOVE_BLK_VARIANT" when writing the array.

-

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

This block sorts according to the Shell sorting method. Please note that the execution time of the block strongly depends on how many elements the array to be sorted has. The following overview shows some measured values of the block depending on the number of array elements.

Table 3-88: Execution times of the block "LGF_ShellSort…"

Number of array elements

S7-1212C DC/DC/DC S7-1516-3 PN/DP

100 approx. 11 to 16 ms approx. 1 to 2 ms

1000 approx. 185 to 205 ms approx. 10 to 12 ms

Note The block is executed synchronously and is not distributed over several PLC cycles. Thus, the execution time directly affects the PLC cycle time. Please observe this behavior with regard to your project and to the controller used and adjust the monitoring time of the controller, if necessary.

Page 72: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 72

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5.5 FC LGF_CRC8 (NEW)

Short description

CRC calculation is used for error detection during data transmission. The result of a calculation provides a CRC value concerning the data send. The receiver detects an incorrect transmission due to the CRC value not being identical. The function "LGF_CRC8" uses an 8-bit generator polynomial (mask).

Block

Figure 3-40: FB LGF_CRC8

FC LGF_CRC8

BYTE initValue Ret_Val BYTE

BYTE mask

ARRAY of BYTE inputArray

Input parameters

Table 89: Input parameters

Parameter Data type Description

initValue BYTE Start value used for calculating. If you do not need a start value, assign 0x0 to the parameter.

mask BYTE Generator polynomial used for calculating.

Input/output parameters (InOut)

Table 90: Input/output parameters (InOut)

Parameter Data type Description

inputArray ARRAY of BYTE Data stream for which the CRC value is to be calculated.

Output parameters

Table 91: Output parameters

Parameter Data type Description

Ret_Val BYTE Calculated CRC value (return value of the function).

Function principle

This block calculates the CRC value from a data stream of any size. The data stream consists of the individual elements of the array at the input/output parameter "inputArray". The start value "initValue" and the generator polynomial "mask" can be selected as desired.

Page 73: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 73

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5.6 FC LGF_CRC8For1Byte (NEW)

Short description

CRC calculation is used for error detection during data transmission. The result of a calculation provides a CRC value concerning the data send. The receiver detects an incorrect transmission due to the CRC value not being identical. The function "LGF_CRC8For1Byte" uses an 8-bit generator polynomial (mask).

Block

Figure 3-41: FB LGF_CRC8For1Byte

FC LGF_CRC8For1Byte

BYTE initValue Ret_Val BYTE

BYTE mask

BYTE inputByte

Input parameters

Table 92: Input parameters

Parameter Data type Description

initValue BYTE Start value used for calculating. If you do not need a start value, assign 0x0 to the parameter.

mask BYTE Generator polynomial used for calculating.

inputByte BYTE Data byte for which the CRC value is to be calculated.

Output parameters

Table 93: Output parameters

Parameter Data type Description

Ret_Val BYTE Calculated CRC value (return value of the function).

Function principle

This block calculates the CRC value from a data byte. The start value "initValue" and the generator polynomial "mask" can be selected as desired.

Page 74: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 74

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5.7 FC LGF_CRC16 (NEW)

Short description

CRC calculation is used for error detection during data transmission. The result of a calculation provides a CRC value concerning the data send. The receiver detects an incorrect transmission due to the CRC value not being identical. The function “LGF_CRC16" uses a 16-bit generator polynomial (mask).

Block

Figure 3-42: FB LGF_CRC16

FC LGF_CRC16

WORD initValue Ret_Val WORD

WORD mask

ARRAY of BYTE inputArray

Input parameters

Table 94: Input parameters

Parameter Data type Description

initValue WORD Start value used for calculating. If you do not need a start value, assign 0x0 to the parameter.

mask WORD Generator polynomial used for calculating.

Input/output parameters (InOut)

Table 95: Input/output parameters (InOut)

Parameter Data type Description

inputArray ARRAY of BYTE Data stream for which the CRC value is to be calculated.

Output parameters

Table 96: Output parameters

Parameter Data type Description

Ret_Val WORD Calculated CRC value (return value of the function).

Function principle

This block calculates the CRC value from a data stream of any size. The data stream consists of the individual elements of the array at the input/output parameter "inputArray". The start value "initValue" and the generator polynomial "mask" can be selected as desired.

Page 75: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 75

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.5.8 FC LGF_CRC32 (NEW)

Short description

CRC calculation is used for error detection during data transmission. The result of a calculation provides a CRC value concerning the data send. The receiver detects an incorrect transmission due to the CRC value not being identical. The function "LGF_CRC32" uses a 32-bit generator polynomial (mask).

Block

Figure 3-43: FB LGF_CRC32

FC LGF_CRC32

DWORD initValue Ret_Val DWORD

DWORD mask

DWORD finalXorValue

BOOL reflectInput

BOOL reflectResult

ARRAY of BYTE inputArray

Input parameters

Table 97: Input parameters

Parameter Data type Description

initValue DWORD Start value used for calculating. If you do not need a start value, assign 0x0 to the parameter.

mask DWORD Generator polynomial used for calculating.

finalXorValue DWORD Value with which another XOR operation will be carried out at the end

reflectInput BOOL If the value is TRUE, the order of bits within the input byte will be mirrored. The order 0…7 turns into 7…0.

reflectResult BOOL If the value is TRUE, the order of bits within the result byte will be mirrored. The order 0…7 turns into 7…0.

Input/output parameters (InOut)

Table 98: Input/output parameters (InOut)

Parameter Data type Description

inputArray ARRAY of BYTE Data stream for which the CRC value is to be calculated.

Output parameters

Table 99: Output parameters

Parameter Data type Description

Ret_Val DWORD Calculated CRC value (return value of the function).

Page 76: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.5 Data handling

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 76

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

This block calculates the CRC value from a data stream of any size. The data stream consists of the individual elements of the array at the input/output parameter "inputArray". The start value "initValue" and the generator polynomial "mask" can be selected as desired. Optionally, you can use the Boolean input parameters "reflectInput" and "reflectResult" to mirror the bits of the input data or of the CRC value (see input parameters). Moreover, at the end, the CRC value is used for an XOR operation with the value present at "finalXOR".

Page 77: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 77

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6 Converter operations

3.6.1 FC LGF_BinaryToGray

Short description

This block converts a binary-coded value to a Gray-coded value.

Block

Figure 3-44: FC LGF_BinaryToGray

FC LGF_BinaryToGray

DWORD variableBinary Ret_Val DWORD

Input parameters

Table 3-100: Input parameters

Parameter Data type Description

variableBinary DWORD Binary-coded value

Output parameters

Table 3-101: Output parameters

Parameter Data type Description

Ret_Val DWORD Gray-coded value

Page 78: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 78

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.2 FC LGF_GrayToBinary

Short description

This block converts a Gray-coded value to a binary-coded value.

Block

Figure 3-45: FC LGF_GrayToBinary

FC LGF_GrayToBinary

DWORD variableGray Ret_Val DWORD

Input parameters

Table 3-102: Input parameters

Parameter Data type Description

variableGray DWORD Gray-coded value

Output parameters

Table 3-103: Output parameters

Parameter Data type Description

Ret_Val DWORD Binary-coded value

Page 79: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 79

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.3 FC LGF_BitsToWord

Short description

This block converts 16 BOOL tags to a WORD tag.

Block

Figure 3-46: FC LGF_BitsToWord

FC LGF_BitsToWord

BOOL bit0 Ret_Val WORD

BOOL bit1

BOOL bit2

BOOL bit3

BOOL bit4

BOOL bit5

BOOL bit6

BOOL bit7

BOOL bit8

BOOL bit9

BOOL bit10

BOOL bit11

BOOL bit12

BOOL bit13

BOOL bit14

BOOL bit15

Input parameters

Table 3-104: Input parameters

Parameter Data type Description

bit0

bit15

BOOL Bit tags

Output parameters

Table 3-105: Output parameters

Parameter Data type Description

Ret_Val WORD Word tag

Page 80: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 80

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.4 FC LGF_WordToBits

Short description

This block converts a WORD tag to 16 BOOL tags.

Block

Figure 3-47: FC LGF_WordToBits

FC LGF_WordToBits

WORD word bit0 BOOL

bit1 BOOL

bit2 BOOL

bit3 BOOL

bit4 BOOL

bit5 BOOL

bit6 BOOL

bit7 BOOL

bit8 BOOL

bit9 BOOL

bit10 BOOL

bit11 BOOL

bit12 BOOL

bit13 BOOL

bit14 BOOL

bit15 BOOL

Input parameters

Table 3-106: Input parameters

Parameter Data type Description

Word WORD WORD tag

Output parameters

Table 3-107: Output parameters

Parameter Data type Description

bit0

bit15

BOOL Bit tags

Page 81: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 81

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.5 FC LGF_DTLtoString

Short description

This block converts a date of the DTL data type to a string of the STRING data type.

Block

Figure 3-48: FC LGF_DTLtoString

FC DTLtoString

DTL inDTL Ret_Val STRING

BOOL format

CHAR separatorDate

Input parameters

Table 3-108: Input parameters

Parameter Data type Description

inDTL DTL Date

format BOOL Format selection of the output string:

0: international (YYYY MM DD ...)

1: traditional (DD MM YYYY ...)

separatorDate CHAR Separator between the components of the output date.

Output parameters

Table 3-109: Output parameters

Parameter Data type Description

Ret_Val STRING Output string

Function principle

The block reads a date of the data type DTL and converts the individual components of the date (year, month, day, hour) to a string and outputs them. The individual components are placed at the correct position in the string according to the selected format. The separator between the components of the date is variable.

Format selection

You can use the input parameter "format" to choose between the international (ISO 8601) and the traditional (DE) date format for the output string.

6. International format (ISO 8601) If the input parameter "format" is not set (format = FALSE), the date will be output as a string in the international format. Example: 2016-03-16 13:34:12.123456789 The figure below shows the positions of the individual characters in the string.

Page 82: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 82

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Figure 3-49: Positions of the individual characters

7. Traditional format (DE) If the input parameter "format" is set (format = TRUE), the date will be output as a string in the traditional format. Example: 16-03-2016 13:34:12.123456789 The figure below shows the positions of the individual characters in the string.

Figure 3-50: Positions of the individual characters

Separators

At the input parameter "separatorDate", you have to specify the separator between the components of the calendar date.

Example: separatorDate = ‘/’ outString = ‘2016/03/16 …’

separatorDate = ‘-‘ outString = ‘2016-03-16 …’

Page 83: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 83

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.6 FC LGF_StringToDTL

Short description

This block converts a string from the string format with date components to the data type DTL.

Block

Figure 3-51: FC LGF_StringToDTL

FC LGF_StringToDTL

STRING inString Ret_Val DTL

BOOL format error Bool

status WORD

Input parameters

Table 3-110: Input parameters

Parameter Data type Description

inString STRING Date as string

format BOOL Format selection of the string read in:

0: international (YYYY MM DD ...)

1: traditional (DD MM YYYY ...)

Output parameters

Table 3-111: Output parameters

Parameter Data type Description

Ret_Val DTL Outputs the date read in

error BOOL 0: no error

1: Block error, "status" outputs the error code

status WORD "status" outputs the status/error code (see table below)

Status and error displays

Table 3-112: Status/error codes

Status Meaning Remedy / notes

16#0000 No errors -

16#7000 Initial value -

16#8201 Format: year The year stated does not correspond to the format or the specification (outside the DTL range of values).

16#8202 Format: month The month stated does not correspond to the format or the specification (outside the DTL range of values).

16#8203 Format: day The day stated does not correspond to the format or the specification (outside the DTL range of values).

16#8204 Format: hour The hour stated does not correspond to the format or the specification (outside the DTL range of values).

Page 84: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 84

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status Meaning Remedy / notes

16#8205 Format: minute The minute stated does not correspond to the format or the specification (outside the DTL range of values).

16#8206 Format: second The second stated does not correspond to the format or the specification (outside the DTL range of values).

16#8207 Format: Nanosecond

The nanosecond stated does not correspond to the format or the specification (outside the DTL range of values).

Function principle

The block reads a date as a string and converts it to the datatype DTL. The individual date components in the string are separated according to the format selected (positioning of the date components within the string). For this, the separator between the components in the string is irrelevant.

Format selection

You can use the input parameter "format" to select whether the string read in is shown in the international (ISO 8601) or traditional (DE) date format.

1. International format (ISO 8601) If the input parameter "format" is not set (format = FALSE), the date in the string will be read in the international format. Example: inString = `2016-03-16 13:34:12.001` format = FALSE outDTL = DTL#2016-03-16-13:34:12.001000 Figure 2-10 shows the positions of the individual characters in the string.

Figure 3-52: Positions of the individual characters

2. Traditional format (DE) If the input parameter "format" is set (format = TRUE), the date in the string will be read in the traditional format. Example: inString = ‘16/03/2016 13:34:12.1‘ format = TRUE outDTL = DTL#2016-03-16-13:34:12.100000 The figure below shows the positions of the individual characters in the string.

Figure 3-53: Positions of the individual characters

Page 85: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 85

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.7 FC LGF_TemperatureConvert

Short description

This block converts °Celsius to °Fahrenheit or Kelvin as well as °Fahrenheit to Kelvin and vice versa.

Block

Figure 3-54: FC LGF_TemperatureConvert

FC LGF_TemperatureConvert

INT mode Ret_Val REAL

REAL temperature error BOOL

Status WORD

Input parameters

Table 3-113: Input parameters

Parameter Data type Description

mode INT Mode

1. °Celsius to °Fahrenheit

2. °Fahrenheit to °Celsius

3. °Celsius to Kelvin

4. Kelvin to °Celsius

5. °Fahrenheit to Kelvin

6. Kelvin to °Fahrenheit

temperature REAL Temperature to be converted

Output parameters

Table 3-114: Output parameters

Parameter Data type Description

Ret_Val REAL Converted temperature

error BOOL 0: no errors

1: Block error

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-115: Status/error codes

Status Meaning Remedy / notes

16#7000 Initial value -

16#0000 No errors -

16#8200 No correct mode at the input "mode". See description of the input parameters

Page 86: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 86

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.8 FC LGF_ScaleLinear

Short description

This function scales the input value using a linear equation.

Block

Figure 3-55: FC LGF_ScaleLinear

FC LGF_ScaleLinear

VARIANT x y VARIANT

VARIANT x1 error BOOL

VARIANT y1 status WORD

VARIANT x2

VARIANT y2

VARIANT yMin

VARIANT yMax

Input parameters

Table 3-116: Input parameters

Parameter Data type Description

x VARIANT Input value to be scaled

x1 VARIANT Point 1 (P1) of the linear function.

y1 VARIANT

x2 VARIANT Point 2 (P2) of the linear function.

y2 VARIANT

yMin VARIANT Lower limit of the output.

yMax VARIANT Upper limit of the output.

Output parameters

Table 3-117: Output parameters

Parameter Data type Description

y VARIANT Output value, scaled.

error BOOL Error display

0: No error.

1: Block error, "status" outputs the error code.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-118: Status and error codes

Status Meaning Remedy

16#0000 No errors. -

16#8200 Actual parameter at the input "x" is of the wrong data type.

The input "x" must only be configured with the data types INT or REAL.

16#8201 Actual parameter at the output "y" is of the wrong data type.

The output "y" must only be configured with the data types INT or REAL.

Page 87: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 87

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status Meaning Remedy

16#8202 Actual parameters at the inputs "x", "x1" and "x2" are of different data types.

All x-parameters must be either INT or REAL.

16#8203 Actual parameters at the inputs "y1", "y2", "yMin", "yMax" and at the output "y" are of different data types.

All y-parameters must be either INT or REAL.

16#8204 The lower limit "yMin" is higher than the upper limit "yMax".

Select the lower limit so that it is below the upper limit.

Function principle

This function scales an input quantity (e. g. an analog input value) linearly to a particular output quantity (e. g. filling level).

To determine the output quantity, the function uses the following linear equation:

𝑦 = 𝑦2 − 𝑦1𝑥2 − 𝑥1

∙ (𝑥 − 𝑥1) + 𝑦1

The line is defined by the two points P1 and P2,. Specify the points in terms of a Cartesian coordinate system by x and y coordinates.

Note If the values of the parameters "x1" and "x2" are equal, the output "y" will output the value of "y1".

By specifying "yMin" and "yMax", you can restrict the calculated value of "y" to a range with a lower and upper limit. Thus, high range and low range errors can be avoided.

Figure 3-56: Scaling

.yMax

P2y2

.y*

P1y1

yMin

x** x2x1

*) resulting scaled value**) value to be scaled

You can configure formal parameters using the following data types:

Page 88: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 88

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Table 3-119: Data types

Formal parameter

Scaling

x, x1, x2 y, y1, y2, yMin, yMax

Data type

INT INT INT INT

INT REAL INT REAL

REAL INT REAL INT

REAL REAL REAL REAL

Example

A signal of 4 to 20mA is present at an analog input module. This signal is converted to a CPU internal value between 0 and 27648 in order to measure a filling level. For this, 0 corresponds to a filling level of 0.0 m and 27648 corresponds to a filling level of 1.7 m.

Thus, you have to configure the block as follows:

x1 = 0; y1 = 0.0 (P1)

x2 = +27648; y2 = 1.7 (P2)

yMin = 0.0

yMax = 1.7

Page 89: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 89

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.9 FC LGF_StringToTaddr

Short description

The system data type "TADDR_Param" contains address information consisting of an IPV4 address and the port number.

The function LGF_StringToTaddr converts a tag of data type "String" to a tag of system data type "TADDR_Param".

Block

Figure 3-57: FC LGF_StringToTaddr

FC LGF_StringToTaddr

STRING ipAddressString Ret_Val TADDR_param

error BOOL

status WORD

Input parameters

Table 3-120: Input parameters

Parameter Data type Description

ipAddressString STRING IPV4 address

Output parameters

Table 3-121: Output parameters

Parameter Data type Description

Ret_Val TADDR_param IPV4 address

error BOOL 0: no errors

1: Block error

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-122: Status/error codes

Status Meaning Remedy / notes

16#0000 No errors -

16#8101 Wrong value in the 1st part of the IP

address Check the IP address at the input

16#8102 Wrong value in the 2nd

part of the IP address

16#8103 Wrong value in the 3rd

part of the IP address

16#8104 Wrong value in the 4th part of the IP

address

16#8105 Wrong value in the port area of the IP address

Page 90: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 90

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

The function converts the IPV4 address with or without port number of the data type "STRING" to "TADDR_param". The string must correspond to the following form:

[0..255].[0..255].[0..255].[0..255] without port number

or

[0..255].[0..255].[0..255].[0..255]:[0..65535] with port number

Example

Standard string format for an IPV4 address without port number: ‘192.168.11.11’

Standard string format for an IPV4 address with port number: '192.168.11.11:3294'

Note Without any port number specified in the parameter "ipAddressString", the parameter "Ret_Val.REM_PORT_NR" outputs the value "0".

Page 91: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 91

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.10 FC LGF_TaddrToString

Short description

The system data type "TADDR_Param" contains address information consisting of an IPV4 address and the port number.

The function LGF_TaddrToString converts a tag of system data type "TADDR_Param" to a tag of data type "String".

Block

Figure 3-58: FC LGF_TaddrToString

FC LGF_TaddrToString

TADDR_Param ipAdressTaddr Ret_Val STRING

Input parameters

Table 3-123: Input parameters

Parameter Data type Description

ipAdressTaddr TADDR_Param IPV4 address

Output parameters

Table 3-124: Output parameters

Parameter Data type Description

Ret_Val STRING IPV4 address

Function principle

The function converts the IPV4 address with or without port number. The system data type "TADDR_Param" is a structured data type. This structure includes the tag "REM_PORT_NR". If this tag is "0", no port will be written in the parameter "Ret_Val".

Example

Ret_val without port number: ‘192.168.11.11’

Ret_val with port number: '192.168.11.11:3294'

Page 92: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 92

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.11 FC LGF_IntToString (NEW)

Short description

This block converts a tag of system data type "DInt" to a tag of data type "String".

Block

Figure 3-59: FC LGF_IntToString

FC LGF_IntToString

DINT intValue Ret_Val STRING

Input parameters

Table 3-125: Input parameters

Parameter Data type Description

intValue DINT Integer value

Output parameters

Table 3-126: Output parameters

Parameter Data type Description

Ret_Val STRING Converted value as string

Page 93: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.6 Converter operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 93

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.6.12 FC LGF_TimeToString (NEW)

Short description

This block converts a tag of system data type "Time" to a tag of data type "String".

Block

Figure 3-60: FC LGF_TimeToString

FC LGF_TimeToString

TIME timeValue Ret_Val STRING

Input parameters

Table 3-127: Input parameters

Parameter Data type Description

intValue TIME Integer value

Output parameters

Table 3-128: Output parameters

Parameter Data type Description

Ret_Val STRING Converted time as string

Page 94: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 94

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7 Signal generators

3.7.1 FB LGF_Frequency

Short description

This block generates a signal that toggles between the values "0" and "1" depending on a defined frequency and a pulse pause ratio.

Block

Figure 3-61: FB LGF_Frequency

FB LGF_Frequency

REAL frequency clock BOOL

REAL pulsePauseRatio countdown TIME

Input parameters

Table 3-129: Input parameters

Parameter Data type Description

frequency REAL Clock frequency in Hz

pulsePauseRatio REAL Puls pause ratio (Default: 1.0 corresponds to 1:1)

Output parameters

Table 3-130: Output parameters

Parameter Data type Description

clock BOOL Output toggles with defined frequency

countdown TIME Remaining time of the current state of "clock"

Function principle

The output "clock" is a Boolean value that toggles at the defined frequency. The pulse pause ratio can be set using the input "pulsePauseRatio".

The output "countdown" outputs the remaining time of the current state of "clock".

If the desired frequency or the pulse pause ratio is less than or equal to "0.0", then the output "clock" = FALSE and "countdown" = "0 s".

Page 95: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 95

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Example

Figure 3-62: FB LGF_Frequency

�𝑢𝑙 𝑒𝑃𝑎𝑢 𝑒𝑅𝑎𝑡 𝑜 = 𝑡𝑜 𝑡𝑜

= 3

1

FB LGF_Frequency

0.5 frequency clock TRUE

countdown T#0S_703MSpulsePauseRatio3.0

TT = 2 ston = 1.5 stoff = 0.5 s

toffton

clock

Page 96: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 96

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7.2 FB LGF_Impulse

Short description

This block generates pulses at a specified frequency. The pulse is always pending for a (control) cycle.

Block

Figure 3-63: FB LGF_Impulse

FB LGF_Impulse

REAL frequency impulse BOOL

countdown TIME

Input parameters

Table 3-131: Input parameters

Parameter Data type Description

frequency REAL Clock frequency in Hz

Output parameters

Table 3-132: Output parameters

Parameter Data type Description

impulse BOOL Signal with pulses

countdown TIME Time until next pulse

Function principle

This block generates pulses at the output "impulse" at the frequency "frequency". The block always starts with a pulse and sets the following pulse after the period duration has elapsed.

Example

Figure 3-64: Example

TRUE

Period duration: 2 seconds

FB LGF_Impulse

frequency

impulse

countdown

0.5

T#0S_703MS

Note New as of V1.2.0 The block LGF_Impulse (as of V1.2.0) does not call the block LGF_Frequency anymore.

Page 97: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 97

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7.3 FB LGF_SawTooth

Short description

This block generates a saw-tooth signal characteristic. Each saw tooth consists of a defined number of steps (increments).

Block

Figure 3-65: FB LGF_SawTooth

FB LGF_SawTooth

INT startValue value INT

TIME timeRange

INT incrementRange

INT numberSteps

BOOL endlessSteps

BOOL restart

Input parameters

Table 3-133: Input parameters

Parameter Data type Description

startValue INT Start value at which the signal starts.

timeRange TIME Time after which the output parameter "value" is incremented

incrementRange INT Size of the step from one increment to the next.

numberSteps INT Number of increments for each saw tooth. (Not to be specified in case of an endless saw-tooth signal).

endlessSteps BOOL Specifies whether an endless saw-tooth signal is to be generated.

restart BOOL Saw tooth starts again at the start value "startValue".

Note Please note that changes at the input parameters will only become effective with "restart".

Output parameters

Table 3-134: Output parameters

Parameter Data type Description

value INT Current value of the saw-tooth signal.

Function principle

This block calculates the values for a saw-tooth signal characteristic which are output at the output parameter "value". The signal starts with the start value

Page 98: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 98

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

"startValue" and is added to the value "Time" each time the time interval "timeRange" has elapsed. The value can be a negative one as well.

If the tag "endlessSteps" is set to "FALSE", the number of adding processes will be counted. If this number exceeds the value "numberSteps", the output parameter "value" is reset to the start value. A new saw tooth starts.

If the tag "endlessSteps" is set to "TRUE", the value "increment" will be added without interruption – once and starting at "startValue". If the maximum positive INT value range (32767) of the output parameter "value" is exceeded, "value" will change to the maximum negative INT value range (-32768) and will be added further.

Note The duration of a saw tooth at "endlessSteps" set to "FALSE" is calculated as follows:

Duration = "timeRange * ("numberSteps" + 1)

Figure 3-66: Signal curve of the output "value"

startValue

incrementRange

timeRange

time

value

endless Steps= true

restart = true

restart = false

Page 99: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 99

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7.4 FB LGF_SawToothCI (NEW)

Short description

This block generates a saw-tooth signal characteristic.

Block

Figure 3-67: FB LGF_SawToothCI

FB LGF_SawToothCI

REAL amplitude sawToothValues REAL

REAL offset error BOOL

UDINT periodeMS statusID UINT

OB_CYCLIC callOB status WORD

BOOL reset

Input parameters

Table 3-135: Input parameters

Parameter Data type Description

amplitude REAL Amplitude of the signal characteristic.

offset REAL Offset of the signal characteristic in Y direction.

periodeMS UDINT Period duration of the signal characteristic in [ms]

callOB OB_CYCLIC Calling cyclic interrupt OB

reset BOOL Reset of the signal characteristic.

Note Changes at the input parameters will be effective immediately.

Output parameters

Table 3-136: Output parameters

Parameter Data type Description

sawToothValues REAL Current value of the saw-tooth signal.

Status and error displays

Table 3-137: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 no errors Job completed.

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" the constant name of a configured cyclic interrupt OB.

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Page 100: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 100

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

This block calculates the values for a saw-tooth signal characteristic which are output at the output parameter "sawToothValues".

The amplitude "amplitude", the offset in Y direction "offset" and the period duration "periodeMS" can be specified at the input parameters.

You can use the input parameter "reset" to reset the signal characteristic. At the output parameter "sawToothValues", the value "0" is output as long as "reset" is set to "TRUE".

The block must be called in a cyclic interrupt OB. The clock cycle of the calling cyclic interrupt OB is determined in the FB with the instruction "QRY_CINT". For this, the constant name of the calling cyclic interrupt OB must be interconnected at the input parameter "callOB".

Figure 3-68: Interconnecting the cyclic interrupt OB

The number of calculated values of the signal characteristic for each period duration is calculated as follows:

𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒 =�𝑒𝑟 𝑜𝑑 𝑑𝑢𝑟𝑎𝑡 𝑜𝑛

𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒 𝑐𝑦𝑐𝑙 𝑐 𝑛𝑡𝑒𝑟𝑟𝑢�𝑡 𝑂𝐵

Note To maintain a continuous signal characteristic of the curve, the clock cycle of the calling cyclic interrupt OB depending on the period duration should not be selected to large.

The figure below shows the signal characteristic of the calculated values.

Figure 3-69: Signal characteristic at "offset" = 0

y

Amplitude

0Time

-AmplitudePeriod duration

Page 101: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 101

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7.5 FB LGF_TriangleCI (NEW)

Short description

This block generates a triangle signal characteristic.

Block

Figure 3-70: FB LGF_TriangleCI

FB LGF_TriangleCI

REAL amplitude triangleValues REAL

REAL offset error BOOL

UDINT periodeMS statusID UINT

OB_CYCLIC callOB status WORD

BOOL reset

Input parameters

Table 3-138: Input parameters

Parameter Data type Description

amplitude REAL Amplitude of the signal characteristic.

offset REAL Offset of the signal characteristic in Y direction.

periodeMS UDINT Period duration of the signal characteristic in [ms]

callOB OB_CYCLIC Calling cyclic interrupt OB

reset BOOL Reset of the signal characteristic.

Note Changes at the input parameters will be effective immediately.

Output parameters

Table 3-139: Output parameters

Parameter Data type Description

triangleValues REAL Current value of the triangle signal.

Status and error displays

Table 3-140: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 no errors Job completed.

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" the constant name of a configured cyclic interrupt OB.

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Page 102: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 102

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

This block calculates the values for a triangle signal characteristic which are output at the output parameter "triangleValues".

The amplitude "amplitude", the offset in Y direction "offset" and the period duration "periodeMS" can be specified at the input parameters.

You can use the input parameter "reset" to reset the signal characteristic. At the output parameter "triangleValues", the value "0" is output as long as "reset" is set to "TRUE".

The block must be called in a cyclic interrupt OB. The clock cycle of the calling cyclic interrupt OB is determined in the FB with the instruction "QRY_CINT". For this, the constant name of the calling cyclic interrupt OB must be interconnected at the input parameter "callOB".

Figure 3-71: Interconnecting the cyclic interrupt OB

The number of calculated values of the signal characteristic for each period duration is calculated as follows:

𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒 =�𝑒𝑟 𝑜𝑑 𝑑𝑢𝑟𝑎𝑡 𝑜𝑛

𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒 𝑐𝑦𝑐𝑙 𝑐 𝑛𝑡𝑒𝑟𝑟𝑢�𝑡 𝑂𝐵

Note To maintain a continuous signal characteristic of the curve, the clock cycle of the calling cyclic interrupt OB depending on the period duration should not be selected to large.

The figure below shows the signal characteristic of the calculated values.

Figure 3-72: Signal characteristic at "offset" = 0

y

Amplitude

0Time

-AmplitudePeriod duration

Page 103: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 103

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7.6 FB LGF_RectangleCI (NEW)

Short description

This block generates a rectangular signal characteristic.

Block

Figure 3-73: FB LGF_RectangleCI

FB LGF_RectangleCI

REAL amplitude rectangleValues REAL

REAL offset error BOOL

UDINT periodeMS statusID UINT

OB_CYCLIC callOB status WORD

BOOL reset

Input parameters

Table 3-141: Input parameters

Parameter Data type Description

amplitude REAL Amplitude of the signal characteristic.

offset REAL Offset of the signal characteristic in Y direction.

periodeMS UDINT Period duration of the signal characteristic in [ms]

callOB OB_CYCLIC Calling cyclic interrupt OB

reset BOOL Reset of the signal characteristic.

Note Changes at the input parameters will be effective immediately.

Output parameters

Table 3-142: Output parameters

Parameter Data type Description

rectangleValues REAL Current value of the rectangular signal.

Status and error displays

Table 3-143: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 no errors Job completed.

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" the constant name of a configured cyclic interrupt OB.

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Page 104: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 104

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

This block calculates the values for a rectangular signal characteristic which are output at the output parameter "rectangleValues".

The amplitude "amplitude", the offset in Y direction "offset" and the period duration "periodeMS" can be specified at the input parameters.

You can use the input parameter "reset" to reset the signal characteristic. At the output parameter "rectangleValues", the value "0" is output as long as "reset" is set to "TRUE".

The block must be called in a cyclic interrupt OB. The clock cycle of the calling cyclic interrupt OB is determined in the FB with the instruction "QRY_CINT". For this, the constant name of the calling cyclic interrupt OB must be interconnected at the input parameter "callOB".

Figure 3-74: Interconnecting the cyclic interrupt OB

The number of calculated values of the signal characteristic for each period duration is calculated as follows:

𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒 =�𝑒𝑟 𝑜𝑑 𝑑𝑢𝑟𝑎𝑡 𝑜𝑛

𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒 𝑐𝑦𝑐𝑙 𝑐 𝑛𝑡𝑒𝑟𝑟𝑢�𝑡 𝑂𝐵

Note To maintain a continuous signal characteristic of the curve, the clock cycle of the calling cyclic interrupt OB depending on the period duration should not be selected to large.

The figure below shows the signal characteristic of the calculated values.

Figure 3-75: Signal characteristic at "offset" = 0

y

Amplitude

0Time

-AmplitudePeriod duration

Page 105: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 105

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7.7 FB LGF_SinusCI (NEW)

Short description

This block generates a sinusoidal signal characteristic.

Block

Figure 3-76: FB LGF_SinusCI

FB LGF_SinusCI

REAL amplitude sinusValues REAL

REAL offset error BOOL

UDINT periodeMS statusID UINT

OB_CYCLIC callOB status WORD

BOOL reset

Input parameters

Table 3-144: Input parameters

Parameter Data type Description

amplitude REAL Amplitude of the signal characteristic.

offset REAL Offset of the signal characteristic in Y direction.

periodeMS UDINT Period duration of the signal characteristic in [ms]

callOB OB_CYCLIC Calling cyclic interrupt OB

reset BOOL Reset of the signal characteristic.

Note Changes at the input parameters will be effective immediately.

Output parameters

Table 3-145: Output parameters

Parameter Data type Description

sinusValues REAL Current value of the triangle signal.

Status and error displays

Table 3-146: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 no errors Job completed.

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" the constant name of a configured cyclic interrupt OB.

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Page 106: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 106

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

This block calculates the values for a sinusoidal signal characteristic which are output at the output parameter "sinusValues".

The amplitude "amplitude", the offset in Y direction "offset" and the period duration "periodeMS" can be specified at the input parameters.

You can use the input parameter "reset" to reset the signal characteristic. At the output parameter "sinusValues", the value "0" is output as long as "reset" is set to "TRUE".

The block must be called in a cyclic interrupt OB. The clock cycle of the calling cyclic interrupt OB is determined in the FB with the instruction "QRY_CINT". For this, the constant name of the calling cyclic interrupt OB must be interconnected at the input parameter "callOB".

Figure 3-77: Interconnecting the cyclic interrupt OB

The number of calculated values of the signal characteristic for each period duration is calculated as follows:

𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒 =�𝑒𝑟 𝑜𝑑 𝑑𝑢𝑟𝑎𝑡 𝑜𝑛

𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒 𝑐𝑦𝑐𝑙 𝑐 𝑛𝑡𝑒𝑟𝑟𝑢�𝑡 𝑂𝐵

Note To maintain a continuous signal characteristic of the curve, the clock cycle of the calling cyclic interrupt OB depending on the period duration should not be selected to large.

The figure below shows the signal characteristic of the calculated values.

Figure 3-78: Signal characteristic at "offset" = 0

y

Amplitude

0Time

-AmplitudePeriod duration

Page 107: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 107

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.7.8 FB LGF_CosinusCI (NEW)

Short description

This block generates a cosinusoidal signal characteristic.

Block

Figure 3-79: FB LGF_CosinusCI

FB LGF_CosinusCI

REAL amplitude cosinusValues REAL

REAL offset error BOOL

UDINT periodeMS statusID UINT

OB_CYCLIC callOB status WORD

BOOL reset

Input parameters

Table 3-147: Input parameters

Parameter Data type Description

amplitude REAL Amplitude of the signal characteristic.

offset REAL Offset of the signal characteristic in Y direction.

periodeMS UDINT Period duration of the signal characteristic in [ms]

callOB OB_CYCLIC Calling cyclic interrupt OB

reset BOOL Reset of the signal characteristic.

Note Changes at the input parameters will be effective immediately.

Output parameters

Table 3-148: Output parameters

Parameter Data type Description

cosinusValues REAL Current value of the triangle signal.

Status and error displays

Table 3-149: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 no errors Job completed.

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" the constant name of a configured cyclic interrupt OB.

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Page 108: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.7 Signal generators

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 108

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function principle

This block calculates the values for a cosinusoidal signal characteristic which are output at the output parameter "cosinusValues".

The amplitude "amplitude", the offset in Y direction "offset" and the period duration "periodeMS" can be specified at the input parameters.

You can use the input parameter "reset" to reset the signal characteristic. At the output parameter "cosinusValues", the value "0" is output as long as "reset" is set to "TRUE".

The block must be called in a cyclic interrupt OB. The clock cycle of the calling cyclic interrupt OB is determined in the FB with the instruction "QRY_CINT". For this, the constant name of the calling cyclic interrupt OB must be interconnected at the input parameter "callOB".

Figure 3-80: Interconnecting the cyclic interrupt OB

The number of calculated values of the signal characteristic for each period duration is calculated as follows:

𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒 =�𝑒𝑟 𝑜𝑑 𝑑𝑢𝑟𝑎𝑡 𝑜𝑛

𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒 𝑐𝑦𝑐𝑙 𝑐 𝑛𝑡𝑒𝑟𝑟𝑢�𝑡 𝑂𝐵

Note To maintain a continuous signal characteristic of the curve, the clock cycle of the calling cyclic interrupt OB depending on the period duration should not be selected to large.

The figure below shows the signal characteristic of the calculated values.

Figure 3-81: Signal characteristic at "offset" = 0

y

Amplitude

0Time

-AmplitudePeriod duration

Page 109: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 109

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.8 Technology operations

3.8.1 FB LGF_LimRateOfChangeBasic

Short description

This block limits the rate of change of an input value. A jump function becomes a ramp function.

Block

Figure 3-82: FB LGF_LimRateOfChangeBasic

FB LGF_LimRateOfChangeBasic

REAL inputValue outputValue REAL

REAL setRateLim error BOOL

REAL defaultOutValue statusID UINT

BOOL onDefaultOutValue status WORD

OB_CYCLIC callOB

Input parameters

Table 3-150: Input parameters

Parameter Data type Description

inputValue REAL Input value (jump function)

setRateLim REAL Rate of change of the ramp function (1/second)

onDefaultOutValue BOOL Preassign the output quantity

defaultOutValue REAL Value for preassigning the output quantity

callOB OB_CYCLIC Calling cyclic interrupt OB

Output parameters

Table 3-151: Output parameters

Parameter Data type Description

outputValue REAL output quantity

error BOOL 0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code

statusID UINT "statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below)

Page 110: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 110

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-152: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 No errors -

1 16#7000 Initial value "onDefaultOutValue" active

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" a configured / available cyclic interrupt OB.

1 16#8201 Negative rate of change. The parameter for the rate of change must not be negative.

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

The ramp is a limitation line and refers to a rate of change per second. If, for example, "setRateLim = 10.0" is configured, 10.0/1.0/0.1 is added to "outputValue" for a sampling time of 1s/100ms/10ms with each call of a block if "inputValue > outputValue" until "inputValue" is reached.

The limitation of the rate of change applies both in the positive and negative range of values as well as for an increase and a decrease.

The output "outputValue" can be preassigned or initialized.

The clock cycle of the calling cyclic interrupt OB in which the calling cyclic interrupt OB is interconnected at the input parameter “callOB” is determined.

Figure 3-83: Interconnecting the cyclic interrupt OB

Preassign the output

If "onDefaultOutValue = TRUE" is set, "defaultOutValue" is output at the output. If TRUE is changed to FALSE, "outputValue" is run as a ramp from "defaultOutValue" to "inputValue". When changing from FALSE to TRUE, the output "outputValue" immediately jumps to "defaultOutValue".

Page 111: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 111

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function characteristics

Figure 3-84: Ramp function characteristic

defaultOutValue

t

outputValue

inputValue (t)

onDefaultOutValue

Page 112: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 112

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.8.2 FB LGF_LimRateOfChangeAdvanced

Short description

The block LGF_LimRateOfChangeAdvanced limits the rate of change of an input value. Jump functions become ramp functions. Additionally, the block offers various operating modes.

Block

Figure 3-85: FB LGF_LimRateOfChangeAdvanced

FB LGF_LimRateOfChangeAdvanced

REAL inputValue outputValue REAL

REAL setPosUpRateLim posUpRateLim BOOL

REAL setPosDownRateLim posDownRateLim BOOL

REAL setNegUpRateLim negUpRateLim BOOL

REAL setNegDownRateLim negDownRateLim BOOL

REAL setHighLim highLim BOOL

REAL setLowLim lowLim BOOL

REAL processValue error BOOL

REAL defaultOutValue statusID UINT

BOOL onDefaultOutValue status WORD

BOOL track

BOOL manOp

BOOL reset

OB_CYCLIC callOB

Input parameters

Table 3-153: Input parameters

Parameter Data type Description

inputValue REAL Input value (jump function)

setPosUpRateLim REAL Rate of change per second for rising ramp in the positive range of values

setPosDownRateLim REAL Rate of change per second for falling ramp in the positive range of values

setNegUpRateLim REAL Rate of change per second for rising ramp in the negative range of values

setNegDownRateLim REAL Rate of change per second for falling ramp in the negative range of values

setHighLim REAL Upper limit

setLowLim REAL Lower limit

processValue REAL Process value

defaultOutValue REAL Value for preassigning the output quantity

onDefaultOutValue BOOL Preassign the output quantity

track BOOL Switching an input value (tracking)

manOp BOOL Switching a process value

Page 113: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 113

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Parameter Data type Description

reset BOOL Restart

callOB OB_CYCLIC Calling cyclic interrupt OB

Output parameters

Table 3-154: Output parameters

Parameter Data type

Description

outputValue REAL output quantity

posUpRateLim BOOL Rise limitation in the positive range activated

posDownRateLim BOOL Fall limitation in the positive range activated

negUpRateLim BOOL Rise limitation in the negative range activated

negDownRateLim BOOL Fall limitation in the negative range activated

highLim BOOL Upper limit activated

lowLim BOOL Lower limit activated

error BOOL

0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code

statusID UINT "statusID" outputs the ID of the block that signals the status. See table below

status WORD "status" outputs the status/error code (see table below)

Page 114: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 114

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Status and error displays

Table 3-155: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 No errors -

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" a configured / available cyclic interrupt OB.

1 16#8201 "setHighLim" < "setLowLim" Upper limit "setHighLim" must be higher than the lower limit "setLowLim".

1 16#8202 Negative rate of change. Parameters for the rate of change must only be >= 0.0

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Function principle

For the positive/negative range of values, two rates of change can be configured each for the ramp (increasing and decreasing values). The following operating modes can be selected via control inputs:

Restart

Preassigning the output

Normal operation (automatic)

Tracking

Switching a process value (manual)

The output quantity can be limited by two configurable limits. An active limitation of the rate of change of a ramp as well as an active limitation of the output quantity are signaled via outputs.

The clock cycle of the calling cyclic interrupt OB in which the calling cyclic interrupt OB is interconnected at the input parameter “callOB” is determined.

Figure 3-86: Interconnecting the cyclic interrupt OB

Page 115: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 115

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Restart

With restart set to "reset = TRUE", the output "outputValue" is reset to 0.0. If "onDefaultOutValue = TRUE" is set, "defaultOutValue" will be output. All signal outputs are set to FALSE.

Preassign the output

If "onDefaultOutValue = TRUE" is set, "defaultOutValue" is output at the output. If TRUE is changed to FALSE, "outputValue" is run as a ramp from "defaultOutValue" to "inputValue”. When changing from FALSE to TRUE, the output "outputValue" immediately jumps to "defaultOutValue".

Normal operation

The ramps are limitation lines and refer to a rate of change per second. If, for example, "setPosUpRateLim = 10.0" is configured, 10.0/1.0/0.1 is added to "outputValue" for a sampling time of 1s/100ms/10ms with each call of a block if "inputValue > outputValue" until "inputValue" is reached.

The limitation of the rate of change can be configured in the positive and negative range of values respectively for an increase and a decrease.

Table 3-156: Designation of the ramps

Parameter Ramp

setPosUpRateLim outputValue > 0 and |outputValue| rising

setPosDownRateLim outputValue > 0 and |outputValue| falling

setNegUpRateLim outputValue < 0 and |outputValue| rising

setNegDownRateLim outputValue < 0 and |outputValue| falling

If the ramps are not configured ("setPosUpRateLim", "setPosDownRateLim", "setNegUpRateLim" and "setNegDownRateLim" equal to 0.0), the output remains at the value 0.0 and normal operation is out of operation.

Tracking

If the input is set to "track = TRUE", the input value “inputValue” will be interconnected directly to the output quantity “outputValue”. Thus, jumps of the input quantity are output as well.

Switching a process value

If "manOp = TRUE" is set, the process value "processValue" will be switched directly to the output quantity "outputValue".

In this operating mode, the configuration of the ramps or the upper/lower limits of the output quantity as well as the preassignment of the output are ineffective.

When changing from TRUE to FALSE, the output "outputValue" is run once again as a ramp to "inputValue".

As soon as the value section between the lower and the upper limitation has been reached, the upper and lower limitation is reactivated.

Page 116: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 116

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Function characteristics

Figure 3-87: Ramp function characteristic, operating modes

setHighLiminputValue (t)

setLowLim

processValue (t)

t

outputValue

defaultOutValue

highLim

posNegRateLim

lowLim

posUpRateLim

negDownRateLim

negUpRateLim

manOp

track

onDefaultOutValue

Page 117: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 117

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.8.3 FB LGF_Ramp

Short description

This block generates a speed curve by means of a support point table. Between the points, there is a linear interpolation within the specified time.

Block

Table 3-157: FB LGF_Ramp

FB LGF_Ramp

REAL defaultOutValue outputValue REAL

INT contStepNbr actTimeTable BOOL

TIME contStepTime stepNumber INT

BOOL onDefaultOutValue remainTime TIME

BOOL start totalTime TIME

BOOL hold remainTotalTime TIME

BOOL continue error BOOL

BOOL cyclicOP statusID UINT

BOOL updateTime status WORD

BOOL reset

OB_CYCLIC callOB

ARRAY of "typeTimeTable" setpoints

Input parameters

Table 3-158: Input parameters

Parameter Data type Description

defaultOutValue REAL Value for preassigning the output quantity

contStepNbr INT Number of the next support point to continue

contStepTime

TIME Remaining time to continue until the support time "contStepNbr"

onDefaultOutValue BOOL Preassign output quantity with "defaultOutValue"

start BOOL Track support point table

hold BOOL Hold current value at output

continue BOOL Continue

cyclicOP BOOL Repeat support point table cyclically

updateTime BOOL Update time values

reset BOOL Restart

callOB OB_CYCLIC Calling cyclic interrupt OB

setpoints

ARRAY of "typeTimeTable"

Support point table. Information on the data type "typeTimeTable" can be found under "Global data".

Page 118: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 118

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-159: Output parameters

Parameter Data type Description

outputValue REAL output quantity

actTimeTable BOOL Support point table is currently being processed.

stepNumber INT Current support point number (support point that is switched)

remainTime TIME Remaining time until the next support point is reached

totalTime TIME Total time

remainTotalTime TIME Total remaining time

error

BOOL

0: no errors

1: Block error, "statusID" outputs the error source, "status" outputs the error code.

statusID

UINT

"statusID" outputs the ID of the block that signals the status. See the table below.

status WORD "status" outputs the status/error code (see table below).

Status and error displays

Table 3-160: Status/error codes

statusID status Meaning Remedy / notes

1 16#0000 no errors Job completed.

1 16#7000 Initial value Restart has been performed.

1 16#7001 first call Rising edge "start".

1 16#7002 Subsequent call Input "cyclicOP" is set.

1 16#8200 OB at the input "callOB" is not configured / available.

Interconnect at the input "callOB" a configured / available cyclic interrupt OB.

1 16#8201 Lower array limit <> 0 The array with the support points must begin with index 0.

2 - Error / status of the subordinate function "QRY_CINT" when requesting the cyclic interrupt parameters.

Possible cause: OB at the input "callOB" is of the wrong type.

Note If "statusID" > 1, all values of the output "status" come from directly called instructions (see table Output parameters). In this case, refer to the information given in the TIA Portal Online Help on the corresponding instructions.

Global data

Together with the block, you automatically receive the PLC data type "typeTimeTable" consisting of the parameters "outVal" for the value of a support point and "time" for the time until the next support point is reached. The declaration is done in a one-dimensional array of the data type "typeTimeTable", beginning with the index 0. The array is created in a global data block and is then transferred to the block "LGF_Ramp".

Page 119: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 119

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Figure 3-88: Example for the declaration of support points

The parameter "time" of the last support point needs to be configured with 0s, since there is no longer any subsequent support point.

Function principle

With the block, speed curves can be performed by means of configured support points. In each call cycle, values are output according to a time schedule and there is an interpolation between the support points.

In each cycle, the currently switched support point number “stepNumber”, the current remaining time “remainTime” until the support point has been reached, the total time “totalTime” and the total remaining time “remainTotalTime” until the speed curve end has been reached are output. Also, the “actTimeTable” output is set in the moment in which the configured speed curve is output.

The clock cycle of the calling cyclic interrupt OB in which the calling cyclic interrupt OB is interconnected at the input parameter “callOB” is determined.

Figure 3-89: Interconnecting the cyclic interrupt OB

The following operating modes can be selected via control inputs:

Restart

Preassign the output

Output speed curve

Stop processing

Specify processing step and time

Switch to cyclic operation

Update total time and total remaining time

Overview of the operating modes

Table 3-161: Overview of the operating modes

Operating mode onDefaultOutValue

start hold continue cyclicOP updateTime reset Output/action

Restart TRUE ↑ Block is initialized.

Page 120: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 120

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Operating mode onDefaultOutValue

start hold continue cyclicOP updateTime reset Output/action

Preassign the output TRUE TRUE FALSE defaultOutValue

Output speed curve FALSE TRUE ↑ FALSE FALSE FALSE outputValue(t); final value is held after processing

Stop speed curve FALSE TRUE TRUE FALSE FALSE Current value of outputValue(t) is held

Specify processing step and time

FALSE TRUE TRUE TRUE ↑ FALSE outputValue (alt)

FALSE Continue with configured support point

Switch to cyclic operation FALSE TRUE FALSE TRUE FALSE outputValue(t); automatic restart after end

Update total time and total remaining time

TRUE ↑ FALSE Total time and total remaining time are updated.

Restart

A rising edge at the input "reset" resets the output "outValue" to 0.0. With "onDefaultOutValue" = TRUE, "defaultOutValue" is output at the output. The total time and total remaining time are updated and output at the output.

Preassign the output

If the speed curve shall start with a particular output value, then "onDefaultOutValue" = TRUE must be set. In this case, the value "defaultOutValue" is present at the output of the timer. All the while, the internal processing of the speed curve continues. If "onDefaultOutValue" switches to FALSE again, it will be interpolated to the currently active support point.

Output speed curve

With a rising edge at the “start” input, the speed curve will be output – as long as “start” is TRUE or until the speed curve has been finished by reaching the last support point. With another rising edge, the speed curve is output again. Additionally, the total time is updated at each start-up.

Switch to cyclic operation

If, in addition to the “start” input, the “cyclicOP” input is also set to TRUE, the speed curve automatically returns to the starting point after the output of the last support point value and starts a new cycle.

There is no interpolation between the last support point value and the starting point. For a bumpless transition, the following needs to apply: last support point value = starting point.

Stop speed curve

With “hold” = TRUE, the value of the output quantity (including the processing time) is frozen. If “hold” is reset to = FALSE, it will be continued at the point of interruption or at a configured point (see “Specify processing step and time”). The processing time of the speed curve is extended by the hold time "T1*" (seeFigure 3-90).

Specify processing step and time

If during the interruption of the speed curve (“hold” = TRUE), the “continue” input parameter for the continuation is set to TRUE, then, after resetting the “hold” input,

Page 121: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 121

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

the support point number "contStepNbr" (destination support point) is switched within the "contStepTime" time period (interpolation). The total remaining time will be recalculated.

Update total time and total remaining time

If support point values are changed, the total time and the total remaining time of the speed curve may change. Since for many support points, a calculation of “totalTime” and “remainTotalTime” may significantly increase the processing time of the function block, it will only be performed once, with a rising edge at the “updateTime” input.

Function characteristics

Figure 3-90: Function characteristics

onDefaultOutValue

start

hold

continue

configured trendcurrent trend

* current values

outputValue

t

T* = contStepTime

3 4/ 4* = contStepNbr

T1*

defaultOutValueT1*21

0 5 5* 6*6

actTimeTable

setpoints[…].outVal

0 1 2 3 4 5setpoints[…].time4 + T1* 5

Page 122: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 122

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

3.8.4 FB LGF_NonLin

Short description

The block realizes a characteristic. The characteristic is specified via a support point table with linear interpolation between the support points. In every cycle, a specified input value generates an output value by means of the characteristic from the support point table.

Block

Figure 3-91: FB LGF_NonLin

FB LGF_NonLin

REAL inputValue outputValue REAL

REAL defaultOutValue

BOOL onDefaultOutValue

BOOL track

BOOL reset

LGF_type

NonLinSetpoints setpoints

Input parameters

Table 3-162: Input parameters

Parameter Data type Description

inputValue REAL Input value for calculating the output value via the defined characteristic.

defaultOutValue REAL Default output value without using the characteristic

onDefaultOutValue BOOL Activating the default output value The default output value will be output as long as this input is set.

track BOOL The value of the output "outputValue" tracks the value of the input "inputValue" without using the characteristic as long as this input is set.

reset BOOL If the support point table is changed during operation, the input "reset" needs to be activated subsequently. Otherwise, the block might not function properly.

Input/output parameters (InOut)

Table 3-163: Input/output parameters (InOut)

Parameter Data type Description

setpoints LGF_typeNonLinSetpoints Support point table for defining the characteristic

Page 123: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 123

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 3-164: Output parameters

Parameter Data type Description

outputValue REAL Output value that has been calculated using the input value via the defined characteristic.

Function principle

The value of the output "outputValue" is output based on the following priority:

1. As long as the input "onDefaultOutValue" is set, the value defined via the parameter "defaultOutValue" will be output as output value.

2. As long as the input "reset" is set, the block will be reset and the value 0.0 will be output as output value.

3. As long as the input "track" is set, the input value will be directly output as output value, without taking into account the characteristic.

4. On the basis of the input value, a characteristic value is calculated via the linearly interpolated support point table and output as output value.

– If the input value is located between two support points within the support point table, the output value is calculated as intersection with the connection line between the previous and the next support point (see Figure 3-92).

– If the input value is located before the first support point (lowest value that has been defined in the support point table), the output value is calculated as intersection of the line that is formed by the first two support points of the support point table.

– If the input value is located after the last support point (highest value that has been defined in the support point table), the output value is calculated as intersection of the line that is formed by the last two support points of the support point table.

Figure 3-92: Exemplary characteristic of the output signal

Output signal

Input signal

Page 124: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

3 Explanation of the Blocks

3.8 Technology operations

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 124

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

ATTENTION To keep the calculating time of the block as low as possible, no check of the configuration or the support point table data will be performed.

When the support points are entered in the support point table, the following particularities need to be observed. Otherwise, malfunction of the block may occur.

At least two support points need to be entered in the support point table.

The support points in the support point table need to be entered in ascending order of the input values in the table.

Support point table

The support point table is realized by a tag of the data type Array. The type of the array corresponds to the PLC data type "LGF_typeNonLinSetpoint".

You can create the support point table in any global data block. The size of the array depends on the number of support points.

Example

Figure 3-93: Exemplary data block

3.8.5 Closed-Loop Control of Simulated Controlled Systems

This entry provides you with the block library "LSim" for simulating controlled systems for the SIMATIC S7-1200 and S7-1500 controller families.

https://support.industry.siemens.com/cs/ww/en/view/79047707

Page 125: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

4 Links & Literature

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 125

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

4 Links & Literature

Table 4-1 Links & Literature

Topic

\1\ Siemens Industry Online Support

http://support.automation.siemens.com

\2\ Download page of the entry

https://support.industry.siemens.com/cs/ww/en/view/109479728

\3\ Programming Guideline and Programming Styleguide

https://support.industry.siemens.com/cs/ww/en/view/81318674

\4\ Library with PLC data types (LPD) for STEP 7 (TIA Portal) and S7-1200 / S7-1500

https://support.industry.siemens.com/cs/ww/en/view/109482396

\5\ Guideline on Library Handling

https://support.industry.siemens.com/cs/ww/en/view/109747503

\6\ Topic page libraries

https://support.industry.siemens.com/cs/ww/en/view/109738702

Page 126: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

5 History

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 126

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

5 History

5.1 Library versioning

The library and library elements are maintained according to the following table:

Table 5-1: Definition of the version

V 1. 2. 3.

Non-compatible changes Compatible changes Error correction

Reduction of interfaces

Modification of interfaces

Incompatible extension of functionality

Extension of interfaces

Compatible extension of functionality

Bugfix

Upgrade to new TIA Portal version

Versioning example

Table 5-2: Example for changing the version

Library FB1 FB2 FC1 FC2 Comment

1.0.0 1.0.0 1.0.0 1.0.0 - Released

1.0.1 1.0.1 1.0.0 1.0.0 - Error handling of FB1

1.0.2 1.0.1 1.0.1 1.0.0 - Optimization of FB2

1.1.0 1.1.0 1.0.1 1.0.0 - Expansion at FB1

1.2.0 1.2.0 1.0.1 1.0.0 - Expansion at FB1

2.0.0 2.0.0 1.0.1 2.0.0 - New functionality at FB1 and FC1

2.0.1 2.0.0 1.0.2 2.0.0 - Error handling of FB2

3.0.0 2.0.0 1.0.2 2.0.0 1.0.0 New function FC2

3.0.1 2.0.1 1.0.3 2.0.1 1.0.1 Upgrade to new TIA Portal version

3.0.2 2.0.2 1.0.4 2.0.2 1.0.0 New functions, error handlings

Page 127: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

5 History

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 127

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

5.2 Change log

Table 5-3: Change log

Version Date Modifications

V1.0.0 09/2015 First version

V1.0.1 10/2015 LGF_Astro V1.0.1

T_ADD instruction replaced by "+”.

V1.0.2 10/2015 LGF_BinaryToGray V1.0.1

Name changed

LGF_GrayToBinary V1.0.1

Name changed

V1.0.3 11/2015 LGF_CompareVariant V1.0.1

Error correction

V1.0.4 11/2015 LGF_SawTooth V1.0.1

Error correction

V1.0.5 11/2015 LGF_Astro V1.0.2

Error correction

LGF_AverageAndDeviation V1.0.1

Error correction

LGF_TimerSwitch V1.0.1

Error correction

LGF_FIFO V1.0.1

Error correction

V2.0 07/2016 New:

Chapter 1.3 Library resources

FB LGF_PulseRelay V1.0.0

FB LGF_SetTime V1.0.0

FB LGF_FloatingAverage V1.0.0

FC LGF_DTLtoString V1.0.0

FC LGF_StringToDTL V1.0.0

FB LGF_LimRateOfChangeBasic V1.0.0

FB LGF_LimRateOfChangeAdvanced V1.0.0

Revised:

LGF_Astro V1.1.1

Outputs systemTime and localTime added

FB LGF_TimerSwitch V1.1.0

Two new modes: Weekday, weekend

FB LGF_ShallSort… V1.1.0

New mode: Sort in descending order

FB LGF_Frequency V1.1.0

New function: Pulse-pause ratio adjustable

FB LGF_Impulse V1.1.0

Calls new LGF_Frequency V1.1.0.

V2.0.1 01/2017 Revised:

LGF_Astro V1.1.2

Error correction for sunrise and sunset calculation.

V2.0.2 01/2017 Revised:

All blocks: Upgrade TIA V14

V3.0.0 03/2017 New:

Page 128: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

5 History

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 128

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Version Date Modifications

FC LGF_CalendarDayWeekV1.0.0

FC LGF_CompareReal V1.0.0

FC LGF_RandomBasic V1.0.0

FC LGF_HighLowLimit V1.0.0

FC LGF_BitsToWord V1.0.0

FC LGF_WordToBits V1.0.0

FC LGF_ScaleLinear V1.0.0

FC LGF_StringToTaddr V1.0.0

FC LGF_TaddrToString V1.0.0

FB LGF_Ramp V1.0.0

FB LGF_NonLin V1.0.0

Revised:

Supplementation in chapter 5.1 Library versioning

FB LGF_PulseRelay V1.0.2

Commentary correction

FB LGF_Astro V1.1.4

Code optimization

FB LGF_SetTime V1.0.2

Correction: FB number: automatic

FB LGF_FloatingAverage V1.1.0

Code optimization

New input parameter "windowSize"

FC LGF_MatrixAddition V2.0.0

Code optimization

Input parameters changed to ARRAY*

FC LGF_MatrixInverse V2.0.0

Code optimization

Input parameters changed to ARRAY*

FC LGF_MatrixMultiplication V2.0.0

Code optimization

Input parameters changed to ARRAY*

FC LGF_MatrixSubtraction V2.0.0

Code optimization

Input parameters changed to ARRAY*

FC LGF_MatrixTranspose V2.0.0

Code optimization

Input parameters changed to ARRAY*

FB LGF_Impulse V1.2.0

Code optimization: No call of LGF_Frequency any longer

V3.0.1 05/2017 Revised:

FB LGF_Ramp V1.0.1

Commentary correction

V4.0.0 09/2018 New:

FC LGF_GermanHoliday V1.0.0 FC LGF_Factorial V1.0.0 FC LGF_Distance V1.0.0 FB LGF_LIFO V1.0.0 FC LGF_CRC8 V1.0.0

Page 129: Library of General Functions (LGF) for S7-1200/1500 · 2018. 11. 6. · Warranty and Liability Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 2 G 8 d Warranty

5 History

Library of General Functions (LGF) Entry ID: 109479728, V4.0.2, 10/2018 129

S

iem

en

s A

G 2

01

8 A

ll ri

gh

ts r

ese

rve

d

Version Date Modifications

FC LGF_CRC8For1Byte V1.0.0 FC LGF_CRC16 V1.0.0 FC LGF_CRC32 V1.0.0 FC LGF_IntToString V1.0.0 FC LGF_TimeToString V1.0.0 FB LGF_SawToothCI V1.0.0 FB LGF_TriangleCI V1.0.0 FB LGF_RectangleCI V1.0.0 FB LGF_SinusCI V1.0.0 FB LGF_CosinusCI V1.0.0

Revised:

Supplementation in chapter 2.2 Simulatability with SIMATIC S7-PLCSIM Advanced (NEW)

FB LGF_Astro V1.1.5

Code optimization

FB LGF_TimerSwitch V1.1.2

Code optimization

V4.0.1 - Only for TIA Portal V15

V4.0.2 10/2018 FB LGF_TimerSwitch V1.1.3

Connection to type restored.