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


Library overview

General information

TIA Portal has an extensive number of "ready-to-use" instructions (mathematical functions, times, counters, etc.). In addition, there are other useful basic functions.

These functions are provided in the form of a library and they can be used freely. The finished functions are freely customizable and can therefore be used universally.

The library described here is versioned and it will be continuously extended. For information on versioning, see Chapter "Versioning".

Hardware and software requirements

Requirements for this library

In order to be able to use the functionality of the library described here, the following hardware and software requirements must be met.

Hardware

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

Software


NOTE
In general, it is possible to open a library with STEP 7 Basic, although STEP 7 Professional elements (e.g. SIMATIC S7-1500 controller) are included. In this case you will be informed with a message when opening the library.
All elements (types and copy templates) can be used if they are supported by the hardware installed in the TIA Portal.
If you try to copy elements with STEP 7 Basic from the library that are not supported (e.g. SIMATIC S7-1500 controller), an error message is displayed.

Working with the library

General information

All blocks in the "LGF" library can be used freely in conjunction with SIMATIC S7-1200 and SIMATIC S7-1500 controllers.

Most of the blocks are stored as types in the library. This means that the blocks are versioned and can thus use all advantages.


Note
Information on the general handling of libraries is provided in the Guideline for Library Handling
https://support.industry.siemens.com/cs/ww/en/view/109747503
and in the Programming Guideline for S7-1200/1500 in the chapter "Libraries".
https://support.industry.siemens.com/cs/ww/en/view/81318674

Note
All blocks in the LGF were created in accordance with the Programming Style Guide.
https://support.industry.siemens.com/cs/ww/en/view/81318674

For more information on libraries, visit the TIA Portal:


Simulation capability with SIMATIC S7-PLCSIM Advanced

Simulation with SIMATIC S7-PLCSIM Advanced is already activated in the properties of the LGF blocks.

Block properties

After translation with SIMATIC S7-PLCSIM Advanced, proceed as follows so that the blocks can be simulated.

  1. Open the properties of your project and activate the option "Support simulation during block compilation" in the "Protection" tab.

Project properties


Note
Blocks with activated simulation capability take up more memory space in the PLC.

User-defined documentation (user help)

In order to explain the principle of operation and use of the blocks to users of the LGF library, user-defined documentation has been created for each block.
The user-defined documentation per block is available in German and English as a PDF file. The PDF files are stored in the following directories of the LGF library.

The user-defined documentation for a block can be called up in the Task Card "Library" and in the library view with the key combination <Shift+F1>.
The respective PDF is always opened with the standard program defined in Microsoft Windows.

So that the user-defined documentation of the blocks can also be called up in the project navigation, you must copy the directories with the PDF files into the project directory UserFiles.


Note
For user-defined documentation, you require SIMATIC STEP 7 Basic / Professional V15.1 Update 1.

Central directory for user-defined documentation

Alternatively, you can store the user-defined documentation in a central directory for all projects. To define a central storage location for user help, proceed as follows:

  1. In the "Options" menu, select the "Settings" command.
  2. Open the area "General > General".
  3. Navigate to the "User documentation" section.
  4. Activate the checkbox "Display call log for user-defined documentation" to display a log of the call-up of the user-defined documentation in the Inspector window.
  5. Activate the "Search for user-defined documentation in a central directory" checkbox to store user-defined documentation in a central directory for projects.
  6. In the "Central directory for user-defined documentation" field, specify the path where you want to store cross-project documentation.

Central directory for user defined documentation


Note
Do not change the names of the PDF, because the file name must precisely match the name of the object in the TIA Portal.

Note
Further information on the user-defined documentation can be found in the system manual "SIMATIC STEP 7 Basic/Professional V15.1 and SIMATIC WinCC V15.1":
https://support.industry.siemens.com/cs/ww/en/view/109755202/114872699275

Explanation of the blocks

The chapters below describe all blocks of the library, "Library of General Functions".
The chapters have the same structure as the library itself.

All blocks are divided into application areas or categories:

Global Library (LGF)

