Programming Siemens S7 Analog Inputs: FC105/FC106 with 4-20mA Level Control
Siemens SIMATIC S7-300 and S7-200 PLCs read 4-20 mA process signals from level, pressure, flow, and temperature transmitters as 16-bit integer counts in the process-image input word (PIW). The IEC 61131-3 standard library TI-S7 Converting Blocks supplied with STEP 7 V5.x exposes FC105 (SCALE) and FC106 (UNSCALE) to linearize that integer to engineering units (e.g., 0.0-100.0 % tank level) and back again for analog outputs. This technical reference walks through FC100, FC101, FC105, FC106 operation, raw-value mapping for 4-20 mA on SM331 (S7-300) and EM231 (S7-200), hardware configuration in STEP 7 Classic, and a complete LAD and FBD example that starts and stops a pump on high and low level setpoints with hysteresis.
Overview: When to Use FC100, FC101, FC105, and FC106
Siemens ships a fixed set of standard converting FBs/FCs in the STEP 7 Standard Library that bridge raw I/O counts and engineering units. The two most commonly called blocks are FC105 (read side) and FC106 (write side). FC100, FC101, FC102, and others handle less common or older conversion tasks.
| Block | Direction | Input type | Output type | Typical application |
|---|---|---|---|---|
| FC105 "SCALE" | Read (AI) | INT (0 to 27648 unipolar; -27648 to +27648 bipolar) | REAL engineering units | Convert AI raw value to process variable (e.g., 4-20 mA → 0-100 %) |
| FC106 "UNSCALE" | Write (AO) | REAL engineering units | INT (0 to 27648 unipolar; -27648 to +27648 bipolar) | Convert process variable to AO raw value (e.g., 0-100 % → 4-20 mA) |
| FC100 "SCALE" | Read (AI) | INT (0 to 27648) | REAL | Legacy predecessor to FC105; same math, older parameter names |
| FC101 "SCALE" | Read (AI) | INT (-27648 to +27648) | REAL | Legacy predecessor; bipolar input range only |
| FC250/FC251 | Legacy string | STRING | REAL | Not relevant to 4-20 mA I/O |
Prerequisites
- STEP 7 V5.5 SPx (Classic) or TIA Portal V13 SP1+ with S7-300 / S7-400 HSP support package installed (TIA V15.1 or later is recommended for current CPUs).
- S7-300 SM331 analog input module (typical catalog numbers: 6ES7331-7KF02-0AB0 for 8 AI 13-bit, 6ES7331-1KF02-0AB0 for 8 AI 12-bit, 6ES7331-7PF11-0AB0 for 8 AI 16-bit with HART).
- For S7-200: STEP 7 Micro/WIN V4.0 SPx with EM231 (6ES7231-0HC22-0XA0, 4 AI) or EM235 (6ES7235-0KD22-0XA0, 4 AI + 1 AO).
- A 4-20 mA two-wire or four-wire level transmitter (e.g., Siemens SITRANS Probe LU, Prosonic FMU, Endress+Hauser FMX21, or generic 24 V loop-powered unit) wired to AI channel 0.
- 24 VDC supply for the analog loop. SM331 does NOT supply loop power for 4-wire transmitters; for 2-wire transmitters set the SM331 measuring range to 2DMU or use the integrated 24 V on the front connector only if the SM331 variant supports it.
- Shielded twisted-pair cable for the analog run, grounded at the cabinet end only.
SM331 Module Selection Matrix
| Catalog number | AI channels | Resolution | Common ranges | Notes |
|---|---|---|---|---|
| 6ES7331-1KF02-0AB0 | 8 | 12-bit | ±10 V, 0-10 V, 0-20 mA, 4-20 mA, Pt100, Ni100, TC | Cheapest, 8 channels, single measuring-range module per group of 2 |
| 6ES7331-7KF02-0AB0 | 8 | 13-bit | ±10 V, 0-10 V, 0-20 mA, 4-20 mA, Pt100, Ni100, TC | Higher resolution; diagnostic per channel |
| 6ES7331-7PF11-0AB0 | 8 | 16-bit (15-bit + sign) | Same as 7KF02 + HART | HART passthrough; needed for HART transmitter diagnostics |
| 6ES7331-7NF10-0AB0 | 8 | 16-bit | 0/4-20 mA, ±20 mA, ±10 V, RTD/TC | Highest accuracy; supports ±20 mA and overflow diagnostics |
Raw Value Mapping: 4-20 mA on S7-300 SM331
SM331 modules configured for measuring range "4DMU" (4-wire current, 4-20 mA) deliver a 16-bit signed integer in the standard SIMATIC range. The same integer range applies to 0-20 mA and 0-10 V. Bipolar ranges (-10 to +10 V, -20 to +20 mA) use -27648 to +27648.
| Process current | Raw integer (decimal) | Hex | Status |
|---|---|---|---|
| ≤ 1.185 mA | -32768 | 8000H | Wire break / underrange (channel diagnostic) |
| 1.185 mA | -4864 | ED00H | Underrange nominal end (corresponds to 0 % - 5 %) |
| 4.000 mA | 0 | 0000H | 0 % engineering (zero) |
| 12.000 mA | 13824 | 3600H | 50 % engineering |
| 20.000 mA | 27648 | 6C00H | 100 % engineering (full scale) |
| 20.000 mA + 5 % | 29376 | 72C0H | Overrange (allowed transient) |
| ≥ 22.81 mA | 32767 | 7FFFH | Overrange (fault, S7 diagnostic buffer entry) |
The FC105 block automatically clips a -32768 input (wire break) to LO_LIM and returns RET_VAL = W#16#0000. The actual "wire break" condition must be read from the S7 diagnostic buffer (SFC51 / RD_REC) or from the SF LED on the SM331.
FC105 SCALE — Parameters and Math
FC105 is located in the STEP 7 Standard Library at Standard Library > TI-S7 Converting Blocks > FC105. Calling it in OB1 reads PIWxxx and returns a REAL in your configured engineering range.
| Parameter | Type | Direction | Description |
|---|---|---|---|
| EN | BOOL | IN | Enable input; only call the FC when EN = 1 to avoid CPU STOP on bad pointer. |
| IN | INT | IN | Raw input from PIWxxx (e.g., PIW288 for SM331 in slot 4). |
| HI_LIM | REAL | IN | Engineering value at IN = 27648 (e.g., 100.0 for 100 %). |
| LO_LIM | REAL | IN | Engineering value at IN = 0 (e.g., 0.0 for 0 %). |
| BIPOLAR | BOOL | IN | 1 = bipolar input range (-27648 to +27648); 0 = unipolar (0 to 27648). For 4-20 mA use 0. |
| RET_VAL | WORD | OUT | W#16#0000 on success; W#16#0008 if HI_LIM ≤ LO_LIM; W#16#0007 if IN is invalid (NaN or -32768 interpreted as wire break). |
| OUT | REAL | OUT | Scaled engineering value (e.g., 0.0 to 100.0 %). |
Math implemented by FC105:
OUT = LO_LIM + (IN / 27648.0) * (HI_LIM - LO_LIM) // unipolar (4-20 mA, 0-10 V)
OUT = LO_LIM + (IN / 27648.0) * (HI_LIM - LO_LIM) // bipolar (-10 to +10 V)
For 4-20 mA with HI_LIM = 100.0 and LO_LIM = 0.0, a raw value of 13824 (12 mA, half range) yields OUT = 50.0. The actual process current at any scaled OUT is recovered by Process_mA = 4.0 + (OUT / 100.0) * 16.0.
FC106 UNSCALE — Parameters and Math
FC106 is the mirror block used for analog outputs. The PLC writes PQWxxx to the SM332 module, which converts 0-27648 to 0-20 mA or 4-20 mA at the output.
| Parameter | Type | Direction | Description |
|---|---|---|---|
| EN | BOOL | IN | Enable input. |
| IN | REAL | IN | Engineering value to convert (e.g., 0.0 to 100.0 %). |
| HI_LIM | REAL | IN | Engineering value at output 27648. |
| LO_LIM | REAL | IN | Engineering value at output 0. |
| BIPOLAR | BOOL | IN | 1 = bipolar output; 0 = unipolar. |
| RET_VAL | WORD | OUT | W#16#0000 on success; W#16#0008 if HI_LIM ≤ LO_LIM. |
| OUT | INT | OUT | Raw output to PQWxxx (analog output word). |
OUT = (IN - LO_LIM) / (HI_LIM - LO_LIM) * 27648.0 // unipolar
Hardware Configuration in STEP 7 (Classic)
- Open the S7-300 station in SIMATIC Manager and double-click Hardware to launch HW Config.
- Insert your CPU (e.g., 6ES7315-2EH14-0AB0, CPU 315-2 PN/DP) in slot 2 and the SM331 (e.g., 6ES7331-7KF02-0AB0) in slot 4.
- Open SM331 properties. In the Addresses tab, confirm the input start address (slot 4, AI area → default 288 for the first 16 bytes, so channel 0 = PIW288, channel 1 = PIW290, ...).
- In the Inputs tab, set channels 0-7 to 4DMU (4-wire current, 4-20 mA). The setting is per-group: groups of 2 channels share a measuring range.
- Set Integration time to 20 ms (50 Hz mains rejection, used in Europe) or 16.67 ms (60 Hz rejection, used in North America). Default 60 ms works for most tank-level apps but adds update delay.
- Enable Diagnostics Interrupt if you need OB82 to catch wire break and overrange events.
- Save and compile (Station → Save and Compile). Download to the PLC.
LAD Example: Read 4-20 mA Level Transmitter and Start/Stop Pump
Hardware assumed: SM331 at slot 4 (start address 288). Pump output on Q0.0. High setpoint 80 % (start pump), low setpoint 20 % (stop pump). Manual Run-permit at I0.0, manual start at I0.1, manual stop at I0.2, thermal fault at I0.3.
Network 1 — Read and scale AI0 (4-20 mA level transmitter, 0-100 %):
PIW288
--|EN| |--[ FC105 SCALE ]--|EN| MD100 MW110
IN: PIW288
HI_LIM: 1.0e+02
LO_LIM: 0.0e+00
BIPOLAR: FALSE
RET_VAL: MW110
OUT -> MD100 (Level % REAL)
Network 2 — Set (start) pump on high level with Run permit and no fault:
MD100 80.0 I0.0 I0.3
==|----[ GE ]----80.0----+---[/]---+---[/]---+----(S)---- Q0.0
| (I0.0 | (I0.3
| Run | Thermal
| permit)| OK)
| |
Network 3 — Reset (stop) pump on low level:
MD100 20.0
==|----[ LE ]----20.0-----------------(R)---- Q0.0
Network 4 — Manual start (I0.1) and stop (I0.2) overrides:
I0.1 Q0.0 I0.3
--[ ]--+--(S)---- Q0.0 (I0.2 stop)--[/]--+--(R)---- Q0.0
Network 5 — Optional wire-break alarm from FC105 RET_VAL:
MW110 W#16#0007 M10.0
--[ == ]-----W#16#0007-----(S)---- M10.0 (Level_Tx_WireBreak_latch)
FBD Example: Same Application in Function Block Diagram
Network 1 — Scale input:
PIW288 ---| FC105 SCALE |---> MD100
HI_LIM = 100.0
LO_LIM = 0.0
BIPOLAR = 0
RET_VAL = MW110
Network 2 — Start pump on high level with Run permit and no fault:
MD100 --[ GE ]-- 80.0 --+-- I0.0 --[ AND ]-- I0.3 --[ AND ]--| S |--- Q0.0
(Run permit) (Thermal OK)
Network 3 — Stop pump on low level:
MD100 --[ LE ]-- 20.0 ---------------------| R |--- Q0.0
Network 4 — Manual start / stop and fault reset:
I0.1 --[ OR ]-- I0.2 --[ NOT ]--| S |--- Q0.0 (Manual start)
I0.2 ------------------------------| R |--- Q0.0 (Manual stop)
Complete Pump Control FB (Hysteresis + Fault Latching)
For a robust field implementation, package the level scaling, hysteresis, and fault latching in a single Function Block (FB100 "PUMP_CTRL") with instance DB100. This is the pattern that survives a long service life in a process plant.
FUNCTION_BLOCK FB100
VAR_INPUT
PIW_Level : INT; // PIW from SM331 (e.g., PIW288)
Sp_High : REAL; // Start setpoint (e.g., 80.0 %)
Sp_Low : REAL; // Stop setpoint (e.g., 20.0 %)
RunPermit : BOOL; // I0.0
ThermalOK : BOOL; // I0.3
ManualStart : BOOL; // I0.1
ManualStop : BOOL; // I0.2
END_VAR
VAR_OUTPUT
PumpRun : BOOL; // Q0.0
LevelPct : REAL; // 0.0 to 100.0 %
LevelmA : REAL; // 4.0 to 20.0 mA
WireBreak : BOOL; // DI from RET_VAL or PIW = -32768
END_VAR
VAR
FC105_RV : WORD; // RET_VAL from FC105
LevelPrev : REAL; // Edge-detection helper
END_VAR
BEGIN
// 1. Scale raw level
FC105(IN := PIW_Level,
HI_LIM := 100.0,
LO_LIM := 0.0,
BIPOLAR := FALSE,
RET_VAL := FC105_RV,
OUT := LevelPct);
// 2. Convert to mA for HMI display
LevelmA := 4.0 + (LevelPct / 100.0) * 16.0;
// 3. Wire-break detection (PIW = -32768 when open circuit)
IF PIW_Level = -32768 THEN
WireBreak := TRUE;
ELSE
WireBreak := FALSE;
END_IF;
// 4. Hysteresis pump control
IF (LevelPct >= Sp_High) AND RunPermit AND ThermalOK AND NOT WireBreak THEN
PumpRun := TRUE;
END_IF;
IF (LevelPct <= Sp_Low) OR NOT RunPermit OR NOT ThermalOK OR WireBreak THEN
PumpRun := FALSE;
END_IF;
// 5. Manual override
IF ManualStart AND RunPermit AND ThermalOK THEN
PumpRun := TRUE;
END_IF;
IF ManualStop THEN
PumpRun := FALSE;
END_IF;
END_FUNCTION_BLOCK
Call FB100 from OB1 with instance DB100. Drive Q0.0 from DB100.DBX0.0 directly. This pattern gives you a 60 % deadband (80 - 20) and prevents pump chattering at the threshold.
S7-200 Differences (EM231 / EM235)
The S7-200 family does NOT have FC105/FC106; the user must scale the raw integer manually because the EM231/EM235 raw count range differs from S7-300:
| Module | Input type | Raw count range | Resolution |
|---|---|---|---|
| EM231 (4 AI, 6ES7231-0HC22-0XA0) | 0-20 mA | 0 to 32000 | 5 µA / count (0.625 µA theoretical) |
| EM231 (4 AI, 6ES7231-0HC22-0XA0) | 4-20 mA | 0 to 32000 (offset 6400 = 4 mA) | 4 µA / count |
| EM235 (4 AI + 1 AO, 6ES7235-0KD22-0XA0) | 0-20 mA | 0 to 32000 | 5 µA / count |
| EM235 (4 AI + 1 AO, 6ES7235-0KD22-0XA0) | 4-20 mA | 0 to 32000 (offset 6400 = 4 mA) | 4 µA / count |
EM231 4-20 mA scaling ladder (STEP 7 Micro/WIN V4.0):
Network 1 — Subtract 6400 (4 mA offset)
AIW0 VW100 VW102
--[ SUB_I ]-- VW100, 6400, VW102 ; VW102 = raw - 6400
Network 2 — Convert to REAL
VW102 VD104 AC0
--[ MOV_R ]-- VD104, AC0 ; AC0 = (raw-6400) as REAL
Network 3 — Scale to 0.0-100.0 (multiply by 100.0/25600.0 = 0.00390625)
AC0 0.00390625 AC0
--[ MUL_R ]-- AC0, 0.00390625, AC0
Network 4 — Store result
AC0 VD108
--[ MOV_R ]-- AC0, VD108 ; VD108 = Level %
For S7-200 SMART (the modern replacement for S7-200, 6ES7288-...), the AI raw range follows S7-300 (0-27648) and the SCALE / NORM_X instructions are available in the Instruction tree. Use the same FC105-equivalent path as S7-1200.
S7-1200 / S7-1500 Alternative (TIA Portal)
For S7-1200/1500, FC105/FC106 are replaced by the box-style NORM_X and SCALE_X instructions in the Basic Instructions > Converter operations palette. NORM_X performs the integer-to-fraction (0.0-1.0) step; SCALE_X performs the fraction-to-engineering-range step. The pair is functionally identical to FC105, with the BIPOLAR parameter replaced by selecting the appropriate data type (INT for 0-27648 unipolar, INT for -27648 to +27648 bipolar). For complete analog input specifications on S7-1200 SM 1231, SM 1232, and SM 1234 modules, see the SIMATIC S7-1200 Programmable Controller System Manual — Analog Inputs (CPU 1212C / SM 1231 / SM 1234).
Verification & Commissioning
- Monitor PIW: Open Monitor/Modify in STEP 7. Apply a known current from a calibrator (Fluke 754, Beamex MC6, or similar). Confirm PIW reads 0 at 4.000 mA and 27648 at 20.000 mA (±1 LSB).
- Monitor scaled REAL: With calibrator at 12.000 mA, MD100 (FC105 OUT) should display 50.0 ±0.1 %.
- Wire break test: Disconnect the +ve loop wire at the transmitter. SM331 should drive PIW to -32768 (8000H), FC105 should clip OUT to LO_LIM (0.0), and the S7 diagnostic buffer should record "Channel 0: Wire break" with SF LED on the SM331. If wired to a non-Siemens HMI, the alarm word M10.0 (Network 5) latches.
- Setpoint sweep: Ramp the calibrator from 4 to 20 mA in 1 mA steps. Q0.0 (PumpRun) should set at 80 % (PIW = 22118) and reset at 20 % (PIW = 5529). The 60 % deadband should be observed.
- Fault test: Open the thermal contact (I0.3 = 0). Pump must stop within one OB1 cycle (typically 10-100 ms) regardless of level.
- HMI cross-check: Compare the HMI displayed % with the level transmitter's local display; typical agreement ±0.5 % of span.
Troubleshooting Matrix
| Symptom | Likely cause | Remedy |
|---|---|---|
| PIW = 0 regardless of input current | Wrong measuring range; SM331 jumper "D" not set | Set side selector to "D"; recompile HW Config and download |
| PIW = 32767 (overrange) | Wiring polarity reversed, or transmitter in current mode but module set for voltage | Swap I+ and I-; verify "4DMU" in software matches "D" on module |
| PIW = -32768 (wire break) | Loop open, fuse blown, or transmitter unpowered | Measure loop voltage at module; verify 24 V supply at transmitter; check shield ground |
| FC105 OUT stuck at LO_LIM even though PIW = 13824 | FC105 is being called with IN wired to the wrong PIW, or PIW type conflict | Verify PIW address in the call instance; check that you are passing a 16-bit INT, not a 32-bit MD |
| FC105 RET_VAL = W#16#0008 | HI_LIM ≤ LO_LIM (invalid range) | Reorder limits: HI_LIM > LO_LIM (e.g., 100.0, 0.0) |
| FC105 RET_VAL = W#16#0007 | IN is outside the unipolar/bipolar range (e.g., -32768 in unipolar mode) | Set BIPOLAR = TRUE if the input can be negative, or treat -32768 as wire break separately |
| Pump chatters at setpoint | No hysteresis on compare; level bouncing ±1 % | Use >= 80.0 to start and <= 19.5 to stop; build into FB100 |
| Reading jumps ±50 counts at constant current | No shielding, or AI integration time too short | Use shielded twisted pair grounded at cabinet end; in HW Config set AI integration time to 20 ms (50 Hz rejection) |
| CPU goes to STOP when calling FC105 | PIW address points outside the configured analog area | Check HW Config addresses; ensure SM331 is in a slot whose I area matches PIW |
| 4-20 mA reads -32768 only at certain temperatures | Loop resistance too high for the supply voltage (2-wire transmitter undervoltage) | Check transmitter datasheet for min supply; use 2-wire variant of SM331-7NF10 with HART power |
| S7-200 EM231 reading is half what it should be | DIP switches on the EM231 set wrong (must match 4-20 mA, not 0-20 mA) | Set SW1-SW6 on the EM231 to 4-20 mA configuration per datasheet |
Field-Commissioning Notes
- Set SM331 hardware integration time to 20 ms (50 Hz European mains) or 16.67 ms (60 Hz North America) for power-line noise rejection. In STEP 7 HW Config: SM331 → Inputs → Channel → Integration time. The default 60 ms is conservative but adds 40 ms update delay.
- For redundant level measurement (two transmitters in the same tank), build the scaling in FC105 on each PIW first, then use a HIGH_SELECT (FC37) or AVERAGE (FC36) function to combine. This preserves the raw value for diagnostics on each transmitter.
- Compare PIW as a signed INT. In LAD, comparing PIW directly to 27648 with == will raise a type clash. Always convert via FC105 to REAL, or use ITD (Integer-to-Double Integer, 32-bit) followed by DTR (Double Integer-to-REAL) before comparison.
- Loop-powered 2-wire transmitters need a separate 24 V supply or use the SM331-7NF10 / SM331-7PF11 "2-wire" (2DMU) configuration. 4-wire transmitters (separate 24 V + signal pair) work with the "4DMU" mode used in this article.
- Always wire the cable shield to the cabinet ground bar at one end only (the cabinet end). Ground loops from both-end grounding inject 50/60 Hz noise that pushes the reading 50-200 counts.
- For 4-20 mA signals on long runs (>100 m), increase the cable gauge from 0.75 mm² to 1.5 mm² to keep loop resistance below the transmitter's compliance voltage budget (typically 250 Ω at 24 V for a 2-wire unit = 12 V drop budget).
- On S7-200, the EM231 has DIP switches SW1-SW6 that MUST match the input range. For 4-20 mA on channel 0, set SW1=ON, SW2=OFF, SW3=ON, SW4=OFF, SW5=ON, SW6=OFF (per the 6ES7231-0HC22-0XA0 datasheet). Wrong DIP setting yields a reading that is always 0 or always 32767.
- For S7-300 firmware V3.x and later, the OB82 (diagnostic interrupt) is automatically inserted by STEP 7 if you enable SM331 diagnostic interrupts in HW Config. Use OB82 to latch a wire-break bit and force the pump off, independent of FC105's clipping.
What is the difference between FC100, FC101, and FC105 in STEP 7?
FC100 and FC101 are the original S7-300/400 scaling blocks; FC101 handles bipolar input ranges (-27648 to +27648) and FC100 handles unipolar (0 to 27648). FC105 is the modernized replacement with cleaner parameter names (BIPOLAR, RET_VAL) and identical scaling math covering both unipolar and bipolar via a single BOOL pin. For new code, always use FC105; FC100/FC101 are kept for compatibility with legacy STEP 7 projects.
What raw integer does a 4-20 mA signal produce on an S7-300 SM331?
For measuring range "4DMU" (4-wire current, 4-20 mA), 4.000 mA maps to raw 0, 12.000 mA to 13824, 20.000 mA to 27648. Below 1.185 mA the module returns -32768 (wire break, hex 8000H); above 22.81 mA it returns 32767 (overrange, hex 7FFFH). The same 0-27648 unipolar range applies to 0-20 mA and 0-10 V inputs on the same module.
How do I scale 4-20 mA on an S7-200 EM231 that does not have FC105?
EM231 in 4-20 mA mode uses raw counts 0-32000 with 4 mA = 6400 counts. Subtract 6400 in integer math (SUB_I), convert to REAL with MOV_R, then multiply by 100.0 / 25600.0 (or 0.00390625) to get percent. S7-200 SMART uses the same 0-27648 range as S7-300 and supports the SCALE / NORM_X instructions natively, so FC105-style scaling applies directly.
Why does FC105 always output LO_LIM even though the transmitter reads correctly on a multimeter?
FC105 clips the output to LO_LIM when the raw PIW is -32768 (wire break). Check the S7 diagnostic buffer for "Channel 0: Wire break" (readable via SFC51 / SFC59) or measure loop current at the SM331 terminals. If the multimeter reads 4-20 mA but PIW is -32768, the measuring-range module on the SM331 side is set incorrectly (e.g., selector on "A" for ±10 V but software on "4DMU"), or the input is configured for voltage but the transmitter is a current source.
What is the equivalent of FC105 in TIA Portal for S7-1200/1500?
Use the NORM_X (normalize integer to fraction 0.0-1.0) and SCALE_X (scale fraction to engineering range) box instructions from the Basic Instructions > Converter operations palette. They replace the FC105 + FC106 pair with explicit data type and range parameters and operate on INT, DINT, and REAL inputs. Refer to the SIMATIC S7-1200 manual collection for the S7-1200 SM 1231/SM 1234 raw value ranges and wiring details.