S5 QW Output Word: Digital Bit Pattern vs Analog Conversion to S7

David Krause16 min read
HMI ProgrammingSiemensTechnical Reference
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

S5 QW Output Word: Digital Bit Pattern vs Analog Conversion to S7

When migrating a SIMATIC S5 program to S7, one of the most common sources of confusion is the meaning of an Output Word (QW) instruction. Engineers familiar with S7 CFC (Continuous Function Chart) often assume every QW points to an analog output module, because in CFC the symbol always maps to a channel of an AO card. That assumption breaks the moment the legacy S5 STL (Statement List) program is opened: QW in S5 is simply the 16-bit output area of the process image, and it is the responsibility of the slot in the rack that determines whether the value is interpreted as analog voltage/current or as sixteen discrete digital outputs.

This reference clarifies the dual nature of QW in S5, walks through a real-world STL segment, and provides a reproducible procedure for identifying whether a given QW must be migrated to a true analog output, a digital bit pattern, or a bit-memory word used purely as a flag cluster.

1. S5 Output Area Addressing Recap

In SIMATIC S5 the process image is divided into four byte-wide address spaces:

Mnemonic Meaning Width Typical mapping
IB / IW Input byte / Input word 8 / 16 bits Input module image (DI/AI)
QB / QW Output byte / Output word 8 / 16 bits Output module image (DO/AO)
FY / FW Flag byte / Flag word 8 / 16 bits Internal bit memory (M-equivalent)
DB / DW Data block / Data word 8 / 16 bits DBx.DBy / DBx.DWy

The PLC does not interpret the data type at the address level. The QW is simply a 16-bit cell in the output process image. The interpretation as analog or digital is performed by the hardware module installed in the slot assigned to that byte number, or by the consumer of the value if the QW is used as a flag cluster (no physical module attached).

2. Why "Output Word" Is Not Synonymous With "Analog Output"

A SIMATIC analog output module (for example the S5 6ES5 470-4UA12 or 6ES5 466-4UA11) contains a digital-to-analog converter. The PLC CPU writes a 16-bit integer to the corresponding QW; the module's DAC then converts that integer into a voltage (e.g., 0...10 V) or current (e.g., 4...20 mA) on the physical terminal. The PLC itself never sees "an analog value" - it only ever sees an integer.

Conversely, two digital output bytes that happen to be addressed as a word can be loaded into the same QW cell. The programmer may do this for several reasons:

  • To send a 16-bit pattern to sixteen discrete outputs (e.g., driving 16 valves with one transfer).
  • To populate both bytes of a digital output module as a single instruction for clarity or to reduce cycle-time load.
  • To use the output area as scratch space / bit cluster (a code-smell; FY/FW should normally be used).

Therefore, encountering QW64 in S5 STL does not prove an analog output exists. It only proves the programmer wrote 16 bits to the process image at byte offset 64.

3. S5-to-S7 Nominal Value Ranges

When the QW really does map to an analog output module, the S5 nominal value range depends on the specific module's resolution. The S7 family standardized the S7 analog range to 0...27648 (unipolar) and -27648...27648 (bipolar), but the S5 modules had different full-scale counts:

Module family (representative MLFB) Resolution Full-scale count Output ranges supported
6ES5 470-4UA12 (AO 8x8 bit) 8 bit 0...255 0...10 V, +/-10 V, 0...20 mA, 4...20 mA
6ES5 466-4UA11 (AO 4x12 bit) 12 bit 0...4096 (unipolar) / +/-4096 (bipolar) 0...10 V, +/-10 V, 4...20 mA
6ES5 467-4UA11 (AO 4x16 bit) 16 bit 0...27648 Same ranges, S7-compatible
Generic S7 AO (e.g. SM 332 6ES7332-5HF00) 11/12/13/14/15/16 bit selectable 0...27648 0...10 V, +/-10 V, 0...20 mA, 4...20 mA

If your migration source module is a 12-bit S5 AO, the S7 scaling function (FC105 "SCALE" or the IEC "NORM_X / SCALE_X" blocks) must be reconfigured with the S5 full-scale count, not 27648, otherwise the analog actuator will see a 6.7x over- or under-range.

4. STL Segment Walk-Through

The following S5 segment is the canonical example that causes confusion:

Segment 1
Name : SENDEXAM
:C   DB  80              ; open DB80
:L   DW   1              ; ACCU1 = DB80.DW1
:DO  DW   1              ; ACCU1 OR DB80.DW1 (OR with data word 1)
:C   DB   0              ; close DB
:L   DW   1              ; ACCU1 = previous result
:A   F  101.0            ; AND flag 101.0 (typically a trigger / start flag)
:JC  =M001               ; jump to M001 if result <> 0
:L   KH  A001            ; load constant hex A001
:T   QW  64              ; transfer to output word 64
:L   KH  0010            ; load constant hex 0010
:T   QW  66              ; transfer to output word 66
:S   F  101.0            ; set flag 101.0 (latch trigger)
:BEU                     ; block end unconditional

