Accessing RAW_VALUE from F-AI AL_STATE in PCS 7 CFC

David Krause12 min read
HMI ProgrammingSiemensTutorial / 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

Overview

The F-AI driver block in the Siemens PCS 7 Advanced Process Library (APL) and the fail-safe S7 F Systems library exposes a structured status output named AL_STATE. The AL_STATE UDT bundles the raw I/O word, scaled process value, dynamic limits, signal-quality flags, and passivation status of the channel into a single tag. Although every member of the structure is visible on the block's output pin, CFC cannot symbolically connect to nested structure elements directly without first exposing them as individual block I/O. This article documents two field-proven methods to extract RAW_VALUE (and any other member of AL_STATE) for downstream CFC logic: a small STL conversion function and the APL CH_V_AL channel block.

Library context. F-AI is shipped with the PCS 7 APL and the S7 F/FH Systems library. CH_V_AL is part of the PCS 7 APL. Both libraries are installed by the SIMATIC PCS 7 setup under Options > PCS 7 Library > APL or F-Library. Confirm that the master data library used by your project is at a release level compatible with the engineering station (PCS 7 V9.0 SP2 / V9.1 / V9.1 SP1 at the time of writing).

Prerequisites

  • SIMATIC PCS 7 V8.2 or higher with the Advanced Process Library installed.
  • STEP 7 / CFC editor with STL programming rights in the project.
  • A compiled CFC chart containing the F-AI (or AI) driver block.
  • Knowledge of the project's chart container hierarchy and operator-station rights for testing.

AL_STATE Structure Definition

The AL_STATE UDT is declared in the APL master data library as UDT 241 (or equivalent, version-dependent). The complete structure is reproduced below in the format that STEP 7 generates when you open the block type.

AL_STATE UDT members used by F-AI / AI driver blocks
Member Type Description
RAW_VALUE WORD Unprocessed A/D converter word, range 0..27648 for 4-20 mA / 0-10 V nominal range.
OVHRANGE REAL Upper over-range threshold (engineering units).
OVLRANGE REAL Lower over-range threshold (engineering units).
PASS_ON BOOL TRUE while the channel is passivated (input value held at substitute).
PASS_OUT BOOL Output passivation flag for downstream F-channels.
QCHF_HL BOOL High-limit hardware fault.
QCHF_LL BOOL Low-limit hardware fault.
QBAD BOOL Bad signal quality (substitute value in use).
QSIM BOOL Simulation active.
QSUBS BOOL Substitute value active.
ACK_REQ BOOL Acknowledgement required for a latched alarm.
V_DATA REAL Process value in engineering units, including bad-quality substitution.
QUALITY BYTE Quality code (see table below).
V_MOD REAL Process value as it enters the channel block (scaled, pre-quality masking).
QUALITY byte bit assignment (per PCS 7 APL convention)
Bit Mnemonic Meaning
0 Q_SIM Simulation
1 Q_SUBS Substitute value
2 Q_BAD Bad / invalid
3 Q_OVR Out of measuring range
4 Q_HL High-limit exceeded
5 Q_LL Low-limit exceeded
6 Q_PAS_ON Passivation ON
7 Q_PAS_OUT Passivation OUT

Why Direct CFC Access Triggers a Compiler Warning

When you drag a connection from AL_STATE to a CFC input of a different type, the compiler cannot perform implicit type promotion. The two most common warning codes are:

  • W: Type conflict when connecting STRUCT to elementary type. The receiving block expects a WORD or REAL, not the parent STRUCT.
  • W: Symbolic access to a structure element not allowed here. The CFC compiler resolves a path like AI.AL_STATE.RAW_VALUE in the symbol table, but the receiving block I/O must be declared as an exposed block parameter, not a deeply nested tag reference.

The symptom reported in the field (a single compiler warning, no error) typically indicates that the link is resolved at compile time but cannot be type-checked. The chart may still download, but the value will not be refreshed as the runtime model expects.

Solution 1 - STL Converter Function (Recommended for Custom Tags)

