Programming Siemens S7-1200 SM 1232 Analog Output with TIA Portal

David Krause12 min read
SiemensTIA PortalTutorial / How-to
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

Programming Siemens S7-1200 SM 1232 Analog Output with TIA Portal

Overview

The Siemens SIMATIC S7-1200 PLC family supports analog output modules that drive field devices such as proportional valves, variable frequency drives, chart recorders, and 4-20 mA indicators. The standard analog output module is the SM 1232 AQ, available in 2-, 4-, and 8-channel variants with 14-bit or 16-bit resolution. This article covers the correct hardware configuration in TIA Portal, the integer-to-real scaling functions NORM_X and SCALE_X, and a common fault mode in which the HMI panel begins to display incorrect values when the analog scaling references a memory tag instead of a constant.

Module nomenclature check: The "SM 1223" referenced in the original question is a digital input/output module (16 DI / 16 DO) and contains no analog channels. For two analog outputs the correct order number is SM 1232 AQ 2x14 bit (6ES7232-4HB32-0XB0). Confirm the part number printed on the side of the module before proceeding.

Prerequisites

  • CPU 1215C (any firmware variant from V4.0 onward; firmware V4.2 or later recommended).
  • SM 1232 AQ 2x14 bit module (6ES7232-4HB32-0XB0) plugged immediately to the right of the CPU.
  • STEP 7 (TIA Portal) V15.1 or higher with the corresponding HSP (Hardware Support Package).
  • Engineering station with administrator rights to install the HSP for newer module revisions.
  • 24 V DC load supply present on the module's power terminals (required even for voltage outputs when the channel is configured for current).
  • Field device wired with loop resistance below 600 Ω.

Hardware Identification

Confirm the analog output module from the front label or the article number printed on the lower-right corner. The three most common AQ variants for the S7-1200 are listed below.

Module Order Number Channels Resolution Output Ranges
SM 1232 AQ 2x14 bit 6ES7232-4HB32-0XB0 2 14 bit +/-10 V, 0-10 V, 0-20 mA, 4-20 mA
SM 1232 AQ 4x14 bit 6ES7232-4HD32-0XB0 4 14 bit +/-10 V, 0-10 V, 0-20 mA, 4-20 mA
SM 1232 AQ 8x16 bit HS 6ES7232-5PA52-0XB0 8 16 bit +/-10 V, 0-10 V, 0-20 mA, 4-20 mA

For firmware compatibility see the S7-1200 Programmable Controller System Manual and the SM 1232 Analog Output Module Manual.

TIA Portal Device Configuration

After adding the SM 1232 to the device view, configure each channel as follows.

  1. Select the module in the device tree.
  2. Open Properties → Analog outputs.
  3. For each channel set:
    • Output type: "Current" or "Voltage" depending on the field wiring.
    • Output range: 4-20 mA for current-loop devices, 0-10 V or +/-10 V for voltage-driven devices.
    • Diagnostics: Enable "Wire break" (current only) and "Overflow / Underflow" interrupts if the application requires them.
  4. Set the channel start addresses in Properties → IO addresses. The default for AQ channel 0 on SM 1232 is QW64; channel 1 is QW66.
  5. Compile the hardware configuration and download to the CPU.

The module will reject output values outside its legal integer range and issue a diagnostic interrupt. The wiring diagram for a 2-wire current output is shown below.

S7-1200 SM 1232 Channel 0 - 4-20 mA Current Output Wiring SM 1232 Channel 0 V0 / I0+ Field device 4-20 mA load M0 / I0-

Integer Range and Resolution

The S7-1200 analog modules use a signed 16-bit integer representation. The numerical range and the corresponding real-world signal are fixed by the output range selected in the device configuration:

Output Range Integer Range Resolution Step Value
+/-10 V bipolar -27648 to +27648 14 bit + sign 0.7234 mV per LSB
0 - 10 V unipolar 0 to 27648 14 bit 0.3617 mV per LSB
0 - 20 mA 0 to 27648 14 bit 0.7234 uA per LSB
4 - 20 mA 0 to 27648 14 bit 0.5787 uA per LSB

Writing 27648 to the output word produces 20 mA; writing 0 produces 4 mA. Writing values above 27648 or any negative integer trips a diagnostic interrupt and the output is forced to 0 mA. Refer to chapter 11 of the S7-1200 System Manual for the full analog value table.

SCALE_X and NORM_X Theory

TIA Portal provides two functions in the Convert library under Basic Instructions → Converter:

  • NORM_X (Normalize): Scales a REAL input value to a 16-bit REAL range (0.0 to 1.0). Useful when preparing the value for SCALE_X.
  • SCALE_X (Scale): Scales a 16-bit REAL value (0.0 to 1.0) to an integer (INT, DINT, UINT) inside a defined output range.

For an analog output driven from an engineering unit (e.g. 4.0 to 20.0 mA), the canonical pattern is:


RealValueEU (REAL, e.g. 4.0..20.0)
  -> SCALE_X with engineering range 4.0..20.0, integer range 0..27648
  -> AQ output word (QW)

A direct SCALE_X call is shown in the table below.

Pin Direction Data Type Value in Example
MIN Input REAL 4.0
VALUE Input REAL 4.0 to 20.0 (operator setpoint)
MAX Input REAL 20.0
OUT Output INT 0 to 27648

For a symmetric bipolar output such as +/-10 V driving a positioner that operates from -100 % to +100 %, the engineering range becomes -100.0 to +100.0 and the integer range becomes -27648 to +27648.

Step-by-Step Program for 4-20 mA Output

  1. Create a new global data block (DB) named ProcessData and declare the following tags:
    • SetpointEU : REAL := 4.0; - operator entry in mA
    • OutputRaw : INT; - integer 0..27648
    • FaultWord : WORD; - optional diagnostics
  2. Open Main (OB1) and insert a SCALE_X block from the converter library.
  3. Wire the inputs as shown in the table above. For an analog output, the block output must be assigned directly to the peripheral output word, e.g. PQW64 for SM 1232 channel 0.
  4. Add a MOVE block to copy "ProcessData".OutputRaw to %QW64, or wire the SCALE_X output directly to %QW64.
  5. Compile and download the program to the CPU.

The complete ladder diagram is shown below.

SCALE_X MIN 4.0 VALUE EU MAX 20.0 SCALE_X QW64 (PAA)

For Structured Text (SCL) the equivalent code is:

"ProcessData".OutputRaw := REAL_TO_INT( SCALE_X(MIN := 0.0, VALUE := NORM_X(MIN := 4.0, VALUE := "ProcessData".SetpointEU, MAX := 20.0), MAX := 27648.0)); %QW64 := "ProcessData".OutputRaw;

The pattern follows the procedure documented in Siemens FAQ 61989691 and the destandardization example in FAQ 77376281.

Root Cause of the HMI "Working Wrong" Fault

The most likely root cause of the original symptom (HMI showing erratic values when the SCALE_X input is bound to %MD2) is a memory overlap. The S7-1200 operand area is byte-addressed, and an MD (memory double word) occupies four consecutive bytes:


%MD2  = bytes MB2..MB5  = words MW2 and MW4  = double-word MD2
%MW2  = bytes MB2..MB3  (overlaps the low word of %MD2)
%MW4  = bytes MB4..MB5  (overlaps the high word of %MD2)
%MD0  = bytes MB0..MB3  (overlaps with %MW2)

If any other code block, HMI tag, or cycle OB writes to %MW2, %MW4, %MB2..%MB5, the value the SCALE_X block reads will be corrupted every cycle. The HMI then appears to behave erratically because the displayed value and the value the SCALE_X block is reading no longer match.

