Summary
Set up and test the analog portion of a Siemens S7 PLC using a 0 to 20 mA current loopback test. This allows the programmer to quickly troubleshoot and verify correct operation of all loop components. Includes hardware setup and brief introduction to scaling.
This article is part of DigiKey’s Siemens PLC and Automation Resource Hub. Visit the hub for more technical briefs on Siemens components, applications, and programming.
At a Glance (Test Configuration)
- Siemens Gen 2 CPU 1214C (Figure 1)
- Analog plug-in module 6ES7 233-4HD50-0XB0.
- Environment: TIA Portal v20
- Circuit: Loopback from DAC AQ to ADC AI via 100 Ω resistors
- Simple scaling from raw binary to HMI-friendly float
Figure 1: Image of a Siemens S7 PLC with two plug-in modules.
Why is the PLC Analog loopback test important?
The analog loopback test allows us to verify the configuration of the PLC hardware and our ability to properly scale the analog values. This is the best way to learn PLC analog hardware and software as each step is immediately observable as green runtime or physical voltage.
When things don’t work, we troubleshoot this chain:
- The user enters a value on the HMI (e.g., 10 mA)
- The number is scaled to the appropriate S7 analog format (13,824 corresponds to 10 mA on a 0 to 20 mA scale)
- The DAC converts the value to a current (10 mA)
- Physical loop: we measure the voltage drop across the 100 Ω resistor (1 VDC)
- The current is read by the ADC (10 mA yields 13,824)
- The value is scaled and then displayed on the HMI (10 mA)
Steps to Activate the Analog Module
Setting up the Siemens S7 analog module is a multistep process:
Install the Module
Install the analog module following the Siemens instructions summarized as:
- Power down the PLC
- Remove the upper and lower doors
- Remove the blank cover modules – this takes some effort, but they will pop out
- Install the module (Figure 2)
- Reinstall the upper and lower doors
Figure 2: Installing a plug-in module into a Gen 2 Siemens S7 PLC.
Tech Tip: Protect your PLC by using a portable anti-static mat and wrist strap. It’s a small cost and inconvenience compared to the cost, time delay, and humility of wiping out a plug-in module or PLC on your production equipment.
Configure the Hardware
The analog module is configured as shown in Figure 3. Here, both input and output are set for 0 to 20 mA. The default filtering and noise reduction filters is used. Here are a few rules of thumb:
-
Set the scaling to the maximum anticipated input voltage or current. The plug-in module includes settings for 0 to 20 mA, 4 to 20 mA, +/- 2.5 VDC. +/- 5 VDC, and +/- 10 VDC.
-
Set the filtering as none (single cycle), weak (4 cycles) or strong (32 cycles).
-
Set the integration time knowing that strong filtering with long integration times can help reduce noise but may be inappropriate for fast-response sensors.
Figure 3: Input channel zero configuration for the PLC’s Analog module.
Add Tags for the Analog Variables
Tag names for physical I/O are assigned in the PLC tags section (Figure 4). The memory addresses are shown in Figure 5.
Figure 4: PLC tags used in the demo project.
Figure 5: Memory address for the Analog I/O.
Compile and the Download the Hardware Changes
Update the hardware by first compiling as shown in Figure 6. Then select “download to device” to apply the changes to the PLC.
Figure 6: Location of the PLC hardware compilation instruction in TIA Portal.
Tech Tip: I’ve tripped over the PLC hardware configuration more times than I’d like to admit. It’s easy to do as hardware configuration and software download are two different things in the Siemens world. I have a note to remind myself, “Step 0: configure the hardware.”
Wire the System
Figures 7 and 8 show the physical connections required for the loopback test. The 100 Ω resistors placement is shown in Figure 7 with the associated wire diagram as Figure 8.
- The resistors are technically not required. However, they are essential to the learning and troubleshooting process. Resistors allow us to observe the current as a voltage drop across a resistor.
Two resistors are used to highlight the fact that the analog input is not ground-referenced. We see this as an equal voltage drop across each resistor.
Figure 7: The AQ to AI analog loopback connections are made using 100 Ω resistors.
Figure 8: Wire diagram for the loopback test.
Program the PLC
The scaling operation is performed in Main [OB1].
-
Network 1: (Figure 9) takes a value from the HMI and sends it to the analog out pin.
-
Network 2: Accepts a value from the analog input and sends it to the HMI.
The code for the fMap operation is included as Listing 1. It was inspired by the Arduino map function described here. Additional functionality is included to hold the last value when not enabled. There is also an epsilon guard against tiny floating-point numbers.
Figure 9: Mapping operation for the Analog value.
(*
* FUNCTION_BLOCK: fMap (floating point mapping operation)
*
* DESCRIPTION:
* Linearly maps an input value from [rInMin, rInMax] to [rOutMin, rOutMax].
* Supports reversed ranges (negative slope) and allows extrapolation
* (values outside the input span map linearly beyond the output span).
* When xEnable = FALSE or when spans are invalid (|span| ≤ rEpsilon), the block
* holds the last valid output value.
*
* Note: Siemens ADC represents the full-scale range for current as 0 to 27,648 with voltage as -27,648 to 27,648.
* Ref: https://support.industry.siemens.com/cs/mdm/109741593?c=79989678731&lc=en-SE
*
* TODO:
*
* 1) Construct a complementary alarm unit with min max warnings and min max alarms.
*
* 2) Construct a complementary saturation block to limit the min and max values.
*
* 3) Consider alternatives to eliminate magic numbers e.g., 5530 as the lower number for a 4-20 mA sensor.
*
* INPUTS:
* #xEnable : FALSE → hold last valid output (no recompute)
* #rEpsilon : Small span guard, default as 1e-5 (REAL)
* #rIn : Input value (raw or pre-normalized)
* #rInMin : Lower input limit
* #rInMax : Upper input limit
* #rOutMin : Lower output limit
* #rOutMax : Upper output limit
*
* OUTPUTS:
* #rOut : Scaled output (or held value)
* #xScalingError : TRUE when spans are invalid (|span| ≤ rEpsilon)
*
* * Header written with assistance from GPT 5o.
*)
IF NOT #xEnable THEN
#rOut := #rLastOut;
RETURN;
END_IF;
#rInSpan := (#rInMax - #rInMin);
#rOutSpan := (#rOutMax - #rOutMin);
IF (ABS(#rInSpan) > #rEpsilon) // Only scale if the in and out spans are meaningful.
AND (ABS(#rOutSpan) > #rEpsilon) THEN
#rGain := #rOutSpan / #rInSpan;
#rOut := ((#rIn - #rInMin) * #rGain) + #rOutMin; // Linear y = mx + b calculation
#rLastOut := #rOut;
#xScalingError := FALSE;
ELSE
#rOut := #rLastOut;
#xScalingError := TRUE;
END_IF;
Listing 1: A floating point map scaling block is used to convert the percent duty cycle to the S7 Analog format.
Results
The results for the Figure 10 bench setup were straightforward:
-
The user was able to set the desired current on the HMI.
-
The current is measured as a voltage drop across the series resistor.
-
The return current was displayed on the display.
-
The calculated current (voltage drop across a fixed resistor) was within 10 mV of the system setpoint.
-
The HMI user set and returned voltages matched perfectly implying that the analog module uses the same voltage reference for both ADC and DAC.
In hindsight, the test would have been more accurate if 1% or even 0.1% tolerance resistors were used.
Figure 10: Author’s bench setup for the Siemens loopback test.
Parting Thoughts
The loopback test is an ideal way to familiarize yourself with the analog function of the PLC. Select the 0 to 20 mA setting as this allows cause-and-effect to be seen. Incorrect wiring or scaling errors are easy to identify.
Stay tuned as this analog module will be used in a PID application to control a thermal system.
Best wishes,
APDahlen
Related Articles by this Author
If you enjoyed this article, you may also find these related articles helpful:
- Getting Started with the Siemens ET 200SP Distributed I/O
- Getting Started with the Siemens Safety PLC
- Guide to Troubleshooting Industrial Control and Automation Equipment
About This Author
Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians.
Dahlen has returned to his Northern Minnesota home, completing a decades-long journey that began as a search for capacitors. Read his story here.