Create a small STL-convertible FC that has a STRUCT input of the same layout as AL_STATE and exposes every member as an individual output. Insert the FC into the chart, then connect AL_STATE of F-AI to the input pin of the FC. The example below implements a one-to-one fan-out of all members.

FUNCTION "AL_STATE" : VOID
TITLE = AL_STATE fan-out for F-AI
VERSION : 0.1
VAR_INPUT
  AL_STATE : STRUCT
    RAW_VALUE : WORD;
    OVHRANGE  : REAL;
    OVLRANGE  : REAL;
    PASS_ON   : BOOL;
    PASS_OUT  : BOOL;
    QCHF_HL   : BOOL;
    QCHF_LL   : BOOL;
    QBAD      : BOOL;
    QSIM      : BOOL;
    QSUBS     : BOOL;
    ACK_REQ   : BOOL;
    V_DATA    : REAL;
    QUALITY   : BYTE;
    V_MOD     : REAL;
  END_STRUCT;
END_VAR
VAR_OUTPUT
  RAW_VALUE : WORD;
  OVHRANGE  : REAL;
  OVLRANGE  : REAL;
  PASS_ON   : BOOL;
  PASS_OUT  : BOOL;
  QCHF_HL   : BOOL;
  QCHF_LL   : BOOL;
  QBAD      : BOOL;
  QSIM      : BOOL;
  QSUBS     : BOOL;
  ACK_REQ   : BOOL;
  V_DATA    : REAL;
  QUALITY   : BYTE;
  V_MOD     : REAL;
END_VAR
BEGIN
NETWORK
TITLE = Copy AL_STATE members to outputs
  L    #AL_STATE.RAW_VALUE;
  T    #RAW_VALUE;
  L    #AL_STATE.OVHRANGE;
  T    #OVHRANGE;
  L    #AL_STATE.OVLRANGE;
  T    #OVLRANGE;
  L    #AL_STATE.PASS_ON;
  T    #PASS_ON;
  L    #AL_STATE.PASS_OUT;
  T    #PASS_OUT;
  L    #AL_STATE.QCHF_HL;
  T    #QCHF_HL;
  L    #AL_STATE.QCHF_LL;
  T    #QCHF_LL;
  L    #AL_STATE.QBAD;
  T    #QBAD;
  L    #AL_STATE.QSIM;
  T    #QSIM;
  L    #AL_STATE.QSUBS;
  T    #QSUBS;
  L    #AL_STATE.ACK_REQ;
  T    #ACK_REQ;
  L    #AL_STATE.V_DATA;
  T    #V_DATA;
  L    #AL_STATE.QUALITY;
  T    #QUALITY;
  L    #AL_STATE.V_MOD;
  T    #V_MOD;
END_FUNCTION
Compilation note. The compiler warning about "L AR1 / L AR2 / LAR1 / LAR2 missing" only appears if the FC accesses AL_STATE through DB-of-instance indirection. With a direct VAR_INPUT structure it compiles cleanly. If your version of the FC needs to read a F-AI instance DB, declare the input as ANY and use L P##IN plus LAR1 sequence, or use the simpler in/out approach described next.

Connecting the converter

  1. Place the AL_STATE FC in the same CFC chart as the F-AI block.
  2. Drag a connection from the AL_STATE output of F-AI to the AL_STATE input of the FC. The compiler will accept the entire STRUCT because the types match.
  3. Connect the individual output pins of the FC (for example RAW_VALUE, QBAD, V_MOD) to downstream blocks such as limiters, alarms, or faceplate additions.
  4. Compile the chart. The warning should disappear because every cross-chart connection now uses an elementary type.

Solution 2 - Use the CH_V_AL Channel Block (Recommended Path)

Siemens provides the CH_V_AL block (PCS 7 APL > Channel blocks > Driver) specifically to wrap the scaled value V_MOD and re-expose the full AL_STATE for downstream use. The block adds additional alarms and feature flags while passing RAW_VALUE, V_MOD, and the quality byte through unchanged.

  1. Open the chart that contains F-AI.
  2. Insert CH_V_AL from the APL library into the chart.
  3. Connect V of F-AI to V of CH_V_AL.
  4. Connect V_MOD of F-AI to V_MOD of CH_V_AL.
  5. Connect the boolean signal Q_BAD (or other quality flags) from F-AI to the corresponding inputs of CH_V_AL.
  6. On the output side, CH_V_AL exposes its own AL_STATE structure. Connect any element of that structure to downstream blocks just as you would for F-AI.

