S7-300 SM 334 4-20mA Configuration: Wiring and Scaling Method

David Krause14 min read
S7-300SiemensTechnical 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

Module Identification and Hardware Capabilities

The combination of CPU 315-2 PN/DP (6ES7 315-2EH14-0AB0) firmware V3.2 and SM 334 AI 4/AO 2 x 8 Bit (6ES7 334-0CE01-0AA0) on TIA Portal V16 Update 6 is a supported configuration, but the analog module has a constrained feature set that must be understood before searching for missing dialog options. The SM 334 8-bit variant is one of the lowest-cost S7-300 analog I/O modules and is intentionally limited in measurement type selection.

Property SM 334 AI 4/AO 2 x 8 Bit (6ES7 334-0CE01-0AA0)
Analog inputs 4
Analog outputs 2
Resolution 8 bits (256 steps)
Input ranges (voltage) 0 to 10 V
Input ranges (current) 0 to 20 mA (only)
Output ranges (voltage) 0 to 10 V
Output ranges (current) 0 to 20 mA (only)
4-20 mA mode Not selectable in software
Channel-to-channel isolation No (referenced to ground)
Configuration method Hardware wiring (no parameter dialog)
Module diagnostics None (no wire break, no over-range interrupt)
Conversion time per channel Approx. 5 ms typical
Critical constraint: The 8-bit SM 334 has no HW Config / device configuration property in TIA Portal for selecting 4-20 mA. The catalog entry is identical for 0-20 mA and 0-10 V; mode is selected by the physical connection at the front connector, and any 4-20 mA behavior must be implemented in user code.

The catalog view in TIA Portal lists the module under SM 334 and provides a single entry for the 8-bit version. There is no dropdown for "Measurement type" because the module is hard-wired to interpret the analog value as 0-20 mA or 0-10 V depending on which terminals are used. The module returns a raw integer in the range 0 to 255 (8-bit), and the live-zero scaling is the programmer's responsibility.

Why the 4-20 mA Option Is Missing in TIA Portal

The user-visible absence of a 4-20 mA selection in TIA Portal's device properties is the correct behavior, not a missing dialog. The 6ES7 334-0CE01-0AA0 module does not implement the "Measuring range" parameter object that is present on SM 331 modules. Only two input modes exist:

  1. Voltage mode (0-10 V): Selected by wiring the signal to the dedicated voltage input terminal pair (e.g., AI0+ terminal 1, AI0- terminal 2).
  2. Current mode (0-20 mA): Selected by wiring the signal to the dedicated current input terminal pair, which engages the internal burden resistor on that channel.

The module returns a raw integer in the range 0 to 255 (8-bit). The scaling to engineering units is the programmer's responsibility, which is the only way to obtain a 4-20 mA live-zero reading on this module. This is documented in the S7-300 module data manual; for the higher-resolution SM 331 family (which provides native 4-20 mA with diagnostics), refer to the S7-300 Isolated Analog Input Module SM 331 AI 8x16 Bit reference.

Hardware Wiring for Current Mode on SM 334

Pin assignment for the 6ES7 334-0CE01-0AA0 front connector (20-pin):

Pin Signal Function
1 AI0+ Analog input 0, positive (V or I)
2 AI0- Analog input 0, negative / return
3 AI1+ Analog input 1, positive
4 AI1- Analog input 1, negative / return
5 AI2+ Analog input 2, positive
6 AI2- Analog input 2, negative / return
7 AI3+ Analog input 3, positive
8 AI3- Analog input 3, negative / return
9, 10 COMP+/COMP- Compensation (unused on this variant)
11 S+ Sensor supply +24 V (not isolated)
12 S- Sensor supply 0 V (ground)
13, 14 AO0 V/I Analog output 0, voltage/current selector (wired at pin)
15 AO0+ Analog output 0, positive
16 AO0- Analog output 0, negative / return
17, 18 AO1 V/I Analog output 1, voltage/current selector
19 AO1+ Analog output 1, positive
20 AO1- Analog output 1, negative / return
Pin numbers above are representative of the 6ES7 334-0CE01-0AA0 wiring diagram in the S7-300 module data manual. Always cross-check against the printed label on the front connector of the physical unit before applying field power, as Siemens has shipped multiple sub-revisions of this part.

For current input on AI0 (4-20 mA sensor, e.g., a pressure transmitter):

  1. Connect the transmitter positive to pin 1 (AI0+).
  2. Connect the transmitter negative to pin 2 (AI0-). The internal burden resistor is already wired between the V-input pin and I-input pin of the same channel; selecting the I terminals engages the burden and protects against voltage on a current-configured channel.
  3. Confirm that the front connector shield bracket is bonded to cabinet ground at a single point.
  4. Do not apply more than 30 mA sustained current to a current-mode input — the internal burden is sized for 20 mA nominal and will saturate above this point.
