Parameterizing LGF_FIFO in TIA Portal for S7-1200/S7-1500

David Krause18 min read
SiemensTIA PortalTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Parameterizing the Siemens LGF_FIFO Function Block in TIA Portal for S7-1200/S7-1500

The Library of General Functions (LGF) for STEP 7 (TIA Portal) and S7-1200/S7-1500 provides a curated set of type-licensed function blocks that implement common automation primitives. Among them, the LGF_FIFO family delivers a complete first-in / first-out buffer without requiring the engineer to manually maintain head/tail pointers, ring indices, overflow/underflow checks, or shift logic. The full LGF reference, with the FIFO description starting on page 46, is published by Siemens as support entry 109479728.

This article covers the end-to-end parameterization of LGF_FIFO: library installation, selection of the correct typed variant, interface pinning, mode selection, status/error handling, sample SCL call, and verification with PLCSIM. A typical application - a queue of floor requests in a multi-floor elevator - is used as the recurring example because it is the canonical reason engineers reach for a FIFO: the order in which events arrive must drive the order in which they are processed.

Scope notice. The LGF is provided free of charge by Siemens as a support utility, but the function blocks are delivered as type-licensed FBs that drop into a project as library master copies. Verify against the current LGF revision (see the "Version history" section of support entry 109479728) before commissioning; status codes and mode constants below are aligned to the LGF release that documents LGF_FIFO on page 46 onward.

1. Overview of the LGF_FIFO Family

A FIFO buffer is a queue that releases elements in the same order they were inserted. In STEP 7 (TIA Portal) the LGF implements it as a function block that owns a typed ARRAY in its Static section, exposes mode, execute, and entry inputs on the block interface, and returns a count plus status on the output side. Because the storage is part of the FB instance, calling the FB with two different instance DBs creates two independent queues that share no data - this is the standard mechanism for parallel buffers in S7-1200/S7-1500 user programs.

The LGF offers one FIFO block per elementary data type, plus a generic AnyDB variant. The full list visible in the LGF master copy library is shown below.

Table 1 - LGF_FIFO block variants shipped with the LGF
FB name Stored element type Typical use
LGF_FIFO_Bool BOOL Bit-level event queues (e.g. latched alarms)
LGF_FIFO_Byte BYTE Compact status bytes, ASCII fragments
LGF_FIFO_Word WORD 16-bit flags, packed bitfields
LGF_FIFO_DWord DWORD 32-bit event tags, timestamps
LGF_FIFO_Int INT Signed 16-bit counters, index sets
LGF_FIFO_DInt DINT Signed 32-bit values, IEC timers in ms
LGF_FIFO_Real REAL Process values, scaled measurements
LGF_FIFO_String STRING Diagnostic text, message queues
LGF_FIFO_AnyDB VARIANT UDT / STRUCT payloads, arbitrary data

Use the typed variants whenever the queued payload is a single elementary type. Reach for LGF_FIFO_AnyDB only when the payload is a STRUCT, UDT, or has a non-uniform length - AnyDB requires a DB handle, an offset, and a length, which adds parameterization complexity.

2. Prerequisites

Before parameterizing the block, confirm that the engineering environment satisfies the requirements below. Mismatched firmware / TIA Portal versions are the most common cause of type-version conflict compiler errors when pulling in a library master copy.

Table 2 - Engineering and runtime prerequisites
Item Required Notes
STEP 7 (TIA Portal) V15.1 or later (LGF version dependent) Verify the LGF release notes on entry 109479728
S7-1200 CPU Firmware V4.2 or later recommended S7-1200 V4.0/V4.1 accepts LGF but lacks some SCL features
S7-1500 CPU Firmware V1.8 or later recommended Newer firmware adds optimized block support
LGF library Latest published .al1x from Siemens Downloaded from entry 109479728
Programmer knowledge Familiarity with FB/DB, instance concept, SCL or LAD/FBD Multi-instance DB handling covered in TIA Portal help
Test bench PLCSIM V15.1+ (or PLCSIM Advanced) for offline validation Optional but recommended before live download
Block protection. The LGF master copies are know-how protected but ship with explicit interface declarations. Parameterization only requires the public interface - never edit the master copy body. Always drag the master copy into the project tree and let TIA Portal generate the instance DB.