A second common cause is data-type mismatch. The SCALE_X input "VALUE" expects REAL. If the operator entry on the HMI is bound directly to %MD2 with a wrong display format (for example INT instead of REAL), the raw bit pattern is interpreted as a floating-point number and the conversion produces garbage.

Engineering rule: On the S7-1200, an MD overlaps with two MWs and four MBs. Avoid binding SCALE_X inputs directly to absolute MD/MW/MB addresses when the same byte range is used by other logic or by HMI tags. Use a named DB tag instead, e.g. "ProcessData".SetpointEU.

A third possibility is endianness confusion. The S7-1200 is little-endian for the MD data type: the low word is stored at the lower byte address. If the SCALE_X block is bound to a DB tag of type WORD but the operator entry is DINT, the bytes are swapped and the SCALE_X output is wildly wrong. Always confirm the data type declared in the DB matches the symbol referenced in the program.

Verification and Diagnostics

After downloading the program, perform the following checks.

  1. Set the operator setpoint to 4.0. Verify with a multimeter in series that the output current is 4.000 mA +/-0.020 mA. Verify with an oscilloscope that no spike exceeds 50 mV ripple.
  2. Set the setpoint to 20.0. Verify 20.000 mA +/-0.020 mA. The output word should read 27648 in online view (TIA Portal → Online → Monitor).
  3. Set the setpoint to 12.0 (mid-scale). The output should read 13824 in the integer view and 12.000 mA in the loop.
  4. Force the output to 27649 (overflow). The SM 1232 should raise a diagnostic interrupt and the CPU diagnostic buffer will record the overflow. Clear the force and confirm recovery.
  5. Disconnect the field loop. With "Wire break" enabled the CPU's diagnostic buffer should record the open circuit.
  6. Online in TIA Portal, drag a watch table onto %QW64 and confirm the integer value tracks the SCALE_X output without jitter.

The diagnostic buffer entry text follows the pattern Analog output wire break on channel 0. The corresponding error code in the local diagnostics of the module is reported in the system data word. See chapter 12 of the S7-1200 System Manual for the full diagnostic data-word mapping.

Troubleshooting Matrix

Symptom Likely Cause Action
HMI shows correct value but field current is 0 mA Module not configured as 4-20 mA in device configuration Re-check output range in Properties → Analog outputs
HMI setpoint reads but SCALE_X output stays at 0 VALUE input not connected, or MIN == MAX Inspect online block I/O; ensure MIN < MAX
HMI value and SCALE_X value drift apart Memory overlap (%MD2 / %MW2 / %MB2) Replace absolute memory with DB tag
SCALE_X output shows 32767 even with valid input EN input not TRUE, or wrong block instance Check ENO; verify block is from converter library
Module reports "Overflow" in diagnostic buffer Integer above 27648 Clamp SCALE_X output with LIMIT block
Module reports "Wire break" Open current loop or no load Check field wiring, ensure load < 600 ohm
Output stuck at 4 mA even with setpoint 20 Load impedance too high, or 24 V missing Measure loop voltage; check M terminal
SCALE_X result negative when setpoint is positive MIN and MAX swapped Verify MIN=low engineering, MAX=high engineering
Output saturates below requested value Loop resistance > 600 ohm at 24 V Recalculate cable resistance, increase supply
Field device receives noisy / oscillating signal No shield on analog cable, or shared conduit with VFD Use shielded twisted pair, ground at one end