The advantage of CH_V_AL is that it is an officially maintained APL type, ships with consistent F-attribute settings, and is supported by the PCS 7 Maintenance Station diagnostics. Custom STL converters are appropriate only when the chart topology prevents a standard block from being used, for example inside a unit that must be replicated by a type instance.

Why the Compiler Warns on "AI.AL_STATE.RAW_VALUE"

The expression AI.AL_STATE.RAW_VALUE is a fully qualified symbolic path. The CFC editor accepts it for display in the symbol browser and in the I/O field of a block, but it is not a valid connection source for a CFC link unless the receiving block has a parameter declared as IN_OUT of the same STRUCT type. When you paste AI.AL_STATE.RAW_VALUE into the input box of a block whose input is a WORD, the compiler sees a path that resolves to a structure element and warns that the implicit demotion is unsafe. The fix is to either:

  • Change the destination to accept the parent structure and demote inside the destination block, or
  • Insert an explicit fan-out (the STL FC or CH_V_AL) so that the connection is type-checked at every link.

Working with RAW_VALUE in CFC

The RAW_VALUE element is the unmodified A/D word, normally 0..27648 for a 4-20 mA input. Common downstream uses include:

RAW_VALUE derived calculations
Use case Formula Notes
Convert to percent of range PCT = (RAW_VALUE / 27648.0) * 100.0 Apply 32-bit REAL cast via DI_REAL STL instruction or by setting a WORD_TO_REAL intermediate tag.
Convert to mA mA = (RAW_VALUE / 27648.0) * 16.0 + 4.0 Valid only for 4-20 mA nominal; for 0-20 mA, change offset to 0 and span to 20.
Detect wire break WB := RAW_VALUE = 0 For 4-20 mA inputs a reading of 0 typically indicates open circuit; check your module-specific behaviour.
Detect over-range OVR := RAW_VALUE > 32511 (or < 0) PLC S7-300/S7-400 analog input modules return 0x7FFF (32767) at over-range and 0x8000 (-32768) at under-range.
Safety note. RAW_VALUE is not a fail-safe value. For safety-related logic, use V or V_MOD of the F-AI block (which is part of the F-runtime signature) and respect the passivation behaviour of the F-channel. Reading RAW_VALUE for diagnostic display on the OS is fine, but never substitute it for the safety-rated V in an interlock.

Step-by-Step Implementation

  1. Insert the converter. Open the S7 program > Blocks, copy the AL_STATE FC source above into a new source file, and compile it to add the block to the master data library.
  2. Place the block. Open the CFC chart with F-AI. Drag AL_STATE from the library into the chart.
  3. Connect AL_STATE. Click the AL_STATE output pin of F-AI and route to the AL_STATE input pin of the FC. The connection colour should turn green (type-consistent).
  4. Expose outputs. Connect RAW_VALUE from the FC to your downstream block. If you also need QBAD, QSIM, or V_DATA, add those connections now.
  5. Compile and download. Compile the chart (CFC > Charts > Compile). The full chart should now compile without warnings related to the new connections.
  6. Verify on the OS. Place RAW_VALUE in a faceplate or a free-design diagnostic view. Force a known value at the input and confirm the OS updates within the standard PCS 7 OS refresh interval (typically 1 s for dynamic fields, 5 s for standard fields).

Verification

After the chart has been compiled and downloaded, run the following checks:

  • Cross-reference. In STEP 7, use Options > Reference Data > Display and confirm that every output pin of the AL_STATE FC has at least one reference. Any output with zero references can be removed to keep the OB1 cycle time lean.
  • Online monitor. Open the chart in Debug > Monitor mode. Toggle the F-AI simulation bit and confirm that QSIM of the FC transitions within one OB1 cycle.
  • OS faceplate. In WinCC Explorer, force a value on the AI channel and confirm that the scaled value, raw value, and quality byte all update coherently.
  • Passivation test (F-channels only). Trigger a passivation from the safety matrix and verify that PASS_ON of the FC goes TRUE and that V_DATA shows the configured substitute value.