Program blocks

PLC data types

PLC tags & constants

Appendix

Service and support

Industry Online Support

Do you have any questions or need assistance?
Siemens Industry Online Support offers round the clock access to our entire service and support know-how and portfolio.
The Industry Online Support is the central address for information about our products, solutions and services.
Product information, manuals, downloads, FAQs, application examples and videos, all information is accessible with just a few mouse clicks:
https://support.industry.siemens.com

Technical Support

The Technical Support of Siemens Industry provides you fast and competent support regarding all technical queries with numerous tailor-made offers - ranging from basic support to individual support contracts. Please send queries to Technical Support via Web form:
https://www.siemens.com/supportrequest

SITRAIN - Digital Industry Academy

We support you with our globally available training courses for industry with practical experience, innovative learning methods and a concept that's tailored to the customer's specific needs.
For more information on our offered trainings and courses, as well as their locations and dates, refer to our web page:
https://www.siemens.com/sitrain

Service offer

Our range of services includes the following:

You can find detailed information on our range of services in the service catalog web page:
https://support.industry.siemens.com/cs/sc

Industry Online Support app

You will receive optimum support wherever you are with the "Siemens Industry Online Support" app. The app is available for iOS and Android:
https://support.industry.siemens.com/cs/ww/en/sc/2067

Industry Mall

Siemens Industry Mall

The Siemens Industry Mall is the platform on which the entire Siemens Industry product portfolio is accessible. From the selection of products to the order and the delivery tracking, the Industry Mall enables the complete purchasing processing – directly and independently of time and location:
https://mall.industry.siemens.com

No. Topic
\1\ Siemens Industry Online Support https://support.industry.siemens.com
\2\ Link to the entry page of the application exampl https://support.industry.siemens.com/cs/ww/en/view/109479728
\3\ Programming Guidelines and Programming Style guide for SIMATIC S7-1200 and S7-1500 https://support.industry.siemens.com/cs/ww/en/view/81318674
\4\ Library with PLC data types (LPD) for STEP 7 (TIA Portal) and SIMATIC S7-1200 / S7-1500 https://support.industry.siemens.com/cs/ww/en/view/109482396
\5\ Guideline on Library Handling in Tia Portal https://support.industry.siemens.com/cs/ww/en/view/109747503
\6\ Libraries in the TIA Portal https://support.industry.siemens.com/cs/ww/en/view/109738702

Change documentation

Versioning of the library

The library and library elements are maintained in accordance with the table below:

P
Non-compatible change Compatible change Error correction
  • Reduction of interfaces
  • Changing the interfaces
  • Incompatible extension of functionality
  • Extension of the interfaces
  • Compatible extension of functionality
  • Bug fix

Versioning example

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 - Troubleshooting 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 - Extension to FB1
1.2.0 1.2.0 1.0.1 1.0.0 - Extension to FB1
2.0.0 2.0.0 1.0.1 2.0.0 - New functionality on FB1 and FC1
2.0.1 2.0.0 1.0.2 2.0.0 - Troubleshooting 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.1 New functions, bug fixes

Change log

Version & DateChange description
V5.1.0
09/2021

NEW:

LGF_BinaryMaskCompare / V01.00.00
LGF_CountBooleanEdges / V01.00.00
LGF_GetBitStates / V01.00.00
LGF_ShiftRegister / V03.00.00

UPDATED:

LGF_BitReset / 03.00.01
  • Insert documentation
LGF_BitSet / 03.00.01
  • Insert documentation
LGF_BitSetTo / 03.00.01
  • Insert documentation
LGF_BitTest / 03.00.01
  • Insert documentation
LGF_BitToggle / 03.00.01
  • Insert documentation
LGF_PulseRelay / 03.00.01
  • Insert documentation
LGF_AstroClock / 03.00.01
  • Bug fix - not enabled - block still running
  • Insert documentation
LGF_GetCalendarDay / 03.00.01
  • Insert documentation
LGF_GetCalendarWeek_ISO / 03.00.01
  • Insert documentation