Edge Cases and Field-Commissioning Notes

  • Burst update under scan: The SM 1232 updates outputs synchronously with the OB1 cycle by default. For deterministic output behavior independent of OB1 time, configure the module to update on PTO or hardware interrupt in the device configuration.
  • Hot-swap and removal: The SM 1232 does not support hot-swap. Power down the CPU before inserting or removing the module.
  • Calibration: The module is factory calibrated. No user calibration is required. Field calibration of the loop is done at the transmitter or controller.
  • Loop load for 4-20 mA: The maximum loop resistance including cable is 600 ohm at 24 V supply. Above this the output saturates below the requested value.
  • Firmware compatibility: CPU firmware V4.0 supports SM 1232 modules up to article suffix 0XB0. For V2.0 of the SM 1232 (suffix 0XB0, 0XB1), CPU firmware V4.2 or later is required. Always cross-check with the S7-1200 system manual compatibility table.
  • HMI scaling: When the HMI displays the same setpoint that feeds SCALE_X, set the HMI tag scaling to "1 decimal place, range 4.0-20.0 mA" to avoid aliasing with the integer view.
  • PLCSIM simulation: PLCSIM supports the SM 1232, but the analog value is not converted to a real current. Use a software meter or watch table to confirm the integer range.
  • Multiple scan times: If the project uses different cycle OB priorities (e.g. OB35 at 100 ms, OB1 at 10 ms), write the AQ word from the highest-priority OB only to avoid last-writer-wins races.
  • Retain behavior: The AQ output word is forced to zero on CPU STOP. If the field device must hold its last value during STOP, use a retentive DB tag plus a watchdog block in OB100 to re-output the last valid value on STOP-to-RUN transition.
  • Engineering to physical unit: For non-electrical units (e.g. valve position 0-100 %), add a second SCALE_X in front to convert the engineering unit to 4.0-20.0 mA, then let the AQ SCALE_X convert to integer 0-27648.

Field-Validated Checklist

  • [ ] Module article number matches the slot in the device configuration.
  • [ ] Output range matches the field wiring (current vs. voltage, unipolar vs. bipolar).
  • [ ] Diagnostics enabled for wire break and overflow.
  • [ ] SCALE_X inputs use a DB tag, not an absolute MD/MW/MB address.
  • [ ] SCALE_X data types are consistent: REAL in/out, INT for the AQ word.
  • [ ] Mid-scale verification done with a calibrated multimeter (4.000, 12.000, 20.000 mA).
  • [ ] Diagnostic buffer cleared after commissioning.
  • [ ] Loop resistance measured below 600 ohm at the most remote device.
  • [ ] Shield grounded at one end only.
  • [ ] HMI tag bound to DB symbol with matching data type.

FAQ

Why does my SM 1223 module have no analog output?

SM 1223 is a digital input/output module (16 DI / 16 DO) and contains no analog channels. For two analog outputs the correct module is SM 1232 AQ 2x14 bit (article number 6ES7232-4HB32-0XB0). Re-check the part number printed on the module side label.

What integer value produces 4 mA on an SM 1232 configured for 4-20 mA?

The integer value 0 produces 4.000 mA and 27648 produces 20.000 mA. Writing any negative integer or any value above 27648 trips an overflow diagnostic interrupt and the output is clamped at 0 mA.

Can I write to the analog output directly from the HMI without using SCALE_X?

Yes, but the HMI must then send an integer 0-27648. To drive the output from an engineering unit such as 4.0-20.0 mA, SCALE_X (or NORM_X plus conversion) is required so that the PLC scales the value before the output word is written.

Why does SCALE_X give 0 when I bind the input to %MD2?

The most common cause is memory overlap. MD2 occupies bytes MB2 through MB5, so any write to %MW2 or %MW4 corrupts the value the SCALE_X block reads. Move the tag into a global data block and bind the SCALE_X input to the DB tag instead.

What is the maximum loop load for the SM 1232 in 4-20 mA mode?

The maximum loop resistance is 600 ohm at 24 V DC supply. Above this value the output saturates below the requested current and a wire-break diagnostic may appear if enabled.

What CPU firmware is required for SM 1232 AQ 2x14 bit?

CPU firmware V4.2 or later is recommended for the 6ES7232-4HB32-0XB0 module revision. Earlier firmware (V4.0, V4.1) supports earlier module revisions. Always verify against the compatibility table in the S7-1200 system manual.

Back to blog