3. Installing the LGF Library

  1. Open the project in TIA Portal and switch to the Libraries task card on the right side of the project view.
  2. Click Open global library and browse to the downloaded .al1x file (LGF for STEP 7 TIA Portal Vxx).
  3. Once the library opens, expand Types > LGF (Library of General Functions) > FIFO & LIFO to expose all LGF_FIFO_* and LGF_LIFO_* master copies.
  4. Select the variant that matches the desired payload type. For a queue of integer floor numbers (elevator example), use LGF_FIFO_Int. Drag and drop it into the Program blocks folder of the S7-1200/S7-1500 CPU in your project tree.
  5. Confirm the dialog Insert FB / Instance. TIA Portal prompts to create the instance DB automatically; accept with the default name (e.g. LGF_FIFO_Int_DB) or rename per naming convention.
  6. Compile the program blocks (Hardware > Compile > Software). The master copy is referenced symbolically through the instance DB.

After installation, the project tree will contain:

  • Program blocks > LGF_FIFO_Int [FBxxxx] - the master copy, type-licensed.
  • Program blocks > LGF_FIFO_Int_DB [DBxxxx] - the instance DB, holds the actual ARRAY storage and any FB-static tags.

4. FB LGF_FIFO Interface Architecture

Every typed variant follows the same interface layout. The differences are limited to the data type of the entry input and the buffer static. The table below summarizes the public interface of the typed variants (e.g. LGF_FIFO_Int); verify exact names against the LGF documentation page referenced at the top of this article.

Table 3 - LGF_FIFO public interface (typed variants)
Section Name Type Direction Function
Input execute BOOL in Edge-triggered execution of one operation
Input mode INT in Operation selector (insert / remove / read / reset)
Input entry Matches variant type (e.g. INT) in Element to insert, or unused for remove/reset
Output done BOOL out One-shot TRUE on completed operation
Output error BOOL out TRUE if status indicates an error
Output status WORD out Detailed status / error code (see Section 9)
Output count DINT out Number of elements currently stored
Static buffer ARRAY[0..n] of element type internal Queue storage (size configured at parameterization)
Static headIndex / tailIndex (named per LGF revision) DINT internal Ring-bookkeeping indices (read-only externally)
Optimized block access. S7-1500 CPUs allow Optimized block access (the default for new DBs). When the LGF instance DB is set optimized, the buffer static is symbolic-only and must not be addressed absolutely. Switching between optimized and standard access after parameterization forces the FB to be recompiled and can reset count; do it before commissioning.

5. Selecting and Resizing the Buffer

The buffer size is governed by the array bound declared in the FB's Static section. The LGF master copy ships with a default of ARRAY[0..100] for the typed variants, which equals 101 elements. The exact default is visible in the project tree when the FB is expanded.

To resize the buffer:

  1. Open the instance DB (e.g. LGF_FIFO_Int_DB). With Optimized block access enabled, switch to the data view to see the symbolic buffer.
  2. Open the master copy FB (right-click the FB > Open), navigate to the Static section, and locate the buffer array declaration. Change the upper bound (for example from 100 to 49 for a 50-element queue).
  3. Save and recompile. The instance DB inherits the new array bound on the next Compile.
  4. Verify the change in the instance DB: the symbol should now show the new dimension, and the DB's overall byte size must grow/shrink accordingly.

For an elevator with eight floors plus basement, a 50-element buffer is ample for a typical cabin request queue; a 16-element buffer is sufficient for single-elevator control. The LGF itself does not enforce a hard upper limit, but instance DB size is bounded by the CPU's work memory. The S7-1500 manual confirms work memory limits per CPU; consult the relevant Siemens product support entry for your specific CPU order number before sizing the buffer to thousands of elements.

6. Operating Modes (mode parameter)

The mode input selects the operation. The LGF documents a numeric set of mode constants. Always pass the symbolic name where possible (e.g. LGF_FIFO_MODE_INSERT) rather than raw integers, because the underlying numeric value can change between LGF revisions. The table below lists the canonical modes as documented for the typed FIFO blocks.

Table 4 - LGF_FIFO mode constants (verify against current LGF)
Symbolic constant Effect on buffer Notes
LGF_FIFO_MODE_INSERT Append entry to the tail of the queue Errors with buffer-full status if maximum reached
LGF_FIFO_MODE_REMOVE Pop the oldest element from the head; returns it in entry Errors with buffer-empty status if queue is empty
LGF_FIFO_MODE_PEEK / LGF_FIFO_MODE_READ Read the head element without removing it Useful for arbitration logic before committing a remove
LGF_FIFO_MODE_RESET Empty the buffer; count := 0; head := tail := 0 No entry value required

Some LGF revisions also expose MODE_INSERT_MULTI and MODE_REMOVE_MULTI for batched operations, accepting a count on a separate input. Where these are not present, batching is implemented by repeatedly calling the FB in a loop from the caller's SCL code.

7. Status and Error Codes