Key observations:

  1. The two T QW instructions write raw 16-bit values to the output process image. No scaling, no linearization, no conversion - the values 0xA001 and 0x0010 are placed as-is.
  2. If the slot for QW64/QW66 holds a digital output module, the 16 bits of each word become 16 individual relays/transistors. Bit 0 of QW64 (address Q64.0) would be set because 0xA001 = 1010 0000 0000 0001 in binary.
  3. If the slot for QW64/QW66 holds an analog output module, the value 0xA001 = 40961 decimal is a nonsensical analog command (way beyond any normal S5 full-scale count of 255, 2048, 4096, or 27648). This is a strong indicator that the output is digital.
  4. The trigger flag F101.0 is used as a one-shot / hand-shake - typical for "send the bit pattern once, then do not resend."

5. Hex-Value Pattern Recognition

For a quick first-pass classification of an unknown QW in S5 STL, the constant value is highly diagnostic:

Typical value seen Likely intent Reasoning
0x0001 ... 0x8000 (single bit set) Digital bit pattern Corresponds to a single digital output on the word (e.g., Q64.0 or Q65.7).
0x00FF, 0xFF00, 0xFFFF Digital bit pattern Typical "all on" patterns for a byte or word of digital outputs.
0xA001, 0x0010, 0x1000 Almost certainly digital Hex values with isolated bits and no analog-full-scale relationship (no multiple of 256, 1024, 2048, 4096, 8192, 13824, 27648).
0 ... 4095 (decimal) Possibly 12-bit analog Fits the S5 12-bit AO full-scale count of 4096.
0 ... 27647 (decimal) Possibly 16-bit analog Fits the S7 AO range (only if the S5 module was 16-bit, e.g., 6ES5 467).
0 ... 255 (decimal) Possibly 8-bit analog Fits the S5 8-bit AO range (e.g., 6ES5 470).
0 ... 1023 / 0 ... 2047 / 0 ... 8191 Possibly 10-bit / 11-bit / 13-bit analog Indicates older S5 modules; check MLFB.

The combination "0xA001 on QW64 and 0x0010 on QW66" sets only a few discrete bits, which is the signature of a digital bit pattern written to a QW pair. There is no plausible 0-10 V or 4-20 mA interpretation for an analog module in any S5 resolution.

6. Hardware Cross-Check Procedure

When the source code is ambiguous, the configuration and the wiring must be consulted:

  1. Open the original S5 hardware configuration (COM 115F / COM S5 or STEP 5 HWConfig equivalent). Note the slot assignment and the module MLFB at the byte addresses 64 and 66 (S5 analog modules usually start at even byte numbers; digital output bytes 32 and 64 are common for SM 322 / S5 6ES5 482 / 6ES5 482-1ALA11 equivalents).
  2. Check the I&C drawing / EPLAN / wiring diagram. Trace QW64 bit 0 to a terminal. If that terminal drives a 24 V relay coil, the channel is digital.
  3. Measure with a multimeter in the de-energized state. Look for pull-up / pull-down resistors, flyback diodes, and the rated load. An AO card output is short-circuit-proof to the module's common, and the loop impedance to a 4-20 mA actuator is typically 250-600 ohm. A DO output is either a transistor (sink/source) or a relay contact.
  4. Read the Siemens Industry Online Support entry for the MLFB. The functional description explicitly states "Analog Output" or "Digital Output." Cross-check at Siemens Industry Mall for the historical datasheet.

7. Mapping QW to S7

The S7 output process image layout is identical in concept but uses the I/O address (PII / PIQ) of the inserted module. The byte offset is set by the slot and the channel start address in HWConfig (TIA Portal: Device configuration → Properties → I/O addresses). Typical S7 mapping:

S5 reference S7 reference (default) Notes
QW 64 (digital pattern) QW 64 or QW 0 after slot re-numbering Address depends on the S7 slot used. S7 lets you freely re-assign addresses in HWConfig; pick a clean PII/PIQ layout.
QW 64 (analog) QW 64 mapped to channel 0 of the AO card Use the same byte offset where possible to minimize STL-to-SCL/ST translation effort.
F 101.0 M 101.0 or "Trigger".Q in a FB static tag Flags become Merkers in S7. The bit address space (M) is identical.
DB 80 / DW 1 DB80.DBW0 in S7 Word 1 in S5 = Byte 0/1 = DBB0/DBB1 = DBW0 in S7 (note: S5 DW n is a 16-bit word; S7 DBW n has the same meaning but offset is byte-based).

8. STL-to-S7 Translation Patterns