4-20 mA Field Transmitter PT + (24V loop) - (return) SM 334 (6ES7 334-0CE01-0AA0) Pin 1 (AI0+) Pin 2 (AI0-) Burden R = 50Ω ADC 8-bit 0-20 mA raw

Configuring the Module in TIA Portal V16

Project setup procedure:

  1. Add the CPU 315-2 PN/DP (6ES7 315-2EH14-0AB0) V3.2 from the hardware catalog. If V3.2 is not listed, install the HSP (Hardware Support Package) for the CPU from the Siemens support portal.
  2. Slot 4: drag SM 334 AIO4/AO2 x 8 Bit from the catalog (order number 6ES7 334-0CE01-0AA0). Slot 4 is the default for the first SM after the CPU on S7-300.
  3. Open the device view, select the SM 334, and confirm the properties dialog. Note that the "Properties > Analog inputs" tab shows only the I/O addresses (e.g., PIW 752..759) and no measurement type field. This is expected.
  4. Compile the hardware configuration (HWCN) and download to the CPU.

Address mapping after compile:

Channel Input word Output word Raw range
AI0 / AO0 PIW 752 PQW 752 0..255
AI1 / AO1 PIW 754 PQW 754 0..255
AI2 PIW 756 — 0..255
AI3 PIW 758 — 0..255
Address offsets depend on the slot position and any other analog modules in the rack. After compilation, verify the addresses under Device view > SM 334 > Properties > I/O addresses. Do not hard-code PIW 752 in user code without confirming the compile output.

Scaling 4-20 mA over a 0-20 mA Raw Input

The SM 334 returns an integer proportional to the actual current, 0-20 mA mapped linearly to 0-255. For a 4-20 mA sensor, the live-zero at 4 mA corresponds to a raw value of approximately:

Raw@4mA = (4 / 20) × 255 = 51

Raw@20mA = 255

RangeSpan = 255 - 51 = 204

Engineering units conversion (scaled to a user range, e.g., 0-100% or 0-10 bar):

Eng = ((RawIn - 51) × (EngMax - EngMin)) / 204 + EngMin

SCL / Structured Text FB (TIA Portal):

FUNCTION_BLOCK "SCALE_4_20_to_ENG"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT
      i_raw : INT;        // PIW input, 0..255
      i_eng_min : REAL;   // engineering value at 4 mA
      i_eng_max : REAL;   // engineering value at 20 mA
   END_VAR
   VAR_OUTPUT
      o_eng : REAL;       // scaled engineering value
      o_below_4mA : BOOL; // wire break / sensor loss
      o_above_20mA : BOOL;// over-range
   END_VAR
   VAR CONSTANT
      RAW_AT_4MA : INT := 51;     // (4/20)*255 rounded down
      RAW_AT_20MA : INT := 255;
      RAW_SPAN : INT := 204;      // 255 - 51
   END_VAR
BEGIN
   IF i_raw < RAW_AT_4MA THEN
      o_below_4mA := TRUE;
   ELSE
      o_below_4mA := FALSE;
   END_IF;
   IF i_raw > RAW_AT_20MA THEN
      o_above_20mA := TRUE;
   ELSE
      o_above_20mA := FALSE;
   END_IF;
   o_eng := (INT_TO_REAL(i_raw - RAW_AT_4MA) /
             INT_TO_REAL(RAW_SPAN)) *
            (i_eng_max - i_eng_min) + i_eng_min;
END_FUNCTION_BLOCK

Ladder equivalent (TIA Portal LAD) — implement the offset and span manually:

  1. Read PIW into MW (e.g., MOVE PIW752 -> MW100).
  2. Subtract 51 to remove the live-zero: SUB_I 51, MW100 -> MW102. Use a conditional coil to clamp to 0 on under-range.
  3. Convert to REAL: DI_R MW102 -> MD104.
  4. Multiply by the engineering range: MUL_R (EngMax - EngMin), MD104 -> MD108.
  5. Divide by 204: DIV_R 204.0, MD108 -> MD112.
  6. Add EngMin offset: ADD_R EngMin, MD112 -> MD116.

Using NORM_X and SCALE_X (TIA Portal V14+):

// Normalize 4-20 mA raw to 0.0 .. 1.0
#norm := NORM_X(MIN := 51,           // raw at 4 mA
                VALUE := "DB_AI".i_raw,
                MAX := 255);         // raw at 20 mA
// Scale 0.0 .. 1.0 to engineering units
"DB_AI".o_eng := SCALE_X(MIN := "DB_AI".i_eng_min,
                          VALUE := #norm,
                          MAX := "DB_AI".i_eng_max);

