• PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    In Part 1, we focused on the PLC side and the logic required to control an ON/OFF signal.
    In this second part, we will focus on the SCADA level, specifically on how to create and configure ON/OFF buttons in WinCC 7.5 using the Graphics Designer.

    1. Preparing the WinCC Screen

    1. Open your project in WinCC Explorer.
    2. Go to Graphics Designer and open the required screen with a double click (in this example, mainScreen.pdl).
    3. Select the background of the screen, go to Properties, and double-click on Background Color. Choose the desired background color (in this example, black).
    4. If the background color does not change:
      • Go to Properties → Effect
      • Set Global Color Scheme to No
    5. From the Elements panel on the right side, drag and drop a Button onto the screen.

    WinCC Explorer – Graphics Designer – mainScreen.pdl

    background of the screen

    Button’s Properties

    2. Adding Dynamic Behavior to the Button

    1. Select the ButtonPropertiesEffects Set Global Color Scheme to No.
    2. Still in Properties, set:
      • Background Color: Blue
      • Font Color: White
    3. Right-click on the lamp icon next to Background Color and select “Dynamic Dialog…”.
    4. In the Dynamic Dialog:
      • Enter the Tag Name inside single quotes ('TagName')
      • Select the variable type (Boolean in this example)
    5. Define the dynamic colors:
      • Yes (1) → Green
      • No (0) → Blue
    6. Go to Trigger:
      • Event → Event Tag
      • Enter the same Tag Name
      • Select Standard Cycle 500 ms
    7. This configuration allows the button color to change dynamically based on the PLC tag value.

    Global Color Scheme Disabled

    Button on main screen

    Dynamization of Properties

    Dynamic Dialog

    Trigger Menu – Trigger Tag

    3. Defining the Button Action (ON Button)

    1. Select the Button and go to the Events category.
    2. Choose
      • Mouse → Press Left
      • Right-click and select Direct Connection
    3. Set:
      • Constant1
      • Tag"on" This means that when the button is pressed, the PLC tag on is set to logic 1.

    Button’s Events Tab

    Direct Connection Menu

    4. Creating the OFF Button

    1. Copy / Paste the ON button.
    2. Repeat exactly the same steps as above.
    3. The only difference:
      • Use the Tag "off"
      • Set the Constant accordingly (typically 1 for the OFF command, depending on PLC logic).

    Copy and paste Button On and create Button Off

    5. Testing in Runtime

    1. Save the screen.
    2. From WinCC Explorer, start the Runtime.
    3. Press the ON and OFF buttons.
    4. Verify that:
      • The PLC tags change correctly
      • The button colors update dynamically
      • The system behaves as expected

    Start Runtime

    Testing Buttons Function

    Conclusion

    With these steps, we successfully created dynamic ON/OFF control buttons in WinCC 7.5, connected them to PLC tags, and verified their behavior in Runtime.

    This approach provides a clear and user-friendly way to control PLC signals directly from the SCADA system.


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

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    In industrial automation, human-machine interfaces (HMIs) like WinCC are essential for controlling and monitoring PLCs efficiently. One common requirement is the ability to toggle outputs using simple ON and OFF buttons. In this tutorial, we will guide you through creating two mutually exclusive buttons in WinCC 7.5: pressing the ON button will activate a signal and automatically deactivate the OFF button, and vice versa. This approach ensures clear, intuitive control and reduces the risk of errors in operation.

    Logic Overview for ON/OFF Buttons in WinCC 7.5
    1. SCADA Side (WinCC 7.5)

    • The HMI will have two buttons: ON and OFF.
    • Each button sets its corresponding variable in the PLC when pressed.
    • The button color changes based on the variable feedback, giving a visual confirmation of the current state.

    2. PLC Side (TIA Portal)

    Since the control comes from the SCADA, the PLC only handles the mutual reset of the opposite button:

    • When the ON button is pressed (RTrig detected for ON), the PLC resets OFF → False.
    • When the OFF button is pressed (RTrig detected for OFF), the PLC resets ON → False.

    This ensures that only one button is active at a time, preventing conflicting commands while keeping the SCADA interface intuitive.

    PLC Side Implementation (TIA Portal) – DemoButton FB

    1. Global DB Variables

    Add two variables on a Global DB

    • on – Bool
    • off – Bool

    These variables will receive signals from SCADA (WinCC) when the buttons are pressed.

    2. Create a new Function Block (FB)

    • Create a new FB, e.g., demoButton.
    • Add a static array for the R_TRIGs

    3. Call R_TRIG in SCL

    • For each element of the array, assign the corresponding variable to the CLK input:

    4. Logic to reset the opposite button

    With this setup:

    • Pressing the ON button automatically sets OFF to FALSE.
      Pressing the OFF button automatically sets ON to FALSE.
    • The R_TRIG ensures that the change occurs only when the button is pressed, not continuously.

    5. Call demoButton Function Block in Main


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

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    Note: To follow along with this example, you will need to run a PLC simulation and establish communication with WinCC 7.5. For a detailed step-by-step guide on setting up a PLC simulation in TIA Portal V16 and connecting it to WinCC, refer to our dedicated tutorial:

    This tutorial covers everything from creating the PLC project and defining variables to configuring the communication between the PLC and WinCC, ensuring you can test your HMI tags in a fully simulated environment.

    In this tutorial, we will guide you step by step on how to create HMI tags in WinCC 7.5 and connect them to your PLC. By the end of this tutorial, you will understand how to define global variables, set up tag properties, and establish the connection between your HMI and PLC.

    Step 1: Create a Global DB in the PLC

    First, we create a Global DB in the PLC project. In the Properties → Attributes section, make sure to deselect “Optimized block access”. This is important because optimized blocks do not allow direct access to individual variables from the HMI.

    Properties → Attributes section, make sure to deselect “Optimized block access

    Inside the Global DB, create two Boolean variables: On and Off. Once created, check that each variable now has a value in the Offset column — this ensures that the PLC assigns a memory location for each variable, which is required for HMI communication.

    Verify that Variables has Offset Value

    Step 2: Open Tag Management in WinCC

    Open your WinCC project and navigate to Tag Management.
    Within the Connection section, create a new group to organize your HMI tags. Grouping tags makes your project cleaner and easier to manage, especially as the number of tags grows.

    Add New Group On Tag Management

    Step 3: Define Each HMI Tag

    For every HMI tag you want to use, define the following:

    1. HMI Tag Name:
      • The name used to reference the tag inside WinCC screens, scripts, and alarms.
    2. Data Type:
      • Choose the appropriate type:
        • Boolean → Binary
        • Integer → Int/UInt (Signed/Unsigned)
        • Real → Floating-point number
    3. Address:
      • This is the PLC memory address associated with the HMI tag. It is crucial to link the tag to the correct PLC variable to ensure proper communication between HMI and PLC.

    Once these steps are completed, your HMI tags are ready and connected to the PLC, allowing you to use them in screens, scripts, alarms, and other WinCC features.

    HMI Tags Definition


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

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    This guide explains how to simulate a PLC project in TIA Portal V16 using PLCSIM, and how to establish communication with WinCC 7.5. The process includes preparing the simulation environment, configuring communication settings, and verifying that the runtime is connected to the simulated CPU.

    To complete the following steps, it is necessary to create a new WinCC project

    Step-by-Step Procedure

    1. Open TIA Portal V16
    Start TIA Portal V16 and create (or open) a project.
    For this initial test, it is sufficient to include only the CPU in your project.

    2. Start the Simulation
    Click the Simulation icon to launch PLCSIM.

    3. Download the Program to PLCSIM
    Once PLCSIM is running, perform a Download to transfer your program to the simulated CPU.

    4. Open the Windows Control Panel
    Go to Control PanelSet PG/PC Interface

    5. Verify the Interface Selection
    Ensure that the selected interface is:
    S7ONLINE → PLCSIM.TCPIP

    6. Open or Create a WinCC 7.5 Project
    Launch WinCC 7.5 and wait for WinCC Explorer to open.

    7. Open Tag Management
    Double-click Tag Management in the project tree.

    8. Edit Connection Parameters
    Right-click the connection you have created and select Connection Parameters.

    9. Set the IP Address
    Enter the IP address of the CPU used in your TIA Portal project.

    10. Select the Access Point
    Set Access Point to: S7ONLINE

    11. Select the Product Family
    Choose S7-1500 connection (for this example).

    12. Open Graphics Designer
    Return to WinCC Explorer and double-click Graphics Designer.
    Your first screen will open—do not edit it yet.

    13. Save the Screen
    Save the screen and name it, for example, mainScreen.

    14. Set the Start Picture
    Close the screen.
    In the Graphics Designer folder, right-click the newly created screen and select Define Picture as Start Picture.

    15. Start Runtime
    From WinCC Explorer, select Start Runtime.

    16. Check the Connection Status
    Go to Tag Management and verify whether the connection shows “connected” or “disconnected.”


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

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    This tutorial explains how to create a new WinCC 7.5 project and configure communication with an S7-1200 or S7-1500 PLC.

    • Open WinCC 7.5
      • Launch WinCC 7.5 from your Siemens Start menu.
    • Create a New Project
      • Once the WinCC Explorer opens, go to File -> New
    • Select Project Type
      • A dialog window will appear. Choose Single User Project, unless you specifically need a Multi User Project or a Client Project.
    • Enter Project Name
      • Type a name for your new project and confirm.
    • Project Interface Opens
      • WinCC Explorer will reload and display the menu structure of the new project.
    • Open Tag Management
      • Double-click Tag Management from the project tree.
    • Add a Driver
      • When Tag Management expands, double-click it again and select:
      • Add New Driver → SIMATIC S7-1200, S7-1500 Channel (Choose a different driver if you are using another PLC type.)
    • Create New Connection
      • A new subfolder named OMS+ will appear.
      • Right-click it and select New Connection.
    • Configure the Connection
      • A new connection object will be created.
      • Right-click the connection and choose Connection Parameter.
    • Set the PLC IP Address
      • Enter the IP address of the PLC CPU you want to connect to.
    • Select the Access Point
      • Choose the correct access point, typically:
        • S7ONLINE (If using MPI or another interface, check the current setting in Set PG/PC Interface.)
    • Select Product Family
      • Choose S7-1500 connection (If you use 1500 series)
    • Check the Access point. Choose S7ONLINE (STEP7).
    • Check Set PG/PC Interface and verify that the Interface assigned is correct.
      • For simulation purpose choose PLCSIM.TCP or Siemens PLCSIM Virtual Ethernet Aapter (TCP/IP single Adapter) or Your Computer’s Network Adapter (if you have physical CPU connected)


    Create a New Project

    Select Project Type

    Enter Project Name

    WinCC Explorer reload and display the menu structure of the new project.

    Open Tag Managerment / Right Click On Tag Management and Add New Drive

    Create New Connection

    Configure the Connection (Connection Paramters)

    Set IP Address (of the CPU), Access Point and Product Family

    Set PG/PC Interface (Siemens Virtual Ethernet Adapter for this example)


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

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    This example demonstrates how to implement a basic, yet robust, PID control loop using the PID_Compact technology object, with full configuration and runtime control via a structured global data block.

    Step 1: Global Data Structure Design

    Create a global DB structure named autoFunction with the following elements:

    Structure

    Step 2: Create a PID_Compact Technology Object

    Inside the project:

    • Go to Technology Objects → Add new → Select PID_Compact.
    • In the Configuration tab:
      • Set Mode to Automatic.
      • Set Process Value Limits:
        • valueUpperDeadband := machine.autoFunction.pidSetpoint + machine.autoFunction.pidConfig.deadband;

    Technology Object: PID

    Invert Control Logic (If Needed)

    IF (machine.autoFunction.actualValue – machine.autoFunction.pidSetpoint) < 0 THEN

        autoFunction_.Config.InvertControl := TRUE;

    ELSE

        autoFunction_.Config.InvertControl := FALSE; END_IF;

    Apply PID Output and Global Gain

    // Store raw output

    machine.autoFunction.pidOut := output;

    // Apply global gain and clamp to -100..100

    output := LIMIT(

        MN := -100.0,

        IN := (autoFunction_.Output * machine.autoFunction.pidConfig.globalGain1) / 100,

        MX := 100.0 );

    Reset PID Output If Within Deadband or Not Enabled

    IF ((machine.autoFunction.actualValue < valueUpperDeadband) AND

        (machine.autoFunction.actualValue > valueLowerDeadband)) OR

        NOT machine.autoFunction.enableAutoFunction THEN

        output := 0.0;

    END_IF;


     Key Benefits of This Approach

    • Fully Dynamic Configuration: No hardcoded tuning values.
    • Deadband Handling: Prevents unnecessary actuator movement.
    • Direction Awareness: Inverted control if setpoint is below process value.
    • Output Scaling: Global gain allows smooth fine-tuning.
    • Safe Fallback: Resets output automatically when PID should not act.

    Basic Configuration 1

    Set Process Value High and Low Limit

    Set Output Value High and Low Limit

    Set PID parameters

    Create a Function block with basic variables

    Initialize basics parameters & call technology into FB

    Basic PID logic

    PID Commissioning -Pretuning

    PID disabled

    PID enabled and locked at 86 due to  r_trig  on enable

    PID enabled and locked at 86. No output due to deadband

    PID enabled and locked at 86. PID reaching setpoint.

    PID enabled and locked at 86. PID reaching setpoint. (Invert Control is True now)


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

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    Introduction

    In many industrial automation systems, maintaining a process variable (such as temperature, pressure, flow, or speed) within a desired range is critical to system stability and performance. This is typically achieved through closed-loop control, most commonly using PID control (Proportional–Integral–Derivative).

    TIA Portal provides a range of function blocks for PID control, with the most modern and flexible being the PID_Compact block, which supports:

    • Continuous (analog) or discrete (digital) control modes
    • Manual and automatic operation
    • Internal or external setpoints
    • Auto-tuning of PID parameters
    • Standard alarm and monitoring functionality
    • Integration with HMI and Engineering Tools for monitoring and diagnostics

    This chapter focuses on the practical use of the PID_Compact block for implementing reliable and maintainable PID logic in Siemens PLCs. You’ll learn how to:

    • Configure the block for your specific application
    • Connect inputs/outputs, setpoints, and enable logic
    • Perform auto-tuning and interpret the results
    • Monitor and fine-tune control performance
    • Avoid common pitfalls such as scaling issues or unstable control behavior

    Whether you are controlling the speed of a pump, the temperature of an oven, or the pressure in a tank, PID_Compact provides a standardized and reusable solution that integrates smoothly with the TIA Portal environment.

    Overview of PID_Compact Function Block

    What is PID_Compact?

    PID_Compact is Siemens’ standard function block for implementing PID control in the TIA Portal environment. It is available in the Standard and Technology libraries for S7-1200 and S7-1500 PLCs.

    This block encapsulates the logic needed for closed-loop PID control, and provides built-in features for:

    • Automatic or manual control
    • Auto-tuning of parameters (Kp, Ki, Kd)
    • Multiple operation modes (continuous or discrete)
    • Error handling and diagnostics
    • Integration with HMI or supervisory systems
    • Runtime monitoring and parameter adjustment

    It is designed to be easy to configure, reusable across projects, and highly adaptable to different types of processes — from simple on/off loops to advanced analog control.

    Key Features

    FeatureDescription
    Auto-tuningCalculates optimal PID parameters based on system response
    Manual/Auto ModeSwitch between manual output and automatic control
    Integrated AlarmsBuilt-in status and error flags for diagnostics
    Ramp & Limiter OptionsOptional ramp-up/down of setpoint and output
    External or Internal SPCan receive setpoint from external signal or internal value
    Multiple Control TypesSupports P, PI, or PID control logic
    Reusable & ModularCan be integrated inside custom FBs or project libraries

    When to Use PID_Compact

    You should consider using PID_Compact if your application requires:

    • Stable control of analog or continuous process variables (e.g. temperature, pressure, level, flow).
    • Simple integration of PID loops into your PLC logic without implementing from scratch
    • On-site or runtime tuning capability (for maintenance or commissioning)
    • Integration with HMI panels to allow operators to change setpoints or monitor loop status

    This block provides a standardized solution for process control that minimizes effort while ensuring maintainability and flexibility in future changes or scaling.

    Block Inputs and Outputs (Simplified View)

    PortTypeDescription
    ENBOOLEnable block execution
    PVREALProcess Value (input measurement)
    SP_INTREALInternal Setpoint (used if SEL_SP = FALSE)
    SP_EXTREALExternal Setpoint (used if SEL_SP = TRUE)
    MANBOOLManual mode active
    MAIN_INREALManual output value
    OUTREALOutput (to actuator)
    CTRL_ENABLEBOOLEnables the control algorithm
    AUTOTUNEBOOLStarts the auto-tuning procedure
    STATUSWORDStatus word (diagnostics)

    Understanding PID Parameters and Tuning Guidelines

    This section provides a detailed explanation of the core parameters used in PID control logic and offers practical tuning guidance to help you configure stable and responsive control loops using the PID_Compact function block in TIA Portal.

    1. Proportional Gain (Kp)

    The proportional gain determines how strongly the controller reacts to the current error — the difference between the desired value (Setpoint) and the actual value (Process Variable).

    • A higher Kp leads to a faster response, but may cause overshooting or oscillation.
    • A lower Kp results in a slower system response and may never fully reach the setpoint.

    Tip: Start with a low value and gradually increase until you observe a slight overshoot, then reduce slightly.

    2. Integral Time (Ti)

    The integral term accumulates past errors over time and helps eliminate steady-state error.

    • A smaller Ti means faster integral action, which can improve accuracy but might cause overshoot or instability.
    • A larger Ti slows down the integral correction, making the system more stable but slower to eliminate errors.

    Use integral only when your system shows a consistent offset after tuning Kp.

    3. Derivative Time (Td)

    The derivative term reacts to the rate of change of the error. It anticipates system behavior and dampens rapid movements.

    • Small or zero Td: Has minimal effect; useful in simple systems.
    • Larger Td: Can stabilize fast-changing systems but is sensitive to noise.

    Avoid using Td in noisy environments (e.g., hydraulic systems).

    4. Sampling Time (Ts)

    Defines how often the PID loop runs. This directly affects control responsiveness and CPU load.

    • Smaller Ts: Faster reaction, but more CPU-intensive and may lead to instability in slow systems.
    • Larger Ts: Slower control but can be more stable and CPU-efficient.

    Choose Ts based on the nature of the system.

    • Fast processes (e.g. liquid level): 100–500 ms
    • Slow processes (e.g. temperature): 1–5 sec

    Deadband

    Defines a range around the setpoint where the PID output is considered zero (no control action). This prevents the system from constantly adjusting for very small errors.

    Useful in systems where minor deviations are acceptable or where actuator wear is a concern.

    Tuning Process – Step-by-Step

    Step 1 – Define the Main Signals

    • Setpoint (SP): Desired value (e.g., 180° heading)
    • Process Variable (PV): Sensor feedback (e.g., gyro value)
    • Control Variable (CV): Output of the PID (e.g., valve/thruster control)

    Step 2 – Understand the Process

    Ask the following:

    QuestionWhy It Matters
    Is the system fast or slow?Affects Ts choice
    Does it have inertia (e.g., temperature)?May require lower Kp, higher Ti
    Is it noise-sensitive?May require Td = 0

    Step 3 – Choose Tuning Method

    Αuto-Tune (Recommended Starting Point)
    PID_Compact supports automatic tuning.

    • It perturbs the output slightly and learns from the system’s response.
    • Suitable for systems like pressure, temperature, flow.

    Manual Tuning
    Start with:

    • Kp = 0.5
    • Ti = 60s
    • Td = 0

    Then:

    Step 4 – Tune Sampling Time (Ts)

    System TypeSiggested Ts
    Fast0.1 – 0.5s
    Slow1 – 5s

    Step 5 – Observe and Adjust

    BehaviorAction
    OscillatesDecrease Kp, increase Ti
    Too SlowIncrease Kp, reduce Ti
    OvershootAdd small Td or reduce Kp
    Constant errorReduce Ti

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

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    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!

  • PLC Steps

    Simplify, Learn, Automate

    Γνῶσις δύναμις ἐστίν

    Libraries in TIA Portal are containers for reusable code components such as:

    • Function Blocks (FBs)
    • Functions (FCs)
    • Data Types (UDTs)
    • Global Data Blocks (DBs)
    • HMI elements (screens, popups, etc.)
    • Tags, tag tables, and user-defined alarms

    They allow you to standardize, share, and reuse these components across different projects or among engineering teams.

    There are two types of libraries in TIA Portal:

    • Project Libraries
      • Stored within the current project.
      • Useful for organizing reusable elements internally in a single project.
      • Cannot be accessed from outside the project.
      • Good for smaller projects where sharing isn’t required.

    Location in TIA Portal: Project View → Libraries → Project Library

    • Global Libraries
      • Stored as standalone .al11 files, outside of any single project.
      • Can be imported and reused in multiple projects.
      • Allow for versioning, backup, and team sharing.
      • Ideal for maintaining company-wide standards or frequently used blocks (e.g., motor control logic, diagnostics modules, etc.)

    Location in TIA Portal: Project View → Libraries → Global Libraries → Open Library

    Why Use Libraries?

    Libraries help in achieving:

    • Reusability – No need to “reinvent the wheel” for every new project.
    • Standardization – Ensures that common logic behaves the same across systems.
    • Maintainability – Updating a block once can propagate improvements to all future uses.
    • Team Collaboration – Common logic can be shared easily across developers.
    • Version Control – Libraries can be versioned to ensure compatibility with specific project versions.

    Practical Use Cases

    • A custom PID control FB saved in a global library can be reused across all projects with identical tuning logic
    • A standardized data structure (UDT) for motor configuration can be saved once and reused in every machine installation
    • Third-party libraries such as LGF (Library for General Functions) provide advanced tools like interpolation or ramp functions that can be integrated directly into your project.

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