Legal information
Library of General Functions (LGF)
Entry ID: 109479728, V4.0.2, 10/2018
2
Siemens AG 2018 All rights reserved
Legal information
Use of application examples
Application examples illustrate the solution of automation tasks through an interaction of several
components in the form of text, graphics and/or software modules. The application examples are
a free service by Siemens AG and/or a subsidiary of Siemens AG (“Siemens”). They are non-
binding and make no claim to completeness or functionality regarding configuration and
equipment. The application examples merely offer help with typical tasks; they do not constitute
customer-specific solutions. You yourself are responsible for the proper and safe operation of the
products in accordance with applicable regulations and must also check the function of the
respective application example and customize it for your system.
Siemens grants you the non-exclusive, non-sublicensable and non-transferable right to have the
application examples used by technically trained personnel. Any change to the application
examples is your responsibility. Sharing the application examples with third parties or copying the
application examples or excerpts thereof is permitted only in combination with your own products.
The application examples are not required to undergo the customary tests and quality inspections
of a chargeable product; they may have functional and performance defects as well as errors. It is
your responsibility to use them in such a manner that any malfunctions that may occur do not
result in property damage or injury to persons.
Disclaimer of liability
Siemens shall not assume any liability, for any legal reason whatsoever, including, without
limitation, liability for the usability, availability, completeness and freedom from defects of the
application examples as well as for related information, configuration and performance data and
any damage caused thereby. This shall not apply in cases of mandatory liability, for example
under the German Product Liability Act, or in cases of intent, gross negligence, or culpable loss of
life, bodily injury or damage to health, non-compliance with a guarantee, fraudulent
non-disclosure of a defect, or culpable breach of material contractual obligations. Claims for
damages arising from a breach of material contractual obligations shall however be limited to the
foreseeable damage typical of the type of agreement, unless liability arises from intent or gross
negligence or is based on loss of life, bodily injury or damage to health. The foregoing provisions
do not imply any change in the burden of proof to your detriment. You shall indemnify Siemens
against existing or future claims of third parties in this connection except where Siemens is
mandatorily liable.
By using the application examples you acknowledge that Siemens cannot be held liable for any
damage beyond the liability provisions described.
Other information
Siemens reserves the right to make changes to the application examples at any time without
notice. In case of discrepancies between the suggestions in the application examples and other
Siemens publications such as catalogs, the content of the other documentation shall have
precedence.
The Siemens terms of use (https://support.industry.siemens.com) shall also apply.
Security information
Siemens provides products and solutions with industrial security functions that support the secure
operation of plants, systems, machines and networks.
In order to protect plants, systems, machines and networks against cyber threats, it is necessary
to implement – and continuously maintain – a holistic, state-of-the-art industrial security concept.
Siemens’ products and solutions constitute one element of such a concept.
Customers are responsible for preventing unauthorized access to their plants, systems, machines
and networks. Such systems, machines and components should only be connected to an
enterprise network or the Internet if and to the extent such a connection is necessary and only
when appropriate security measures (e.g. firewalls and/or network segmentation) are in place.
For additional information on industrial security measures that may be implemented, please visit
https://www.siemens.com/industrialsecurity.
Siemens’ products and solutions undergo continuous development to make them more secure.
Siemens strongly recommends that product updates are applied as soon as they are available
and that the latest product versions are used. Use of product versions that are no longer
supported, and failure to apply the latest updates may increase customer’s exposure to cyber
threats.
To stay informed about product updates, subscribe to the Siemens Industrial Security RSS Feed
at: https://www.siemens.com/industrialsecurity.
Table of Contents
Library of General Functions (LGF)
Entry ID: 109479728, V4.0.2, 10/2018
3
Siemens AG 2018 All rights reserved
Table of Contents
Legal information ......................................................................................................... 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
Table of Contents
Library of General Functions (LGF)
Entry ID: 109479728, V4.0.2, 10/2018
4
Siemens AG 2018 All rights reserved
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
1 Library Overview
1.1 General
Library of General Functions (LGF)
Entry ID: 109479728, V4.0.2, 10/2018
5
Siemens AG 2018 All rights reserved
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.