The original S5 STL transfers to S7 STL (or SCL) almost line-for-line, but the syntax differs:

// S5 source
:L   KH  A001
:T   QW  64
// S7 STL equivalent
L    W#16#A001
T    QW  64
// S7 SCL equivalent ("cleaner")
QW64 := W#16#A001;
QW66 := W#16#0010;
// S7 Structured Text (IEC 61131-3) variant
QW64 := 16#A001;  // digital bit pattern
QW66 := 16#0010;  // digital bit pattern

Important detail: the S7 W#16# literal is unsigned 16-bit, exactly matching S5 KH. The older S7 B#16# would be wrong - it is only 8 bits and would truncate 0xA001 to 0x01, masking out 15 of the 16 intended bits.

9. Edge Case: QW Used as Bit-Cluster Without Any Module

Some legacy S5 programs write to QW addresses that have no module at all. The CPU simply overwrites a part of the process image that is never read back by hardware. The bits still toggle in the image, so the programmer can read them with A Q 64.0 / = Q 64.0 as if they were outputs. This pattern is functionally a flag cluster in disguise and should be migrated to M area in S7 to avoid confusion with real outputs that may be added later.

Diagnostic test: in STEP 5 online, set the QW and read the corresponding output LEDs on the rack. If the LEDs do not change, the QW is unassigned and is acting as a scratch register. In TIA Portal, the equivalent check is to put the CPU in "Monitor & Force" mode on the PII/PIQ and confirm that no slot reacts.

10. Edge Case: Mixed-Use QW in One Byte

It is also possible for a byte to be used as an analog channel on one bit and as a digital output on the other - although rare and almost always a bug in the S5 program. Example: an 8-bit S5 analog output module at byte 32 may share the same physical connector footprint as a 4-bit digital output. The S5 CPU cannot prevent the dual assignment; the programmer is expected to be aware of which channels are wired to which device. During migration, this must be untangled by either splitting the S5 QW into two separate S7 channels (one AO, one DO) or by documenting the unusual wiring and keeping the legacy assignment with comments in the S7 source.

11. Verification Checklist

Before commissioning a migrated S7 program that contains QW writes, perform the following:

  1. Symbol table parity: Create a symbol table in TIA Portal / STEP 7 that maps every QW used in the S5 source to a meaningful S7 symbol. If the symbol name contains "AO" or "VALVE_OUT" but the actual hardware is a digital card, fix the name or the hardware.
  2. Cross-reference check: Use the S5 "Cross-Reference" listing to find every read and write of the QW. If the value is read with L QW 64 in many places as a single 16-bit value, the intent is likely digital pattern. If the value is fed into scaling math, the intent is analog.
  3. Force test in S7 PLCSIM: Load the migrated program into PLCSIM, force the QW, and watch the simulated channel. This catches 90% of addressing errors before going to the plant.
  4. Voltage / current measurement on site: Put a multimeter or a current clamp on the output terminals while the S7 program runs. A digital output should sit at 24 V (or 0 V) steady. An analog output should ramp / modulate within the configured range.
  5. Scaling boundary test: Force QW64 = 0 and QW64 = 27648 (or the S5 full-scale equivalent). The field instrument should reach exactly its 0% and 100% points. Any offset or gain error here means scaling constants need adjustment.

12. Common Pitfalls When Migrating

Pitfall Symptom Fix
Assuming every QW is analog S7 program tries to scale a digital bit pattern with FC105, producing wild output values Identify the QW intent first (see Section 5). Use the S5 hardware list and wiring diagram, not the variable name.
S5 full-scale (e.g. 4096) used with S7 FC105 default (27648) Analog actuator only reaches 14.8% of full scale Pass the S5 full-scale value to FC105's HI_LIM input, or rewrite with NORM_X / SCALE_X using the correct range.
Using B#16# instead of W#16# Upper byte of digital pattern is lost; only bit 0 of lower byte is set Use W#16#A001 for a 16-bit word literal.
Forgetting that S5 DW numbering starts at 1, S7 DBW starts at 0 DB offsets are off by 1, data block content is shifted Subtract 1 from every S5 DW/DL/DR reference when translating to S7 DBW/DBB/DBD, or use the STEP 5 → STEP 7 converter (S5 to S7 converter plug-in) which auto-adjusts.
No module installed for an unassigned QW CPU goes into SF (system fault) on first scan due to peripheral access error Either install the expected module, replace the QW access with an M-area flag, or use SFC 36 / SFC 37 to mask the missing I/O.
Output address conflict with an S7 input that maps to the same byte CPU reports address conflict; OB 70 / OB 121 / OB 122 triggered Re-number the I/O in TIA Portal / HWConfig. S7 does not allow a single byte to be both an input and an output.

13. Safety Considerations for Migration

