Calling APL Blocks with Structured Variables (Integral FB1823) Inside S7-SCL in SIMATIC PCS 7

Calling APL Blocks with Structured Variables (Integral FB1823) Inside S7-SCL in SIMATIC PCS 7

In SIMATIC PCS 7 S7-SCL, calling Advanced Process Library (APL) technological blocks—such as the mathematical integrator block Integral (FB1823)—requires instantiating the block as a multi-instance in the VAR declaration and correctly populating APL structured variables. APL inputs and outputs do not use simple REAL primitives; instead, they utilize structured records containing a value (Value: REAL) and a NAMUR quality code byte (ST: BYTE). Attempting to pass a plain REAL directly into an APL block call results in SCL compiler type mismatch errors. To resolve this, declare an intermediate struct variable or assign Value and ST explicitly before invoking the block.

Table of Contents

APL Technological Block Architecture and Structured Data Types

In the SIMATIC PCS 7 Advanced Process Library (APL):
* Quality Code Integration: In conformance with NAMUR NE 107, every analog and discrete process signal carries both its magnitude and its signal health (Quality Code / Status Byte).
* The APL Struct Pattern:
* Analog input/output: STRUCT Value : REAL; ST : BYTE; END_STRUCT;
* Discrete input/output: STRUCT Value : BOOL; ST : BYTE; END_STRUCT;
* Status Byte Standard:
* 16#80: Good (Normal process value).
* 16#60: Simulated value.
* 16#00: Bad / Passivated (Channel wire break or sensor failure).

The Structure Interface Constraint in S7-SCL

When an engineer writes custom S7-SCL code calling an APL block (such as Integral FB1823):
* Passing a direct real expression: my_integral(In := 25.4); causes the SCL compiler to abort:
Error: Data type mismatch for parameter In.
* The parameter In expects the entire two-component structure. In S7-SCL, structure elements must either be populated via an intermediate variable or written component-by-component into the instance data block prior to execution.

Implementation Pattern - Multi-Instance Declaration and Struct Assignment

The following production-ready S7-SCL code demonstrates how to call Integral (FB1823) as a multi-instance, handling APL structures cleanly:

FUNCTION_BLOCK FB1008
TITLE = 'Custom_Mass_Totalizer'
{ S7_m_c := 'true' }
VAR_INPUT
    FlowRate_PV   : REAL;       // Raw analog flow rate (kg/h)
    Reset_Cmd     : BOOL;       // Totalizer reset pulse
    Hold_Cmd      : BOOL;       // Pause integration
END_VAR

VAR_OUTPUT
    Total_Mass    : REAL;       // Accumulated mass (kg)
END_VAR

VAR
    // Declare APL block as a Multi-Instance
    Inst_Integral : Integral;   // FB1823 from APL Library

    // Intermediate APL Analog Structure
    In_Struct     : STRUCT
        Value : REAL;
        ST    : BYTE := 16#80;  // 16#80 = Good Signal Quality
    END_STRUCT;
END_VAR

BEGIN
    // Populate structure components
    In_Struct.Value := FlowRate_PV;
    In_Struct.ST    := 16#80;   // Signal valid

    // Call Multi-Instance APL Integral Block
    Inst_Integral(
        In     := In_Struct,    // Pass full structure
        Reset  := Reset_Cmd,
        Hold   := Hold_Cmd,
        TI     := 3600.0        // Timebase: 3600s (hours to seconds)
    );

    // Read result from APL output structure
    Total_Mass := Inst_Integral.Out.Value;

END_FUNCTION_BLOCK

APL Data Structure and Variable Mapping Matrix

Compare primitive and APL structured data types in S7-SCL:

Standard S7 TypeCorresponding APL Structure TypeInternal ComponentsDefault Healthy ValueREALStruct (Analog)Value: REAL, ST: BYTEValue := 0.0; ST := 16#80;BOOLStruct (Binary)Value: BOOL, ST: BYTEValue := FALSE; ST := 16#80;TIMEREAL (APL Timebase)Seconds as floating pointTI := 1.0;MODEBYTEOperation Mode Bitmask16#01

Verification

To confirm that the SCL block calling the APL block functions correctly:
1. In S7-SCL, compile the block; verify that zero compiler errors and warnings occur.
2. Place the compiled block into a CFC chart assigned to OB35 (100 ms).
3. Connect an analog channel driver output (Pcs7AnIn.Out) to the block's FlowRate_PV input.
4. Switch CFC to Test Mode online; inject a simulated flow rate of 100 kg/h.
5. Verify that Total_Mass accumulates deterministically matching the integration formula.

Limitations and Operational Precautions

Never set ST := 16#00 (Bad) during normal operation unless propagating a genuine field sensor failure. If ST = 16#00, the APL Integral block automatically sets its bad quality output and freezes integration. Always ensure that the caller block's execution interval matches the sampling time assumed by the integrator.

Engineer FAQ

Where is the Integral block located in the PCS 7 catalog?

It is located in PCS 7 AP Library -> Blocks -> Math / Time -> Integral (FB1823).

Why does APL use structures instead of simple REAL variables?

Structures allow passing both the numerical value and its cryptographic signal health (NAMUR status) across blocks in a single signal connection.

Can I call Integral without a multi-instance?

Yes, by calling it with an external dedicated instance DB (CALL Integral, DB100), but multi-instance embedding inside a parent FB is preferred for modularity.

What does the TI parameter represent on Integral?

Parameter TI is the integration time constant in seconds. Setting TI := 3600.0 scales flow rates given in units per hour to seconds.

Technical References

Related Articles

Related Tags

  • S7-SCL
  • APL Blocks
  • Integral FB1823
  • Structured Variables
  • Quality Code
6 respuestas