LGF_GetCalendarWeek_US / 03.00.01
  • Insert documentation
LGF_IsGermanHoliday / 03.00.01
  • fix bug in Constant "DAYS_AFTER_EASTER_60" from 6 to 60
  • Insert documentation
LGF_SetTime / 03.00.02
  • Bug fix - bias correction for time offsets (200 / 330)
  • Insert documentation
LGF_TimerSwitch / 03.00.01
  • Insert documentation
LGF_BitCount / 03.00.02
  • Insert documentation
LGF_CountFalInDWord / 03.00.01
  • Insert documentation
LGF_CountRisInDWord / 03.00.01
  • Insert documentation
LGF_CompareLReal / 03.00.01
  • Insert documentation
LGF_CompareLRealByPrecision / 03.00.01
  • Insert documentation
LGF_CompareVariant / 03.00.01
  • Insert documentation
LGF_CalcDistance_2D / 03.00.01
  • Insert documentation
LGF_CalcDistance_3D / 03.00.01
  • Insert documentation
LGF_GetFactorial / 03.00.01
  • Insert documentation
LGF_Integration / 03.00.02
  • Insert documentation
  • Fix bug - incompatibility with S7-1200 and LTIME
LGF_IsValueInLimits / 03.00.01
  • Insert documentation
LGF_IsValueInRange / 03.00.01
  • Insert documentation
LGF_IsValueInTolerance / 03.00.02
  • Bug fix - negative setpoint verification
  • Insert documentation
LGF_NthRoot / 03.00.01
  • Insert documentation
LGF_Random_DInt / 03.00.01
  • Insert documentation
LGF_Random_Real / 03.00.01
  • Insert documentation
LGF_Random_UDInt / 03.00.01
  • Insert documentation
LGF_RandomRange_Dint / 03.00.01
  • Insert documentation
LGF_RandomRange_Real / 03.00.01
  • Insert documentation
LGF_RandomRange_UDInt / 03.00.01
  • Insert documentation
LGF_ScaleLinear / 03.00.01
  • Insert documentation
  • Move to folder "Math operations"
LGF_SearchMinMax / 03.00.01
  • Rework constants and comments
  • Insert documentation
LGF_SearchMinMax_DInt / 03.00.01
  • Insert documentation
LGF_SearchMinMax_LReal / 03.00.01
  • Insert documentation
LGF_SearchMinMax_UDInt / 03.00.01
  • Insert documentation
LGF_StoreMinMax / 03.00.01
  • Insert documentation
LGF_MatrixAddition / 03.00.01
  • Insert documentation
LGF_MatrixCompare / 03.00.01
  • Insert documentation
LGF_MatrixInverse / 03.00.01
  • Insert documentation
LGF_MatrixMultiplication / 03.00.01
  • Insert documentation
LGF_MatrixScalarMultiplication / 03.00.01
  • Insert documentation
LGF_MatrixSubtraction / 03.00.01
  • Insert documentation
LGF_MatrixTranspose / 03.00.01
  • Insert documentation
LGF_CalcCRC16 / 03.00.01
  • Insert documentation
  • Assign default start values to optional inputs - `initValue`, `mask`
LGF_CalcCRC16Advanced / 03.00.01
  • Insert documentation
  • Assign default start values to optional inputs - `initValue`, `mask`, `finalXorValue`, `reflectInput`, `reflectResult`
LGF_CalcCRC32 / 03.00.01
  • Insert documentation
  • Assign default start values to optional inputs - `initValue`, `mask`
LGF_CalcCRC32Advanced / 03.00.01
  • Insert documentation
  • Assign default start values to optional inputs - `initValue`, `mask`, `finalXorValue`, `reflectInput`, `reflectResult`
LGF_CalcCRC8 / 03.00.01
  • Insert documentation
  • Assign default start values to optional inputs - `initValue`, `mask`
LGF_CalcCRC8Advanced / 03.00.01
  • Insert documentation
  • Assign default start values to optional inputs - `initValue`, `mask`, `finalXorValue`, `reflectInput`, `reflectResult`
