Skip to content

Functions, Function Blocks, and Reading Checklist

Functions And Function Blocks

Use an FC when the logic has no memory of its own. Typical examples are calculations and value conversions.

FUNCTION "FC_ClampReal" : Real
VAR_INPUT
    reValue : Real;
    reMinimum : Real;
    reMaximum : Real;
END_VAR

BEGIN
    IF reValue < reMinimum THEN
        "FC_ClampReal" := reMinimum;
    ELSIF reValue > reMaximum THEN
        "FC_ClampReal" := reMaximum;
    ELSE
        "FC_ClampReal" := reValue;
    END_IF;
END_FUNCTION

Use an FB when the logic needs memory: timers, filters, latches, previous values, counters, or state machines.

Practical Reading Pattern

When you open an unfamiliar SCL block, scan it in this order:

  1. Read the block name and description header.
  2. Read VAR_INPUT and VAR_OUTPUT to understand the contract.
  3. Look for static VAR state: timers, latches, counters, state values.
  4. Read the REGION names.
  5. Find output assignments and state transitions.
  6. Check reset and fallback paths.

This is usually faster than reading top to bottom from the first line.

Beginner Checklist

Before committing a new or changed SCL block:

  • Every Boolean marker has an obvious reset strategy.
  • Timers are declared once, called once, and their .Q result is stored if used in several places.
  • REAL values use tolerances instead of exact zero comparisons.
  • Arrays and loop results are initialized before the loop.
  • State-machine transitions are explicit and include a fallback state.
  • Outputs have deterministic assignments in every relevant mode.
  • Names follow the PCS coding style and include units where units matter.

Next Topics

This guide covers the basics. The next handbook page should collect real project lessons learned: timer call order, reset priority, alarm latching, startup behavior, HMI command handshakes, simulation hooks, and review checklists for common PLC programming mistakes.