WARNING: A QW that drives a digital relay coil in the S5 plant, when mistakenly wired to an analog output card in the new S7 cabinet, will deliver a continuous voltage (e.g., 0...10 V) to a 24 V relay coil. The relay will overheat, may weld closed, and the actuator downstream of the relay will not be de-energizable. Always validate QW intent and verify the actual hardware slot before applying power to the new S7 rack.

For plants that contain safety-relevant actuators (e.g., ESD valves, fire dampers, burner shut-off), the S5 program is often safety-related and cannot be migrated "bit-for-bit" without a fresh risk assessment per IEC 61511 / IEC 61508. S5 CPUs are no longer supported in safety-certified installations - consider a safety PLC (S7-1500F, ET 200SP F, or SIMATIC S7-300F) and re-engineer the safety function.

14. Reverse-Engineering Flowchart

The following decision tree summarizes the classification procedure for any QW encountered in S5 STL during a migration:

  1. Locate the QW in the S5 source. Note the byte number (e.g., QW64).
  2. Open the S5 hardware config. What module is at slot for byte 64?
  3. If module is Digital Output (SM 322 / S5 6ES5 482 / similar) → QW is a digital pattern. Migrate as QW in S7 with the same byte offset. No scaling needed.
  4. If module is Analog Output (SM 332 / S5 6ES5 466 or 470) → QW is a true analog command. Note the module's full-scale count. Migrate the value range and re-scale with FC105 / NORM_X / SCALE_X accordingly.
  5. If no module is at the slot → QW is acting as a bit cluster. Migrate to M-area. Add a code comment explaining the original intent.
  6. Cross-check the value being written: hex with isolated bits = digital. Decimal near 255 / 4096 / 27648 = analog. Anything else: verify with the S5 programmer's notes or the original commissioning report.

15. Quick-Reference Parameter Table

Parameter / mnemonic S5 syntax S7 STL syntax S7 SCL syntax
Load 16-bit constant L KH A001 L W#16#A001 variable := W#16#A001;
Transfer to QW T QW 64 T QW 64 QW64 := value;
Open data block C DB 80 OPN DB 80 implicit via "MyDB".
Load data word 1 L DW 1 L DB80.DBW 0 value := "MyDB".DW0;
OR with DW 1 OW DW 1 OW DB80.DBW 0 value := value OR "MyDB".DW0;
AND with flag 101.0 A F 101.0 A M 101.0 implicit boolean
Set flag 101.0 S F 101.0 S M 101.0 "Trigger" := TRUE;
Block end unconditional BEU BEU implicit (end of FC / OB / FB)

16. Tools for the Job

17. Engineering Notes

In practice, the S5 STL segment shown above (with the 0xA001 / 0x0010 constant and the F101.0 hand-shake) is a textbook "send 16 bits to 16 valves, then latch the done flag" routine. Migrating it requires no scaling, no analog configuration, and no FC105. The work is purely STL → ST/SCL cleanup, plus a clean symbol table entry (for example, QW64 := "valve_pattern_1";). Engineers who default to "QW means analog" end up hunting for an AO card that does not exist and waste hours chasing a non-problem. Always classify the QW before assuming the hardware type.

FAQ

Does an S5 Output Word (QW) always mean an analog output?

No. A QW is a 16-bit cell in the output process image; whether it is treated as analog or digital depends on the module installed in the assigned slot. A QW can also be used as a 16-bit digital pattern, or even as a flag cluster if no module is wired to that byte.

What is the S5 analog full-scale count and how does it differ from S7?

S5 analog outputs used 8-bit (0...255), 12-bit (0...4096 or +/-4096), or 16-bit (0...27648) ranges depending on the MLFB. S7 standardized on 0...27648. When migrating, the FC105 / NORM_X / SCALE_X high limit must be set to the S5 full-scale count of the original module, not 27648.

How do I translate S5 STL constants like KH A001 to S7?

Use the 16-bit hex literal: L W#16#A001; in S7 STL, or QW64 := W#16#A001; in S7 SCL. Do not use B#16#A001 - that is an 8-bit literal and will silently truncate to 0x01.

How do I tell if a QW in an old S5 program is analog or digital without the wiring diagram?

Look at the value being written: hex constants with isolated bits (e.g. 0xA001, 0x0010) almost always indicate a digital pattern. Decimal values near 255, 4096, or 27648 indicate analog. Then cross-check the S5 hardware configuration to confirm the module type at that byte offset.

Why is my S7 CPU going into system fault after migration when the S5 program ran fine?

The most common cause is a QW (or IB/IW) access to a byte that has no module installed in the S7 rack. The S7 CPU will raise a peripheral access error (SF LED) and call OB 122. Either install the expected module, change the S7 I/O address to a populated slot, or replace the QW access with M-area memory if the original QW was acting as a flag cluster.

Back to blog