Troubleshooting Matrix

F-AI / AL_STATE common issues
Symptom Likely cause Resolution
Compiler warning: type conflict STRUCT → elementary Direct connection from AL_STATE to a non-structure input Insert STL FC or CH_V_AL to expose elementary pins
RAW_VALUE always shows 0 on the OS Connection routed to the wrong instance, or input not enabled in HW Config Check the symbol address in the cross-reference and verify the channel is enabled in HW Config
QBAD stuck TRUE even with valid input Channel is passivated; substitute active Acknowledge passivation from the safety matrix; check F-runtime group signature
Runtime value flickers between two readings Multiple chart instances driving the same tag Use the Cross-Reference tool to find duplicate writers and remove the duplicate connection
FC does not compile, "Unknown structure element" Library version mismatch between UDT and FC Re-import the master data library that matches the project version
OS value is stale by 5+ seconds Tag not declared as dynamic in the WinCC tag list Open WinCC tag properties and set the acquisition cycle to 500 ms or 1 s

Performance Considerations

An STL fan-out FC of 15 members compiles to roughly 30 STL instructions (L/T pair per member) and adds approximately 8-12 microseconds of OB1 execution time per call on a CPU 410-5H. For plants with several hundred F-AI channels, prefer a single CH_V_AL per channel because the block is generated in optimised MC7 code and avoids the parameter-pass overhead of a call-by-value FC.

Field-Proven Caveats

  • The order of members inside AL_STATE is fixed by the library. Do not reorder them in a derived UDT or you will silently desynchronise the FC.
  • Some PCS 7 V8.x versions expose QCHF_HL/QCHF_LL only when the channel is configured for HART; on a plain 4-20 mA channel those bits are always 0.
  • When migrating from V8.2 to V9.x, regenerate the CFC charts; the symbol table for AL_STATE was refactored in V9.0 and old connections may show as "type conflict" until the chart is recompiled.
  • Do not read RAW_VALUE across a cross-cpu link (for example via SEND/RECV) without first placing it in a DB; direct access to instance-DB internals across a network is not supported in PCS 7.

FAQ

How do I expose RAW_VALUE from F-AI to another CFC block?

Insert a small STL FC (or use the APL block CH_V_AL) that copies every member of the AL_STATE structure to its own output pin. Connect AL_STATE of F-AI to the FC's structured input, then connect the FC's RAW_VALUE output to the destination block. This eliminates the CFC compiler warning that occurs when a STRUCT is wired directly to an elementary type.

Why does CFC reject AI.AL_STATE.RAW_VALUE as a connection source?

CFC does not allow deep structure-element paths as link sources. The path is valid for display in the symbol browser but the receiving block must declare an IN_OUT parameter of the parent STRUCT type. The simplest workaround is the STL fan-out FC shown above, which promotes RAW_VALUE to a top-level WORD output.

What is the value range of RAW_VALUE on a standard 4-20 mA input?

Nominal range is 0 to 27648 (16-bit unsigned). Values above 32511 indicate over-range and the value 0x7FFF (32767) signals a wire break on most SM 331 / SM 332 modules. Use these limits when building custom diagnostics in CFC.

Can I use RAW_VALUE inside a fail-safe program?

No. RAW_VALUE is a non-safety tag and is excluded from the F-runtime signature. For safety logic always use the F-AI output V (or V_MOD) and respect the channel's passivation flags PASS_ON and PASS_OUT.

Does CH_V_AL provide RAW_VALUE on its output?

Yes. CH_V_AL re-exposes the full AL_STATE structure, including RAW_VALUE, V_MOD, V_DATA, and the QUALITY byte, plus additional alarm limits. It is the preferred path when the chart must remain standard-library compliant and supported by the PCS 7 Maintenance Station.

Back to blog