The status output carries a 16-bit code. Success is reported as 16#0000 and done = TRUE. The error output is the binary OR of any non-success condition. Standard error categories documented in the LGF include:

Table 5 - Representative LGF_FIFO status codes (verify exact values in support entry 109479728)
Status Meaning Recommended reaction
16#0000 Operation completed without error Proceed
16#8001 (buffer full) Insert rejected because buffer is at capacity Skip insert or trigger upstream backpressure
16#8002 (buffer empty) Remove/Peek requested on empty queue Suppress request; do not raise an alarm unless persistent
16#8401 (invalid mode) mode input outside defined range Clamp mode to one of the supported constants
16#8600 range (parameterization) Buffer dimension or element size inconsistent with the call Re-verify Static declarations after a copy/paste of the FB
Always read status on the same scan that done goes TRUE. The block is edge-triggered; once execute is reset by the caller, status may be cleared or held depending on LGF revision. Latch a copy into a dedicated DWORD tag in the caller's data block if a persistent error log is required.

8. Step-by-Step Parameterization Procedure

The following procedure produces a working LGF_FIFO_Int instance, inserts a tag, retrieves it, and verifies the result with a watch table. It assumes an S7-1500 CPU but applies identically to S7-1200.

8.1 Declare the project-side data

  1. Create a global DB Data_FIFO with optimized block access. Add the following tags:
    • iqFloorRequest   INT   - in-tag: floor number requested from the cabin panel.
    • qServicedFloor   INT   - out-tag: floor number to be serviced next.
    • iEnableInsert   BOOL   - rising edge triggers an insert.
    • iEnableRemove   BOOL   - rising edge triggers a remove.
    • qFifoDone   BOOL
    • qFifoError   BOOL
    • qwFifoStatus   WORD
    • qdFifoCount   DINT
  2. Compile Data_FIFO.

8.2 Place the FB and wire the instance

  1. Drag LGF_FIFO_Int from the LGF global library into Program blocks. Accept the prompt to create LGF_FIFO_Int_DB as the instance DB.
  2. Open OB1 (or the cyclic OB where elevator logic runs) and drop a new instance call. TIA Portal will show the FB interface; the field boxes accept symbolic tags or absolute addresses.
  3. Wire the inputs/outputs as shown in the call mapping below.
Table 6 - Call wiring (LGF_FIFO_Int)
Interface pin Connect to
execute (insert path) Data_FIFO.iEnableInsert
mode (insert path) LGF_FIFO_MODE_INSERT from the LGF constant table
entry (insert path) Data_FIFO.iqFloorRequest
execute (remove path) Data_FIFO.iEnableRemove
mode (remove path) LGF_FIFO_MODE_REMOVE
entry (remove path) Data_FIFO.qServicedFloor
done Data_FIFO.qFifoDone
error Data_FIFO.qFifoError
status Data_FIFO.qwFifoStatus
count Data_FIFO.qdFifoCount

Two separate calls in the same OB are acceptable because the LGF uses execute as an edge; they will not collide if iEnableInsert and iEnableRemove are mutually exclusive. If simultaneous insert and remove is required, the caller must arbitrate using count and the empty/full boundary checks described in Section 7.

8.3 SCL implementation snippet

The following SCL block shows a clean parameterized call from inside an FB or OB. It demonstrates a single call with the mode selected at runtime, which is a common pattern when the caller wants to economize on multi-instance data.

// SCL example - single parameterized FIFO call
#iTempMode := LGF_FIFO_MODE_REMOVE; // or LGF_FIFO_MODE_INSERT