LGF_CalcCRC8For1Byte / 03.00.01
  • Insert documentation
  • Assign default start values to optional inputs - `initValue`, `mask`
LGF_FIFO / 03.00.01
  • Insert documentation
LGF_IsParityEven / 03.00.01
  • Insert documentation
LGF_IsParityOdd / 03.00.01
  • Insert documentation
LGF_LIFO / 03.00.01
  • Insert documentation
LGF_ShellSort_DInt / 03.00.01
  • Insert documentation
LGF_ShellSort_LReal / 03.00.01
  • Insert documentation
LGF_ShellSort_UDInt / 03.00.01
  • Insert documentation
LGF_BinaryToGray / 03.00.01
  • Insert documentation
LGF_DTLtoString_DE / 03.00.01
  • Insert documentation
LGF_DTLtoString_ISO / 03.00.01
  • Insert documentation
LGF_DTLToUnixTime / 03.00.01
  • Insert documentation
LGF_GpsDDToGps / 03.00.02
  • Fix `tempStatus` initialization
  • Insert documentation
LGF_GpsToGpsDD / 03.00.02
  • Fix `tempStatus` initialization
  • Insert documentation
LGF_GrayToBinary / 03.00.01
  • Insert documentation
LGF_IntToString / 03.00.01
  • Insert documentation
LGF_StringToDTL_DE / 03.00.01
  • Insert documentation
LGF_StringToDTL_ISO / 03.00.01
  • Insert documentation
LGF_StringToInt / 03.00.01
  • Insert documentation
  • ENO handling done by STRG_VAL system function
LGF_StringToTaddr / 03.00.01
  • Insert documentation
LGF_StringToTime / 03.00.01
  • Insert documentation
LGF_TaddrToString / 03.00.01
  • Insert documentation
LGF_TimeToString / 03.00.01
  • Insert documentation
LGF_UnixTimeToDTL / 03.00.01
  • Insert documentation
LGF_MergeBitsToDWord / 03.00.01
  • Insert documentation
LGF_MergeBitsToWord / 03.00.01
  • Insert documentation
LGF_MergeBytesToDWord / 03.00.01
  • Insert documentation
LGF_MergeBytesToWord / 03.00.01
  • Insert documentation
LGF_MergeWordsToDWord / 03.00.01
  • Insert documentation
LGF_SplitByteToBits / 03.00.01
  • Insert documentation
LGF_SplitDWordToBits / 03.00.01
  • Insert documentation
LGF_SplitDWordToBytes / 03.00.01
  • Insert documentation
LGF_SplitDWordToWords / 03.00.01
  • Insert documentation
LGF_SplitWordToBits / 03.00.01
  • Insert documentation
LGF_SplitWordToBytes / 03.00.01
  • Insert documentation
LGF_CelsiusToFahrenheit / 03.00.01
  • Insert documentation
LGF_CelsiusToKelvin / 03.00.01
  • Insert documentation
LGF_ConvertTemperature / 03.00.01
  • Rename from "LGF_TemperatureConvert" to "LGF_ConvertTemperature"
  • to start with the verb
  • include the Rankine conversion
  • Code refactoring, regions, commends and constants
  • Set version to V3.0.0
  • harmonize the version of the whole library
  • Insert documentation
LGF_FahrenheitToCelsius / 03.00.01
  • Insert documentation
LGF_FahrenheitToKelvin / 03.00.01
  • Insert documentation
LGF_KelvinToCelsius / 03.00.01
  • Insert documentation
LGF_KelvinToFahrenheit / 03.00.01
  • Insert documentation
LGF_KelvinToRankine / 03.00.01
  • Insert documentation
LGF_RankineToKelvin / 03.00.01
  • Insert documentation
LGF_CosinusCI / 03.00.01
  • Insert documentation
LGF_Frequency / 03.00.01
  • Insert documentation
LGF_Impulse / 03.00.01
  • Insert documentation
LGF_RectangleCI / 03.00.01
  • Insert documentation
LGF_SawToothCI / 03.00.01
  • Insert documentation