The 4-20 mA loop integrity check is critical: with this 8-bit module, raw values < 51 indicate a wire break, an open loop, or a sensor that has lost loop power. Program the under-range bit o_below_4mA into the process tag list so the HMI can flag "sensor loss" rather than reading 0%.

Alternative Siemens Modules with Native 4-20 mA Support

If 4-20 mA support is required with built-in diagnostics, wire-break detection, and direct software parameterization, replace the SM 334 8-bit module with a higher-resolution variant or an SM 331 input module.

Module Order Number Resolution Native 4-20 mA Wire-Break Diagnostics Notes
SM 334 AI 4/AO 2 x 8 Bit 6ES7 334-0CE01-0AA0 8 bit No (scaling required) No Article subject
SM 334 AI 4/AO 2 x 12 Bit 6ES7 334-0KE00-0AB0 12 bit No (scaling required) No Higher resolution, same config-by-wiring
SM 331 AI 8 x 12 Bit 6ES7 331-1KF02-0AB0 12 bit Yes (per channel) Yes (in 4-20 mA mode) Classic workhorse; full HW Config
SM 331 AI 8 x 16 Bit 6ES7 331-7NF10-0AB0 16 bit Yes (per channel) Yes Isolated, high accuracy

When using the SM 331 AI 8 x 16 Bit, the manual explicitly states: "With the measuring range 4 to 20 mA and activated wire-break check, the isolated analog input module enters a wire break in the diagnostics if the process value falls below 1.185 mA (approx. 6% below 4 mA)." This is documented in the S7-300 Isolated Analog Input Module SM 331 manual (Siemens support portal).

Diagnostics, Wire-Break Detection, and Error Codes

The 6ES7 334-0CE01-0AA0 reports no module-level diagnostics. There is no SFC 51 / SZL index that surfaces a wire break or over-range status from this module. The only error visible to the user program is the raw input value itself:

Observed raw value (PIW) Equivalent mA Interpretation
0 0 mA Open loop, sensor unpowered, or current-mode wiring not selected
1..50 0.08..3.92 mA Sensor operating below 4 mA (fault or out-of-range)
51 4.00 mA Live-zero nominal
153 (mid-scale) 12.00 mA 50% of full scale
255 20.00 mA Full scale nominal
255 (saturated) > 20 mA (clamped by burden) Over-range, but indistinguishable from 20 mA on 8-bit ADC
Because the 8-bit ADC quantizes to 256 steps, the current resolution is approximately 0.078 mA per LSB (20 mA / 255). For 4-20 mA this means a step of about 1.6% of span per count — too coarse for precision transmitters. A 12-bit or 16-bit module is required if accuracy better than 1% is required.

If the application requires the 4-20 mA loop to be supervised for wire break, implement the alarm in user code by reading o_below_4mA from the FB block above and routing it to a process alarm OB. Because the SM 334 does not generate hardware interrupts, supervision must be done by cyclic OB1 polling (e.g., 100 ms). If a hard alarm is required, route the o_below_4mA bit to a digital output that energises a relay or an external alarm lamp.

Verification and Commissioning Procedure

  1. Apply 24 VDC to the sensor loop and confirm the transmitter output (use a calibrated mA source or a milliamp meter in series).
  2. Open an online watch table in TIA Portal with the PIW address (e.g., PIW 752). Force the transmitter to 4.000 mA. The raw value should read 51 ± 1 count. If it reads 0, the wiring is on the voltage terminals or the loop is open.
  3. Force the transmitter to 12.000 mA. Raw value should read approximately 153.
  4. Force the transmitter to 20.000 mA. Raw value should read 255.
  5. Force the transmitter to 0.000 mA (open loop test). Raw value should read 0. The SCALE block output should clamp to i_eng_min and o_below_4mA should latch TRUE.
  6. Capture the scaled engineering units (e.g., 0-100%) and verify linearity across at least five points: 4, 8, 12, 16, 20 mA.
  7. Document the linearity table in the commissioning report. Deviation greater than ±1 LSB per step on a healthy transmitter indicates wiring noise; route the cable in a separate conduit, away from VFD power conductors.

Troubleshooting Matrix