LGF_FIFO_Int_DB(
    execute := #bExecute,
    mode    := #iTempMode,
    entry   := #iPayload,
    done    => #bDone,
    error   => #bError,
    status  => #wStatus,
    count   => #diCount);

IF #bError THEN
    // Persistent log; do not just clear
    "HmiLog".FifoLastStatus := #wStatus;
END_IF;

When the LGF is used inside a multi-instance parent FB, drop LGF_FIFO_Int_DB as a multi-instance under the parent's Static section. TIA Portal will create a STAT instance of type LGF_FIFO_Int that shares the parent's instance DB - this is the recommended pattern for libraries of queues (one queue per axis, per channel, per machine module).

8.4 LAD / FBD implementation

For ladder logic, place the FB call box, then click the small Instance DB drop-down to choose LGF_FIFO_Int_DB. Tag the inputs and outputs as in the table. The mode input can be wired to a constant or to an INT tag controlled by a selector contact network (e.g. MOVE box loaded with the symbolic constant when a particular path is active).

9. Verification with PLCSIM

PLCSIM (V15.1 or later, matching the TIA Portal version) lets the engineer exercise the FIFO offline before downloading to a real CPU. The verification sequence below is sufficient to catch the most common parameterization mistakes (wrong mode, array bound out of range, instance DB not generated).

  1. Start PLCSIM and load the project. Run the simulation to RUN.
  2. Open Data_FIFO in the watch table and force iEnableInsert := FALSE, iEnableRemove := FALSE, iqFloorRequest := 3.
  3. Set iEnableInsert := TRUE for one scan. Confirm qFifoDone = TRUE, qFifoError = FALSE, qwFifoStatus = 16#0000, qdFifoCount = 1.
  4. Insert two more values (e.g. 5, 2) the same way. Confirm qdFifoCount = 3 after each insert.
  5. Set iEnableInsert := FALSE; set iEnableRemove := TRUE for one scan. Confirm qServicedFloor = 3 (oldest first) and qdFifoCount = 2.
  6. Repeat remove until empty; on the next remove with empty queue, confirm qFifoError = TRUE and qwFifoStatus matches the empty-buffer code from Section 7.
  7. Force insert past the array bound (repeat the previous test more times than the buffer size). Confirm buffer-full status code is reported and qdFifoCount caps at the configured size.
  8. Set iEnableRemove := FALSE, mode to LGF_FIFO_MODE_RESET, drive execute once. Confirm qdFifoCount = 0 and no error.

If any step fails, jump to Section 11 to identify the parameterization mistake.

10. Performance and Resource Considerations

The LGF FIFO is implemented in SCL. Insert and remove are O(1) operations: a single head/tail index update plus one assignment. The execution time is dominated by the array bound check the FB performs internally. On a representative S7-1500 CPU (CPU 1515-2 PN, firmware V2.9) the typical call-time for a 100-element LGF_FIFO_Int is in the low microsecond range; on S7-1200 (CPU 1215C, firmware V4.4) it is in the tens of microseconds. The exact value depends on the firmware revision and the number of user programs competing for OB1 time - measure it with the Runtime measurement in the TIA Portal online view if deterministic cycle time is required.

Memory cost is dominated by the array. A LGF_FIFO_Real with 1,000 elements consumes approximately 4 KB of instance DB memory; the same for LGF_FIFO_String with STRING[254] consumes roughly 256 KB. Plan the work-memory budget accordingly and consider LGF_FIFO_AnyDB for very large or variable-length payloads - the AnyDB variant stores elements contiguously in a caller-supplied DB and can be sized without recompiling the FB.

11. Common Parameterization Errors and Edge Cases

Table 7 - Troubleshooting matrix for LGF_FIFO parameterization
Symptom Likely root cause Remedy
Compiler: "Type version of FB LGF_FIFO_Int is not compatible" LGF master copy newer than the version supported by the CPU firmware Update CPU firmware or downgrade the LGF revision per release notes
Instance DB always empty after insert Caller resets execute too fast, before the FB has sampled the edge Hold execute TRUE until done or error is observed; reset on the next scan
Status reads buffer-full on first insert Array bound was declared as ARRAY[0..0] (single element) Resize the static buffer array in the FB
Status reads invalid-mode mode tag was set to a raw integer that does not match any LGF constant Use the symbolic constants from the LGF constant table
Sequence behaves like LIFO Caller mixes up INS (tail) and REM (head) - check that you are not removing the just-inserted element Insert then inspect buffer[0..count-1] in the data view to confirm order
Watch table shows scrambled values Optimized DB and absolute address used together - mismatch of symbolic vs. absolute offset Use only symbolic access for optimized blocks
Output entry never updates on remove Caller writes the entry tag on every scan, overwriting the FB's output before the next read Copy entry into a latched INT on the scan done becomes TRUE

12. Special Topic: LGF_FIFO_AnyDB

For STRUCT or UDT payloads - for example, a queue of "typeFloorRequest" with fields floor : INT, priority : INT, timestamp : DINT - the typed variants are insufficient. LGF_FIFO_AnyDB stores elements of arbitrary type in a caller-provided DB. The parameterization differs:

  • handle   DWORD   - the DB handle returned by DB_ANY_TO_VARIANT or by the SCL DB reference operator.
  • offset   DINT   - byte offset of the storage region within the target DB.
  • length   DINT   - number of elements in the region.
  • elementSize   DINT   - size of one element in bytes (SCL SIZEOF).
  • entry   VARIANT   - typed view onto the element being inserted or retrieved.

When the target DB is optimized, the offset and size must still be expressed in bytes from the start of the DB's data view. Symbolic offsets cannot be passed directly to the FB; the caller computes them in the OB1 cyclic code using SIZEOF and a base-offset constant. Misalignment between elementSize and the actual UDT size is the single largest source of AnyDB parameterization bugs - always log both to the HMI for the first 100 cycles of commissioning.

13. Integration Patterns

13.1 Multi-instance for repeating equipment

When one PLC controls multiple elevators, conveyors, or machines, declare a parent FB typeElevatorControl with a static instance of LGF_FIFO_Int. Each instance DB of typeElevatorControl then carries its own private queue. Memory overhead per instance is small (the array bound dominates), and the call site becomes a single multi-instance call instead of N global DBs.

13.2 HMI mirroring

Mirror count and status to the HMI for diagnostics. Do not mirror the entire buffer array to the HMI on a polling tag list - the cyclic load will degrade OB1 performance. Use a recipe-style HMI read on demand, or expose only the head/tail of the queue.

13.3 Restart / cold-start behavior

Instance DBs with optimized block access have a configurable retain property. The buffer is normally non-retain because a stale floor request is unsafe after a CPU restart; clear the Set in IDB retain bit on the buffer static and on the index tags. After a power-on, the FB will report an empty queue and the elevator will wait for new requests - which is the desired behavior.

13.4 Safety / F-CPU considerations

The LGF itself is not F-certified. In a safety-related elevator application, the FIFO may be used for standard floor request arbitration, while the safety chain (door lock, overspeed, level stop) runs in the F-runtime and is implemented with F-typed blocks. Do not pass a non-safety FIFO output to a safety tag without an F-capable input filter.

14. Field-Proven Checklist

Before signing off a parameterized LGF_FIFO application, confirm each item below. The checklist is intentionally short - each line represents a category of failure observed in field commissioning.

  • Master copy version recorded in the project change log.
  • Instance DB Optimized block access setting matches the rest of the program.
  • buffer upper bound verified to match the application requirement.
  • mode input wired to symbolic constants, not raw integers.
  • Caller latches done, error, and status on the same scan and resets execute only after observing them.
  • Buffer-full and buffer-empty conditions are handled in the calling OB - the application does not silently ignore them.
  • Watch-table dry run executed in PLCSIM, with the worst-case sequence (insert beyond capacity, remove from empty).
  • Retain attributes on buffer and on the index tags are cleared for non-retain semantics.
  • HMI diagnostic shows count and status on a dedicated diagnostics screen.
  • Fallback behavior on power-on is documented in the operating manual (empty queue, no movement until new request).

15. Summary

The LGF LGF_FIFO blocks remove a large amount of boilerplate from PLC programs that need queued data. By selecting the typed variant that matches the payload, wiring the public interface to symbolic project tags, and verifying the edge-triggered behavior in PLCSIM, the engineer gains a queue that is documented, type-licensed, and supported through the Siemens support channel. For STRUCT/UDT payloads, the LGF_FIFO_AnyDB variant covers the same use case at the cost of additional parameterization around the DB handle, offset, length, and element size. The official reference for the family is Siemens support entry 109479728 and should be consulted for the exact status code values, mode constants, and library revision notes of the LGF currently deployed in your engineering environment.

FAQ

Which LGF_FIFO variant should I use for a queue of 16-bit integers?

Use LGF_FIFO_Int for plain INT payloads and LGF_FIFO_DInt for DINT. Reserve LGF_FIFO_AnyDB for STRUCT/UDT data; for plain integers it adds unnecessary handle/offset/element-size parameterization.

How do I insert more than one element at a time?

Call the FB once per element inside a FOR loop in SCL, toggling execute each iteration. Some LGF revisions expose MODE_INSERT_MULTI with a count input; check the constant table in your installed library before writing the loop manually.

Why does status show 16#8002 even though I just inserted an element?

16#8002 is the empty-buffer code; the symptom usually means the remove call is firing immediately after the insert in the same OB1 cycle, before the insert's count has propagated. Add a one-shot edge detector on the remove enable, or use a state machine that arbitrates insert vs. remove.

Can I use LGF_FIFO in a multi-instance under a parent FB?

Yes. Declare the LGF_FIFO master copy as a STAT instance under the parent FB's static section. TIA Portal will create a per-instance multi-instance DB. This is the recommended pattern when one PLC controls several independent queues (elevators, channels, machines).

What happens to the FIFO contents after a CPU restart?

By default the instance DB is non-retain: the buffer is cleared, head/tail indices return to zero, and count reads zero. If the application requires retention (unusual for floor requests, common for diagnostic logs), set the retain attribute on the buffer and index tags in the instance DB and verify with a power-cycle test in PLCSIM.

Back to blog