Resolving Inverted Siemens HMI Tank Level Display in TIA Portal
A water-treatment skid with a top-mounted, distance-measuring level sensor will report 0.256 m when the tank is full and a larger value when the tank is empty. If that raw distance is wired straight to an HMI tag labelled "Level", the operator sees the tank as "almost empty" at the moment it overflows. The fault is not the sensor and it is not the HMI hardware — it is a missing or incorrect linear scaling / inversion block between the analog input and the displayed engineering value. This reference walks through the root cause, the math, and the TIA Portal configuration for both SIMATIC Comfort Panels and SIMATIC Unified Comfort Panels, plus the equivalent on the S7-1200/S7-1500 PLC side.
1. Problem Definition
Observed behaviour on the HMI faceplate:
- Sensor in the tank, water at the top → tag reads
0.256 m→ bar/digital readout shows ~25 % full or "almost empty". - Sensor in the tank, water drained → tag reads the full stand-off distance → bar shows 100 % full.
- Trend curve goes downward while the tank is being filled.
Affected products in the typical water-treatment architecture:
| Component | Typical model / family | Role |
|---|---|---|
| Level sensor | Ultrasonic, radar (FMCW), or capacitive proximity mounted at the tank top | Outputs distance from face of sensor to water surface |
| Analog input module | SM 1231 (S7-1200), SM 531 (S7-1500), or ET 200SP AI 4xU/I 2-wire | Converts 4–20 mA / 0–10 V to integer 0–27648 |
| PLC | S7-1200 (CPU 1211C/1212C/1214C/1215C/1217C) or S7-1500 (CPU 1511-1 PN … CPU 1518-4 PN/DP) | Scaling / inversion in user program |
| HMI | Comfort Panel TP700 / KTP700 / TP1200 or Unified TP700 / TP1500 / TP2200 | Displays engineering value (0–100 % or 0–max level) |
2. Root Cause Analysis
A non-contact level sensor mounted at the top of a vessel measures the empty space above the water, not the water column itself. The raw output is therefore a distance that decreases as the level rises. Mapping that value directly to "Tank Level" is an inverted representation.
Three configurations can produce the symptom:
- No scaling at all — the raw integer from the AI is shown on the HMI as if it were the engineering value in metres.
- Scaling without inversion — the analog raw count has been linearly mapped to metres, but the linear equation preserves the original "distance from top" relationship rather than subtracting from a stand-off.
-
Correct HMI scaling, but mirrored bar direction — the numeric value is right, but the bar/indicator object is configured with
Process value 0%at the top of the range. This is rare on Siemens panels, but it is worth checking the "Display limits" / "Representation" block on the slider/bar object.
3. The Math: From Distance to Level
Let:
-
D= sensor reading (metres, distance from sensor face to water surface) -
Hmax= stand-off distance of the sensor face above the tank bottom (metres) -
L= true level in the tank (metres of water)
The simple linear transform is:
L = H_max - D
To express the same value as a percentage of the tank's usable range:
Level_% = 100 * (H_max - D) / H_max_useful
where H_max_useful is the distance from sensor face to the lowest valid measurement point (e.g. 5 cm above the bottom to avoid the sensor dead band).
3.1 Worked Example
Tank depth = 2.50 m. Sensor mounted so the face is 2.70 m above the floor (gives 0.20 m clearance from the rim). Reported D = 0.256 m when full:
L = 2.70 - 0.256 = 2.444 m (full)
Level_% = 100 * (2.70 - 0.256) / 2.50 = 97.76 %
For D = 2.60 m (empty, just above bottom blanking):
L = 2.70 - 2.60 = 0.10 m (low-level alarm point)
Level_% = 100 * (2.70 - 2.60) / 2.50 = 4.00 %
This is the engineering value the HMI must display.
4. Solution A — Scale on the PLC (S7-1200 / S7-1500)
Scaling on the controller is the recommended location because the same scaled value can then be reused for alarms, trending, interlocking, and historian logging without re-doing the math on every consumer.
4.1 Raw Analog Count → Engineering Units (TIA Portal V18 / V19 / V20)
For a 4–20 mA input on an SM 1231 / SM 531, Siemens uses a nominal range of 0–27648 counts. The unipolar scaling block "NORM_X" normalises the input to a 0.0–1.0 real, and "SCALE_X" de-normalises the linear function. The canonical recipe is in the Siemens FAQ How can analog values be scaled and normalized in STEP 7 (TIA Portal) for the SIMATIC S7-1200/S7-1500?.
// FB "LevelScale" — distance sensor 4..20 mA on IW96
// iRaw : INT 0..27648
// rDistMax_m : REAL full-scale distance, e.g. 2.70 m
// rDistMin_m : REAL zero-scale distance, e.g. 0.00 m
// returns : REAL level in metres (0 = empty, rDistMax_m = full)
#rNorm := NORM_X(MIN := 0, VALUE := #iRaw, MAX := 27648);
#rDist := SCALE_X(MIN := #rDistMin_m, VALUE := #rNorm, MAX := #rDistMax_m);
#rLevel := #rDistMax_m - #rDist; // invert
IF #rLevel < 0.0 THEN #rLevel := 0.0; END_IF;
IF #rLevel > #rDistMax_m THEN #rLevel := #rDistMax_m; END_IF;
Wire #rLevel to a data block tag, e.g. "Tank1"."Level_m" (REAL) and a parallel "Tank1"."Level_pct" (REAL 0–100) that the HMI binds to.
4.2 Handling Overflow / Open-Circuit (S7-1500)
On S7-1500, the AI module returns 32767 (overflow) or -32768 (wire-break on 4–20 mA) — see the SM 531 manual. Add a guard before NORM_X:
IF #iRaw > 27648 THEN // overflow / open circuit
#bError := TRUE;
#rLevel := 0.0;
RETURN;
END_IF;
5. Solution B — Scale on the HMI (Comfort Panels)
For a stand-alone HMI tag (e.g. an OPC UA connection straight to a Modbus gateway), scaling can be done in the tag's "Properties → Range" or via the "Linear Scaling" function in the HMI tag. Procedure for TIA Portal V18+ on a TP/KTP Comfort panel:
- In the project tree, expand PLC tags → Show all tags and select the HMI tag that carries the raw distance (or add an internal HMI tag pointing to it).
- Open Properties → Range.
- Toggle Linear scaling on.
- Enter:
PLC value range= 0 … 27648
Display value range= 2.70 … 0.00 (note: max at min — this is the inversion) - Bind the tag to the bar/IO field on the screen.
The bar object "Representation" should remain at 0 % = low, because the HMI now receives a value where 0 m = empty and 2.70 m = full.
6. Solution C — Scale on the HMI (Unified Comfort Panels)
Unified panels (TP700 Unified, TP1500 Unified, TP2200 Unified) use a different scaling object. The official procedure is in the TIA Portal help Applying linear scaling to a tag (RT Unified):
- Project tree → Runtime HMI tags → select the tag.
- In the inspector, open Properties → Value & Scaling.
- Enable Linear scaling.
- Set
PLC / source raw= 0 to 27648 (or the actual driver range). - Set
HMI scaled= 0.00 to tank depth, but place the raw-max pair at the scaled-min end of the mapping to invert. Siemens documents this as a "decreasing" linear function — both endpoints move independently, so entering0 → 2.70and27648 → 0.00is supported and is the correct configuration for an inverted distance sensor.
7. Scaling Tables and Parameter Mapping
| Layer | Block / Object | Raw range | Output range | Inversion |
|---|---|---|---|---|
| Analog input | SM 1231 / SM 531 channel 0 | 0–27648 counts (4–20 mA) | — | — |
| PLC program | NORM_X + SCALE_X | 0–27648 | 0.00–2.70 m (distance) | Subtract from 2.70 |
| PLC output tag | DB "Tank1"."Level_m" | REAL | 0.00–2.70 m (true level) | — |
| Comfort HMI tag | Linear scaling on tag | 0–27648 | 2.70–0.00 m (mirror) | Built into scaling dialog |
| Unified HMI tag | Linear scaling on tag | 0–27648 | 0.00–2.70 m + mirror pair | Built into scaling dialog |
| Screen object | Bar / slider / IO field | 0–100 % | — | Set low-value to 0 %, high-value to 100 % |
8. Verification
Apply any of the three solutions above, then run the following commissioning checks in order. Each one must pass before moving to the next.
- Tag inspection. In TIA Portal, go online with the HMI and the PLC, add a watch table on the HMI tag and on the PLC tag. With the tank empty, confirm the displayed value is near zero. With the tank full, confirm the value is at the maximum (e.g. 2.70 m or 100 %).
- Direction test. Open the manual fill valve, watch the value on the HMI for 30 s. The numeric value and the bar should both rise. Close the drain — they should both fall. If the bar moves opposite to the number, the bar object is mirrored, not the tag.
- Alarm thresholds. Set Low-low at 5 %, Low at 15 %, High at 90 %, High-high at 95 %. Trigger each alarm by lifting the actual level past the threshold and confirm the message text and colour are correct on the HMI. See SIMATIC HMI Comfort Panels Programming and Operating Manual for the alarm configuration procedure.
- Trend. Open the trend view for the level tag. A fill cycle should appear as a clean ramp upward, a drain as a ramp downward. Inverted trends indicate the PLC block is correct but the HMI tag has been re-scaled a second time.
- Power-cycle. Restart the panel and the PLC, confirm the value reads correctly before any I/O update — confirms the scale is in the user program / tag properties, not in a temporary online override.
9. Common Pitfalls and Field-Repairs
| Symptom | Likely cause | Correction |
|---|---|---|
| Bar moves down while the level rises; numeric value is correct | Bar/slider object is configured as "Representation inverted" or has min/max swapped | Untick the inversion on the screen object; verify min = 0 %, max = 100 % |
| Numeric value still in metres of distance after scaling | Linear scaling enabled twice (PLC + HMI) without subtraction | Pick one layer for inversion; remove the other |
| Reading jumps to a very large negative or 32767 | Wire break on 4–20 mA loop, or AI module not configured for the current type | Check wiring and the SM 1231/531 channel configuration (Measurement type = Current 4–20 mA) |
| Value drifts by tens of mm with the tank still | Sensor aimed at a stand-pipe, agitator, or foam | Re-aim the sensor; add a stilling tube per the sensor manual |
| HMI shows "0" constantly | Connection interrupted, or HMI tag is bound to a non-existent PLC tag | Check the HMI connection in Devices & Networks; verify the DB tag name |
| Display correct on TP700 but wrong on Unified client | Web client is binding a second, unscaled copy of the tag | Bind the screen to the unified runtime tag, not the internal IO field variable |
10. Sensor Selection and Cross-Reference
The most common sensor families that produce the symptom in this article (top-mount, distance output, 4–20 mA):
- Ultrasonic: Sitrans LU150 / LU240 (Siemens), Vega VEGA 60 / 61 / 62, Endress+Hauser Prosonic FMU30 / FMU90.
- Radar (FMCW): Sitrans LR560 (Siemens), Vega VEGAPULS 69, Endress+Hauser Micropilot FMR10 / FMR20.
- Capacitive: ifm LI5 / LK1 / LMT series, Balluff BCS series.
All of the above default to "distance from process connection to target" as the primary measured value. The factory setting for the 4–20 mA loop is typically scaled to the sensor's full measuring range (e.g. 0–4 m for a 4 m ultrasonic). The "empty calibration" point is the far end (4 mA at 0 m level) and the "full calibration" point is the near end (20 mA at the maximum level). The HMI must therefore invert relative to the analog current.
11. Summary Procedure
- Identify whether the sensor is top-mount distance or bottom-mount hydrostatic.
- If distance: pick the inversion location — PLC (recommended), Comfort HMI, or Unified HMI — using the recipes in sections 4, 5, 6.
- Wire the inverted engineering value to the HMI tag bound to the bar and the IO field.
- Run the five-step verification in section 8.
- Document the scaling in the panel's "Process values" comment field so the next engineer does not re-do the work.
My Siemens Comfort Panel shows the right number but the bar drops while filling — what is wrong?
The numeric tag is scaled correctly but the bar/slider object has its Representation set to "inverted" or its Process value 0% and 100% swapped. Untick any "invert" flag on the screen object and confirm the bar's min/max match the tag's min/max (e.g. 0 m empty, 2.70 m full).
I scaled the tag on the HMI and again on the PLC — value is now wrong again. Why?
You have inverted the signal twice. Pick one location — Siemens recommends the PLC using NORM_X + SCALE_X — and leave the HMI tag configured as a direct pass-through with no linear scaling.
Do I need to invert for a hydrostatic submersible level probe?
No. A hydrostatic probe mounted at the bottom of the tank outputs a signal that already rises with increasing level. Connect it directly to the AI channel and scale 4 mA → 0 m, 20 mA → tank depth. The bar will track the level without any math inversion.
Which TIA Portal versions support the linear-scaling dialog on Unified tags?
Linear scaling on Runtime HMI tags is available from TIA Portal V17 onward on Unified Comfort Panels running firmware V17.0.0.3 or later. For older panels, perform the scaling in the PLC instead.
My reading is 32767 (overflow) — is that the same bug?
No. 32767 from an S7-1500 AI is a wire-break or under/over-range flag, not an inversion. Check the loop wiring, the SM 1231/SM 531 channel's Measurement type setting, and add an overflow guard in the PLC code before the NORM_X call.