Symptom Root Cause Diagnostic Step Resolution
Raw value always 0 regardless of input current Wired to voltage terminals instead of current terminals; or loop not energised Measure mA at the terminal block; check pinout against SM 334 wiring label Re-wire to current input pair; verify 24 VDC loop supply
Raw value stuck at 255 Current > 20 mA (loop shorted, sensor malfunction) or input pin pair shorted Disconnect field wire and inject known mA Replace field transmitter; verify burden resistor is not bypassed
Raw value reads 51 with 4 mA input but floats ±5 counts Sensor noise pickup; long cable run; missing shield ground Check shield bonding; route signal away from VFD cables Tie shield at one end only; add 0.1 μF at terminal if not present
4-20 mA reading in HMI is 0-100% but reverses on wire swap Polarity reversed at terminal Measure with multimeter Swap AI+ and AI- conductors
Scaled engineering value drifts by ±2% of span 8-bit quantisation; the module cannot resolve finer than 0.078 mA Compare 5-point linearity test Upgrade to SM 331 AI 8 x 12 Bit (12-bit) or 16-bit variant
"Sensor loss" alarm never fires even with sensor disconnected Under-range test in user code not implemented Review SCALE block: o_below_4mA must be wired to alarm tag Implement the FB shown in the scaling section and route the bit to a process alarm
CPU goes to SF (System Fault) on analog module Module removed/failed; backplane issue Check diagnostic buffer in TIA Portal (Online > Diagnostics > Buffer) Re-seat module; verify 24 VDC backplane power supply; replace module if persistent
HMI shows 0% but PLC tag is 4 mA live PLC scaling not applied; raw integer directly mapped to HMI Inspect HMI tag connection and PLC tag scaling Insert the SCALE FB in the PLC and map the scaled REAL to the HMI tag

Field-Engineering Notes

  • The SM 334 AI 4/AO 2 x 8 Bit is one of the few S7-300 modules still shipped for cost-sensitive applications (HVAC, simple tank level, building automation). It is documented in the S7-300 Module Data manual under the SM 334 family.
  • If 4-20 mA is mandatory and budget permits, prefer the SM 331 AI 8 x 12 Bit (6ES7 331-1KF02-0AB0) — it provides per-channel measurement type selection in HW Config and a wire-break diagnostic in 4-20 mA mode.
  • For current outputs on the SM 334, the 0-20 mA range is also the only option. To drive a 4-20 mA valve, scale the output value to occupy the 51-255 raw range using the same procedure as the input block.
  • The module is not channel-isolated; use a 24 VDC isolated transducer or signal conditioner if the field device is grounded at a different potential than the S7-300 cabinet.
  • When replacing a faulty 6ES7 334-0CE01-0AA0 with a 6ES7 334-0KE00-0AB0 (12-bit version), recompile the HWCN and re-verify all scaling, since 12-bit raw values (0-4095) require a different scaling formula.
  • For TIA Portal V16 Update 6, the GSD/GSDML import and HSP installation are unchanged from earlier V16 updates; the SM 334 8-bit module ships in the standard catalog and requires no extra HSP.
  • If the application requires IEC 61131-3 structured text, the SCALE_4_20_to_ENG FB shown above can be invoked once per analog channel in OB1 (typical 100 ms cycle) or in a cyclic OB (e.g., OB35 at 100 ms).

FAQ

Why does TIA Portal V16 show no 4-20 mA option for my SM 334 (6ES7 334-0CE01-0AA0)?

The 8-bit SM 334 module does not expose a measurement-type parameter in HW Config. It accepts 0-20 mA only, and 4-20 mA live-zero is implemented by software scaling in the user program. The same catalog entry covers both voltage (0-10 V) and current (0-20 mA); the wiring terminals select the mode.

What is the raw integer returned by the SM 334 for a 4 mA input?

Approximately 51 counts, calculated as (4 / 20) × 255. With ±1 LSB noise, a healthy live-zero reads 50-52 counts at 4.000 mA. Values below 50 indicate a sensor problem or wiring error.

Can the SM 334 detect a 4-20 mA wire break?

No — the module has no diagnostics interrupt and no SZL entry. You must poll the raw input in the cyclic OB and generate the wire-break alarm in user code when the value is less than the live-zero threshold (about 51 raw counts for an 8-bit module).

Which S7-300 analog input module supports 4-20 mA natively with wire-break detection?

Use SM 331 AI 8 x 12 Bit (6ES7 331-1KF02-0AB0) for cost-effective native support, or SM 331 AI 8 x 16 Bit (6ES7 331-7NF10-0AB0) for high accuracy. Both allow per-channel 4-20 mA selection and built-in wire-break diagnostics in HW Config.

Do I need to use FC105 (SCALE) for 4-20 mA on the SM 334?

No. FC105 is a 0-20 mA / 0-10 V scaler for modules that return a 0-27648 integer (e.g., S7-300 12-bit modules). The SM 334 8-bit returns 0-255, so use the custom FB shown in the scaling section, or NORM_X and SCALE_X in TIA Portal V14+ with MIN=51 and MAX=255.

Back to blog