Problem Overview
The S7-1200 family reads current-loop analog inputs as integer counts in IW (Input Word) tags. For a 4-20 mA loop on an SM 1234 AI channel, the nominal integer range is 0 to 27648 counts, with 4 mA corresponding to 5530 counts and 20 mA to 27648 counts. A flow meter driving 4-20 mA proportional to 0-1000 m³/h cannot be displayed directly on an HMI; the raw count must be converted to a floating-point engineering value, then compared against a process threshold (in this case 500 m³/h for a low-flow alarm).
This article walks through the canonical TIA Portal implementation: NORM_X to convert the raw integer into a 0.0-1.0 real, SCALE_X to map that real into the engineering range 0.0-1000.0, and a comparison block to drive a Boolean low-flow tag that the HMI displays. The procedure follows the official Siemens instruction sequence documented under "Processing of analog values" in the S7-1200 manual collection.
Prerequisites
Hardware
- S7-1200 CPU, firmware 4.x or later. The NORM_X and SCALE_X instructions are available in all V13+ firmware; legacy SCALE and NORM instructions are retained for compatibility.
- Signal module capable of 4-20 mA input. The SM 1234 (catalog number
6ES7234-4HE32-0XB0) is the typical choice — 4 analog inputs (13-bit resolution) plus 2 analog outputs (14-bit). Other AI-capable SMs (SM 1231, SM 1232) and the CPU onboard AI on 1211C/1212C/1214C/1215C/1217C CPUs are functionally equivalent for this procedure. - 2-wire or 4-wire flow transmitter with 4-20 mA loop output.
Software
- TIA Portal V15.1 or later (V16/V17/V18 also valid).
- HMI configuration: Comfort Panel, Basic Panel (KTP), or WinCC Runtime on a PC.
Wiring
- Connect the transmitter positive terminal to the AI channel input (e.g., I+, channel 0).
- Connect the transmitter negative to the module common (M, channel 0). For 4-wire transmitters, provide a separate 24 VDC loop supply.
- The S7-1200 SM analog inputs support both voltage and current modes; current mode is selected in the device configuration by setting the measuring range to "Current (4-20 mA)" per channel.
Analog Input Signal Ranges
The S7-1200 normalizes the analog input using a 16-bit signed integer representation. The relevant numerical ranges for a unipolar 4-20 mA input:
| Process variable | Current (mA) | Decimal count (IW) | Hex |
|---|---|---|---|
| Overflow / out-of-range high | > 22.81 | 32767 | 7FFF |
| Overrange high | 20.000 – 22.81 | 27649 – 32511 | 6C01 – 7EFF |
| Nominal high | 20.000 | 27648 | 6C00 |
| Nominal range | 4.000 – 20.000 | 5530 – 27648 | 159A – 6C00 |
| Nominal low | 4.000 | 5530 | 159A |
| Underrange / wirebreak | < 4.000 | -32768 – 5529 | 8000 – 1599 |
| Negative overflow | < -22.81 | -32768 | 8000 |
The "nominal range" 5530 to 27648 is the linear scaling domain. Below 5530, the AI is reporting an underrange condition — this corresponds physically to an open loop (wire break) or a transmitter output that has fallen out of its calibrated span.
When a wire break occurs on an active 4-20 mA input, the input drives toward 0 mA; the S7-1200 returns approximately 0 counts (below 5530), and the diagnostics bit for that channel is set if diagnostics are enabled. The NORM_X instruction will pass this through, but the downstream SCALE_X will yield an engineering value below 0 m³/h — a useful built-in indicator for HMI fault coloring, but not a valid measurement.
Memory Layout and the MW/MD Overlap Pitfall
TIA Portal allows symbolic addressing, but when falling back to absolute memory (MW10, MD20, etc.), the engineer must respect overlapping regions. Merker word MW10 occupies bytes MB10 and MB11; Merker double word MD10 occupies bytes MB10 through MB13. Writing both MW10 and MD10 in the same scan corrupts the higher word of MD10 because NORM_X writes 4 bytes to MD10 and the absolute tag MW10 aliases the first two bytes. This is the exact trap that surfaces in early ladder implementations of NORM_X / SCALE_X cascades.
The recommended practice is to assign each NORM_X and SCALE_X output to a non-overlapping MD (double word) and never reuse adjacent MW or MD addresses that share byte ranges.
Suggested tag table:
| Symbolic name | Absolute address | Data type | Purpose |
|---|---|---|---|
AI_Flow_Raw |
IW1 | INT | Raw input word from channel 0 |
Norm_Flow |
MD12 | REAL | NORM_X output (0.0 – 1.0) |
Scaled_Flow_m3h |
MD20 | REAL | SCALE_X output (0.0 – 1000.0 m³/h) |
LowFlow_Alarm |
M0.0 | BOOL | Comparison result: scaled < 500.0 |
Flow_Fault |
M0.1 | BOOL | Out-of-range or wirebreak indicator |
The MD12 (norm result) and MD20 (scaled result) addresses are deliberately separated to avoid the trap where MW10 aliased into MD10.
Step 1 — Normalize with NORM_X
Add the NORM_X instruction from the "Converter operations" folder to a code block (typically OB1 or a dedicated FC for scaling). NORM_X performs the linear normalization:
OUT = ((FLOAT(IN) - MIN) / (MAX - MIN)), clamped to 0.0 ... 1.0
For a 4-20 mA input:
-
IN=AI_Flow_Raw(the raw IW) -
MIN= 5530.0 (the count at 4 mA) -
MAX= 27648.0 (the count at 20 mA) -
OUT=Norm_Flow(MD12, REAL)
TIA Portal default data types for the MIN/MAX pins accept REAL. Set MIN = 5530.0 and MAX = 27648.0 — these are the standard S7-1200 nominal-range endpoints for 4-20 mA inputs as documented in the Siemens S7-1200 manual collection under "Processing of analog values".
When the loop is healthy and the transmitter outputs, say, 12 mA (50% of span), the raw IW is approximately 16589. NORM_X computes:
OUT = (16589 - 5530) / (27648 - 5530) = 11059 / 22118 ≈ 0.5000
This 0.5 normalized real feeds the next stage.
Step 2 — Scale to Engineering Units with SCALE_X
SCALE_X maps a normalized 0.0-1.0 input into an arbitrary engineering range:
OUT = (IN * (MAX - MIN)) + MIN, with IN clamped to 0.0 ... 1.0
For this flow application:
-
IN=Norm_Flow(MD12) -
MIN= 0.0 (engineering zero) -
MAX= 1000.0 (engineering full scale, m³/h) -
OUT=Scaled_Flow_m3h(MD20, REAL)
At 12 mA loop current with Norm_Flow = 0.5, SCALE_X returns:
OUT = (0.5 * (1000.0 - 0.0)) + 0.0 = 500.0 m³/h
The output is a REAL type, suitable for direct HMI display via the configured tag.
Step 3 — Low-Flow Threshold Logic
The HMI requirement is a Boolean indicator that illuminates when flow drops below 500 m³/h (50% of full scale). Insert a CMP_LT (less-than) comparator after SCALE_X:
-
CMP_IN1=Scaled_Flow_m3h(MD20) -
CMP_IN2= 500.0 (REAL constant) -
Result=LowFlow_Alarm(M0.0, BOOL)
The "<" (CMP < REAL) block produces a direct TRUE when flow is below 500 m³/h, no inversion required. For a clean HMI implementation, name the tag LowFlow_Active and bind it to a circle indicator on the screen. Color the circle red when TRUE, green when FALSE.
If a greater-or-equal comparator was wired by mistake, the resulting tag would invert polarity — meaning the lamp is ON when flow is above threshold. This is a common wiring error; use a less-than comparator directly to drive the alarm state.
Step 4 — Out-of-Range and Wirebreak Detection
The simple 0-1000 m³/h scaling cannot distinguish a valid zero flow reading from a wire break or transmitter failure — both produce an underrange input. Add a parallel diagnostic block:
- Compare
AI_Flow_Rawagainst 5530 (underrange). If IW < 5530, setFlow_Fault= TRUE. - Compare
AI_Flow_Rawagainst 27648 (overrange). If IW > 27648, setFlow_Fault= TRUE.
Both comparisons belong in OB1 or a cyclic FC. Combine the two via an OR instruction driving M0.1.
Additionally, enable the channel diagnostics in the device configuration of the SM 1234 (Properties → Analog inputs → Channel 0 → Diagnostics: "Wire break" enabled). When the loop opens, the diagnostic interrupt fires and the channel value is forced to 0; the diagnostic OB (OB82) executes and can be configured to set Flow_Fault and to log the event to the HMI alarm buffer. The SM 1234 (6ES7234-4HE32-0XB0) supports per-channel wire-break and overflow diagnostics per its hardware specifications.
Step 5 — HMI Tag Configuration
On a Basic or Comfort Panel, the HMI is linked to the PLC via the HMI tag table. The following tags must be added:
| HMI tag name | PLC tag | Data type | Acquisition | Scaling |
|---|---|---|---|---|
Flow_m3h |
Scaled_Flow_m3h (MD20) |
Real | Cyclic, 1 s | None |
LowFlow |
LowFlow_Alarm (M0.0) |
Bool | Cyclic, 500 ms | None |
FlowFault |
Flow_Fault (M0.1) |
Bool | Cyclic, 500 ms | None |
Drag the Flow_m3h tag onto a numeric output field and set the format to "9999.9" or similar. Bind LowFlow to a circle graphic and configure its appearance property "Color animation" based on the tag state. Repeat for FlowFault with a different color (typically yellow or red).
If a KTP400 Basic or similar panel is used, ensure the HMI connection points to the PLC and that symbolic addressing is enabled in both the PLC and HMI project so DB references are not required.
Step 6 — Complete OB1 Implementation
A complete OB1 segment in STL form (for documentation) demonstrates the data flow:
L "AI_Flow_Raw" // IW1, INT
ITD // INT to DINT
DTR // DINT to REAL (acc 1)
NORM_X EN=1, MIN=5.530e+003, MAX=2.7648e+004, OUT=>"Norm_Flow"
SCALE_X EN=1, MIN=0.0, MAX=1000.0, OUT=>"Scaled_Flow_m3h"
L "Scaled_Flow_m3h"
L 5.000e+002
<R // REAL less-than
= "LowFlow_Alarm"
L "AI_Flow_Raw"
L 5530
<I // INT less-than (underrange)
O // OR with overrange check
L "AI_Flow_Raw"
L 27648
>I
= "Flow_Fault"
In FBD/LAD view this becomes a linear cascade: IW → NORM_X → MD12 → SCALE_X → MD20 → CMP → M0.0; and a parallel diagnostic branch from IW → two CMPs → OR → M0.1.
Verification and Commissioning
Perform the following checks before declaring the scaling valid:
- Sensor substitution. Disconnect the field transmitter and apply a precision current source (e.g., WIKA CEP1000 or Beamex MC6) at 4.000 mA. The HMI must display 0.0 m³/h.
- Step to 50%. Apply 12.000 mA. HMI should show 500.0 ± 0.5 m³/h (tolerance per transmitter datasheet and AI module accuracy).
- Step to full scale. Apply 20.000 mA. HMI should show 1000.0 ± 0.5 m³/h.
-
Wire-break simulation. Open the loop at the field terminals. Verify that:
-
Flow_m3hdrops to a value at or below 0 (depending on wire-break behavior of the AI module). -
FlowFaultbit = TRUE. - HMI diagnostic banner appears if configured.
-
-
Low-flow threshold. Reduce current to 11.95 mA (just below 50% of span, equivalent to ~498 m³/h).
LowFlow_Alarmshould transition to TRUE. Restore to 12.05 mA (~502 m³/h);LowFlow_Alarmshould drop to FALSE. - Memory inspection. With the PLC in RUN, use a watch table to confirm MD12 and MD20 update each scan and that no overlapping memory is being written.
If any step fails, consult the troubleshooting matrix below.
Troubleshooting Matrix
| Symptom | Probable cause | Remedy |
|---|---|---|
| HMI shows 0.0 m³/h regardless of input | AI channel not configured for current mode, or wiring reversed | In TIA Portal device config, set the channel measuring range to "Current (4-wire) 4-20 mA" or "Current (2-wire) 4-20 mA" per transmitter type. Verify polarity at the terminals. |
| HMI shows -3276.8 m³/h or similar negative large value | NORM_X MIN set to 0 instead of 5530 | Change MIN to 5530.0 to match the 4 mA count. The Siemens S7-1200 "Processing of analog values" reference specifies this as the standard 4-20 mA minimum. |
| Scaled value jitters or steps in increments > 0.1 m³/h | 13-bit AI resolution limit | The SM 1234 specifies 13-bit resolution for the AI channels. Expect quantization noise of ±0.5 LSB. Apply a moving average in the PLC if smoother display is required. |
| LowFlow_Alarm stuck ON | Constant 500.0 typed as INT instead of REAL, causing truncated comparison | Type the constant as 500.0 (REAL). TIA Portal will reject INT-DINT-REAL mismatch on the CMP input. |
| MD20 contains garbage or overlapping tags | Another block writes to MW20 or MD20 (overlapping with MD20) | Audit all absolute addresses. Reassign Scaled_Flow_m3h to a fresh MD that is not aliased by any other used tag. |
| HMI shows "####" overflow | Numeric field format too narrow for value | Widen the format on the HMI to allow at least 6 digits before the decimal. |
| Flow_Fault never asserts | Diagnostics not enabled on the SM 1234 channel | In device configuration, enable "Wire break" and "Overflow/underflow" under the channel diagnostics. Ensure OB82 is present in the program. |
| NORM_X output pinned at 1.0 | MAX constant set below actual input | Verify MAX = 27648.0. Anything above 27648 saturates the output at 1.0 per NORM_X clamping. |
Field-Proven Caveats
- Two-wire vs four-wire transmitter. The SM 1234 supports both. For a two-wire loop, the channel must be configured for "Current (2-wire)" measurement and the module provides the loop supply (typically 24 VDC). Misconfiguration yields an apparent 0 mA reading.
- Common-mode and ground loops. For long cable runs (>30 m) or installations with significant VFD noise, use a shielded twisted pair with the shield grounded at the panel end only. Differential noise on the analog signal can produce phantom readings of several m³/h.
- HMI update rate. A 1-second cyclic acquisition is acceptable for a flow display. Tightening below 250 ms adds little value and increases bus load on Profinet between the S7-1200 and the HMI.
- Engineering range override. If the flow meter outputs 4-20 mA for 0-1500 m³/h instead of 0-1000, change only the SCALE_X MAX to 1500.0. The NORM_X constants remain 5530 and 27648 because the loop current range is unchanged.
- Negative reading interpretation. A scaled value < 0 indicates an underrange loop condition, not a valid reverse flow. Treat it as a fault unless the application specifically allows bidirectional measurement, in which case wire the transmitter to a different AI channel configured for ±20 mA or ±10 V and recalibrate.
- Symbolic addressing recommendation. For production code, prefer symbolic tags with a user-defined data block (DB) instead of MD/MW regions. This eliminates overlap traps by construction and improves HMI tag synchronization.
Cross-Platform Notes
- S7-1500 compatibility. The NORM_X / SCALE_X procedure is identical on S7-1500 CPUs. Use the same constants (5530, 27648).
- ET 200SP / ET 200MP. Distributed AI modules (e.g., 6ES7531-7KF00-0AB0) follow the same normalization rules. Confirm the channel configuration uses the standard 4-20 mA measuring range in TIA Portal.
- LOGO! 8 / S7-200. These platforms use scaled analog blocks (Analog Amplifier on LOGO!, library functions on S7-200) and do not use NORM_X/SCALE_X. The raw-to-engineering concept is the same.
- Third-party controllers. Allen-Bradley MicroLogix/CompactLogix use the SCP (Scale with Parameters) instruction; ControlLogix uses a similar instruction set. The principle of normalizing to a fractional real then scaling to engineering units is universal.
FAQ
What integer range does a 4-20 mA S7-1200 analog input produce?
The nominal range is 5530 to 27648 counts. 0 mA underrange is reported as values below 5530 down to -32768; overrange above 20 mA (up to ~22.81 mA) reports 27649 to 32511; full overflow is 32767.
Can I use a single MD for both the NORM_X output and SCALE_X input?
Yes — connecting the NORM_X OUT directly to the SCALE_X IN pin is the standard implementation. The intermediate variable does not need an explicit absolute address. Just ensure no other block writes to that MD region.
Why does my scaled value read negative when the transmitter is disconnected?
A 4-20 mA loop driven to 0 mA produces an underrange raw count below 5530. NORM_X clamps the lower bound to 0.0, but if your MIN constant is incorrectly set (e.g., 0 instead of 5530) the SCALE_X result will go negative. Set MIN to 5530.0 and use a separate diagnostics bit to flag the underrange condition.
Do I need to enable channel diagnostics on the SM 1234 to detect a wire break?
Yes. Without enabling "Wire break" in the device configuration, the AI returns 0 counts but does not raise a diagnostic interrupt. Enable the diagnostic and ensure OB82 is present so the HMI can display the fault banner.
What resolution can I expect from an SM 1234 AI channel?
The SM 1234 (6ES7234-4HE32-0XB0) specifies 13-bit resolution for the four analog inputs. Effective usable resolution after noise and calibration is approximately 12-13 bits. A moving-average filter over 4 to 16 samples in the PLC reduces visible jitter for the HMI display.
Can I use SCALE_X with negative engineering ranges for bidirectional flow?
Yes. Set SCALE_X MIN to a negative value (e.g., -1000.0) and MAX to +1000.0. The wiring must use a bidirectional AI channel configured for ±20 mA or ±10 V, and the NORM_X MIN/MAX constants must be the bipolar equivalents (-27648 / +27648). For unidirectional 4-20 mA hardware, a negative engineering range cannot produce a valid negative flow.