LGF_SinusCI / 03.00.01
  • Insert documentation
LGF_TriangleCI / 03.00.01
  • Insert documentation
LGF_LimRateOfChangeAdvancedCI / 03.00.01
  • Insert documentation
LGF_LimRateOfChangeCI / 03.00.01
  • Insert documentation
LGF_NonLinearInterpolation / 03.00.01
  • Insert documentation
LGF_RampCI / 03.00.01
  • Insert documentation
  • Change UDT member name from `outValue` to `outputValue`
LGF_AverageAndDeviation / 03.00.01
  • Insert documentation
LGF_Boxplot_DInt / 03.00.01
  • Insert documentation
LGF_Boxplot_LReal / 03.00.01
  • Insert documentation
LGF_Boxplot_UDInt / 03.00.01
  • Insert documentation
LGF_DifferenceQuotientFB / 03.00.01
  • Insert documentation
LGF_DifferenceQuotientFC / 03.00.01
  • Insert documentation
LGF_FloatingAverage / 03.00.02
  • Insert documentation
LGF_Histogram_DInt / 03.00.01
  • Insert documentation
LGF_Histogram_LReal / 03.00.01
  • Insert documentation
LGF_Histogram_UDInt / 03.00.01
  • Insert documentation
LGF_RegressionLine / 03.00.01
  • Insert documentation
LGF_SimpleSmoothingFB / 03.00.01
  • Insert documentation
LGF_SimpleSmoothingFC / 03.00.01
  • Insert documentation
LGF_SmoothByPolynomFB / 03.00.01
  • Insert documentation
LGF_SmoothByPolynomFC / 03.00.01
  • Insert documentation
LGF_SawTooth / 03.00.01
  • Insert documentation
V5.0.0
04/2020

NEW:

LGF_BitReset / V03.00.00
LGF_BitSet / V03.00.00
LGF_BitSetTo / V03.00.00
LGF_BitTest / V03.00.00
LGF_BitToggle / V03.00.00
LGF_PulseRelay / V03.00.00
LGF_AstroClock / V03.00.00
LGF_GetCalendarDay / V03.00.00
LGF_GetCalendarWeek_ISO / V03.00.00
LGF_GetCalendarWeek_US / V03.00.00
LGF_IsGermanHoliday / V03.00.00
LGF_SetTime / V03.00.00
LGF_TimerSwitch / V03.00.00
LGF_CountFalInDWord / V03.00.00
LGF_CountRisInDWord / V03.00.00
LGF_CompareLReal / V03.00.00
LGF_CompareLRealByPrecision / V03.00.00
LGF_CompareVariant / V03.00.00
LGF_CalcDistance_2D / V03.00.00
LGF_CalcDistance_3D / V03.00.00
LGF_GetFactorial / V03.00.00
LGF_Integration / V03.00.00
LGF_IsValueInLimits / V03.00.00
LGF_IsValueInRange / V03.00.00
LGF_IsValueInTolerance / V03.00.00
LGF_NthRoot / V03.00.00
LGF_Random_DInt / V03.00.00
LGF_Random_Real / V03.00.00
LGF_Random_UDInt / V03.00.00
LGF_RandomRange_Dint / V03.00.00
LGF_RandomRange_Real / V03.00.00
LGF_RandomRange_UDInt / V03.00.00
LGF_SearchMinMax / V03.00.00
LGF_SearchMinMax_DInt / V03.00.00
LGF_SearchMinMax_LReal / V03.00.00
LGF_SearchMinMax_UDInt / V03.00.00
LGF_StoreMinMax / V03.00.00
LGF_MatrixInverse / V03.00.00
LGF_MatrixTranspose / V03.00.00
LGF_MatrixAddition / V03.00.00
LGF_MatrixCompare / V03.00.00
LGF_MatrixMultiplication / V03.00.00
LGF_MatrixScalarMultiplication / V03.00.00
LGF_MatrixSubtraction / V03.00.00
LGF_CalcCRC16 / V03.00.00
LGF_CalcCRC16Advanced / V03.00.00
LGF_CalcCRC32 / V03.00.00
LGF_CalcCRC32Advanced / V03.00.00
LGF_CalcCRC8 / V03.00.00
LGF_CalcCRC8Advanced / V03.00.00
LGF_CalcCRC8For1Byte / V03.00.00
LGF_FIFO / V03.00.00
LGF_IsParityEven / V03.00.00
LGF_IsParityOdd / V03.00.00
LGF_LIFO / V03.00.00
LGF_ShellSort_DInt / V03.00.00
LGF_ShellSort_LReal / V03.00.00
LGF_ShellSort_UDInt / V03.00.00
LGF_BinaryToGray / V03.00.00
LGF_DTLtoString_DE / V03.00.00
LGF_DTLtoString_ISO / V03.00.00
LGF_DTLToUnixTime / V03.00.00
LGF_GpsDDToGps / V03.00.00
LGF_GpsToGpsDD / V03.00.00
LGF_GrayToBinary / V03.00.00
LGF_IntToString / V03.00.00
LGF_ScaleLinear / V03.00.00
LGF_StringToDTL_DE / V03.00.00
LGF_StringToDTL_ISO / V03.00.00
LGF_StringToInt / V03.00.00
LGF_StringToTaddr / V03.00.00
LGF_StringToTime / V03.00.00
LGF_TaddrToString / V03.00.00
LGF_TimeToString / V03.00.00
LGF_UnixTimeToDTL / V03.00.00
LGF_CelsiusToFahrenheit / V03.00.00
LGF_CelsiusToKelvin / V03.00.00
LGF_ConvertTemperature / V16.12.2018
LGF_FahrenheitToCelsius / V03.00.00
LGF_FahrenheitToKelvin / V03.00.00
LGF_KelvinToCelsius / V03.00.00
LGF_KelvinToFahrenheit / V03.00.00
LGF_KelvinToRankine / V03.00.00
LGF_RankineToKelvin / V03.00.00
LGF_CosinusCI / V03.00.00
LGF_Frequency / V03.00.00
LGF_Impulse / V03.00.00
LGF_RectangleCI / V03.00.00
LGF_SawToothCI / V03.00.00
LGF_SinusCI / V03.00.00
LGF_TriangleCI / V03.00.00
LGF_LimRateOfChangeAdvancedCI / V03.00.00
LGF_LimRateOfChangeCI / V03.00.00
LGF_NonLinearInterpolation / V03.00.00
LGF_RampCI / V03.00.00
LGF_AverageAndDeviation / V03.00.00
LGF_Boxplot_DInt / V03.00.00
LGF_Boxplot_LReal / V03.00.00
LGF_Boxplot_UDInt / V03.00.00
LGF_DifferenceQuotientFB / V03.00.00
LGF_DifferenceQuotientFC / V03.00.00
LGF_FloatingAverage / V03.00.01
LGF_Histogram_DInt / V03.00.00
LGF_Histogram_LReal / V03.00.00
LGF_Histogram_UDInt / V03.00.00
LGF_RegressionLine / V03.00.00
LGF_SimpleSmoothingFB / V03.00.00
LGF_SimpleSmoothingFC / V03.00.00
LGF_SmoothByPolynomFB / V03.00.00
LGF_SmoothByPolynomFC / V03.00.00
LGF_SawTooth / V01.00.10
LGF_BitCount / V03.00.00
LGF_MergeBitsToByte / V03.00.01
LGF_MergeBitsToDWord / V03.00.00
LGF_MergeBitsToWord / V03.00.00
LGF_MergeBytesToDWord / V03.00.00
LGF_MergeBytesToWord / V03.00.00
LGF_MergeWordsToDWord / V03.00.00
LGF_SplitByteToBits / V03.00.00
LGF_SplitDWordToBits / V03.00.00
LGF_SplitDWordToBytes / V03.00.00
LGF_SplitDWordToWords / V03.00.00
LGF_SplitWordToBits / V03.00.00
LGF_SplitWordToBytes / V03.00.00