Importing and Using LGF or Other External Libraries

In addition to creating your own custom function blocks and libraries, TIA Portal also allows you to import and use external libraries—collections of pre-built logic blocks, data types, and utility functions that help simplify complex control tasks.

One of the most commonly used libraries is the LGF (Library for General Functions), which includes ready-to use blocks for mathematical operations, interpolation, signal processing, ramping, and more. Using such libraries can greatly accelerate development, improve code quality, and ensure consistency across projects.

What is the LGF Library?

The LGF (Library for General Functions) is a Siemens-provided library designed to support common
automation needs with pre-validated and tested function blocks.

Some commonly used blocks from the LGF library include:

Function BlockDescription
LGF_NonLinearInterpolationPerforms multi-point interpolation based on a custom curve
LGF_RampImplements a smooth ramp-up/down transition
LGF_DeadBandAdds a deadband to avoid small signal fluctuations
LGF_FilterApplies a digital low-pass filter to noisy signals

These blocks are particularly useful in analog processing, motion control, and custom logic scaling.

How to Import an External Library in TIA Portal

Step-by-Step Guide:

  • Download the Library
    • Ensure you have the .al11 library file (e.g., LGF_Vx.y.al11). Siemens libraries can usually be downloaded from the Siemens Support Portal.
  • Open Global Libraries Panel
    • In TIA Portal:
    • Project View → Libraries → Global Libraries → Open Library
  • Navigate and Select the Library File
    • Browse to the location of the .al11 file and click Open.
  • Browse Library Contents
    • Once opened, you will see categories such as:
      • Types
      • Blocks
      • Tag Tables
  • Insert into Your Project
    • Right-click the desired FB/UDT → “Copy to Project Library” or directly to Program blocks.
    • The block is now available for use just like any other project block.

Using a Block from LGF in Your Logic

Let’s take an example with the LGF_NonLinearInterpolation block:

  • Add the Block to Your Project
    • Copy it from the global library to your project.
  • Declare an Instance in Your Code
    • In a Function Block or OB, declare an instance:
    • lgfInterp : LGF_NonLinearInterpolation
  • Configure Parameters
    • Input X value (e.g. from a sensor)
    • Array of X breakpoints and Y values (curve definition)
    • Output Y value
  • Use UDT or Constants for Curve Data
    • It’s common practice to store curve points in a Struct or constant DB to keep the logic clean and maintainable.

  • Avoid modifying the contents of a third-party library directly; instead, copy blocks into your project before customizing.
  • Keep all imported libraries under version control and store them in a shared location accessible to your team
  • Document usage of external blocks in your project, especially for critical logic (e.g., scaling, safety calculations).

Summury

External libraries like LGF provide a powerful set of tools that can significantly simplify your control logic. By understanding how to properly import and use them, you can:

  • Reduce development time
  • Increase reliability
  • Promote standardization
  • Reuse validated logic across multiple projects

Practical Example: Using LGF_NonLinearInterpolation for Sensor Scaling

To demonstrate how to integrate external library blocks into a structured and reusable logic system, we present a practical example using the LGF_NonLinearInterpolation block from the LGF library.

This example performs non-linear scaling on multiple sensors by applying unique interpolation curves per sensor, defined via structured data. The logic is encapsulated in a reusable function block that can handle a dynamic number of sensors

Defining the sensor Data Type

We begin by creating a user-defined data type (sensor) with the following structure:

Each sensor contains:

  • A raw input value (e.g., from an analog channel),
  • A scaled output value (LREAL),
  • A set of 5 interpolation points (setpoints) used for custom curve mapping.

New data Type named sensor

Creating an Array of Sensors in a Data Block

A global data block is created to hold multiple sensor instances:

Create sensors on global DB

Each sensor in the array has its own configuration and feedback data.

Creating a Reusable Scaling Function Block

A function block is created to process all sensors dynamically using a FOR loop. The block interface includes:

  • The input sensor array is declared with open indexing ([*]), allowing flexibility in the number of sensors.
  • Up to 10 LGF block instances are statically declared to handle a maximum of 10 sensors.

Create a new FB and its variables

Implementation Logic

Inside the function block, a FOR loop is used to iterate over the full range of the sensor array. Each sensor’s raw input is passed to an instance of the LGF block, and the scaled output is written back to the same sensor structure.

Use of LGF non Linear interpolation function – Modify Values on setpoints (inputs & Outputs), modify “value” and check outputValue

  • The use of LOWER_BOUND and UPPER_BOUND makes the logic dynamic, supporting sensor arrays of varying lengths.
  • Each LGF block handles one sensor, mapping its raw value to a scaled value using the unique curve defined in setpoints.

Call the function on OB and set as input the sensors of global DB

Summary of Benefits

This approach demonstrates the combined use of:

  • Structured data (UDTs) for sensor configuration and feedback
  • External library blocks for complex operations like non-linear interpolation
  • FOR loop with open array bounds for scalable logic
  • IN_OUT parameters to directly operate on the project’s data block

This design is modular, scalable, and reusable, and it reflects best practices for working with real-world sensor arrays in industrial automation.

Tip: Apply the Same Pattern with Your Own Custom Blocks

The structure demonstrated in this example—using structured data (UDTs), arrays, and function blocks with dynamic loops—is not limited to library blocks like LGF_NonLinearInterpolation.

You can apply the same modular approach to your own custom-built FBs, encapsulating logic such as:

  • Motor or actuator control
  • Alarm management
  • Analog signal conditioning
  • Diagnostics or status monitoring
  • PID or setpoint handling

By designing your FBs with IN_OUT parameters using UDTs, and processing arrays through indexed loops, you can:

  • Increase code reuse across multiple machines or projects
  • Make logic easier to maintain and troubleshoot.
  • Reduce programming errors due to copy/paste or inconsistent logic

These custom blocks can also be saved in Global Libraries, versioned, and shared across your engineering team—just like LGF or any external library.


If you found this helpful, please consider supporting with a small donation. Thank you!

Posted in

One response to “TIA Portal Tutorial: Using LGFs and External Libraries”

Leave a Reply

Discover more from PLC Steps - Your Guide to Industrial Automation

Subscribe now to keep reading and get access to the full archive.

Continue reading