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.
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(orAI) 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.
| 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). |
| 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
WORDorREAL, not the parentSTRUCT. -
W: Symbolic access to a structure element not allowed here. The CFC compiler resolves a path like
AI.AL_STATE.RAW_VALUEin 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
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
- Place the
AL_STATEFC in the same CFC chart as theF-AIblock. - Drag a connection from the
AL_STATEoutput ofF-AIto theAL_STATEinput of the FC. The compiler will accept the entireSTRUCTbecause the types match. - 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. - 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.
- Open the chart that contains
F-AI. - Insert
CH_V_ALfrom the APL library into the chart. - Connect
VofF-AItoVofCH_V_AL. - Connect
V_MODofF-AItoV_MODofCH_V_AL. - Connect the boolean signal
Q_BAD(or other quality flags) fromF-AIto the corresponding inputs ofCH_V_AL. - On the output side,
CH_V_ALexposes its ownAL_STATEstructure. Connect any element of that structure to downstream blocks just as you would forF-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:
| 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. |
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
-
Insert the converter. Open the S7 program > Blocks, copy the
AL_STATEFC source above into a new source file, and compile it to add the block to the master data library. -
Place the block. Open the CFC chart with
F-AI. DragAL_STATEfrom the library into the chart. -
Connect
AL_STATE. Click theAL_STATEoutput pin ofF-AIand route to theAL_STATEinput pin of the FC. The connection colour should turn green (type-consistent). -
Expose outputs. Connect
RAW_VALUEfrom the FC to your downstream block. If you also needQBAD,QSIM, orV_DATA, add those connections now. - Compile and download. Compile the chart (CFC > Charts > Compile). The full chart should now compile without warnings related to the new connections.
-
Verify on the OS. Place
RAW_VALUEin 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_STATEFC 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-AIsimulation bit and confirm thatQSIMof 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_ONof the FC goes TRUE and thatV_DATAshows the configured substitute value.
Troubleshooting Matrix
| 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_STATEis 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_LLonly 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_STATEwas refactored in V9.0 and old connections may show as "type conflict" until the chart is recompiled. - Do not read
RAW_VALUEacross 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.