S7-1500: Application of Siemens PLC in Water Treatment Automation Systems

Hello, PLC enthusiasts! Today we will delve into the application of the Siemens S7-1500 PLC in water treatment automation systems. Imagine you are responsible for the automation upgrade of a city’s water treatment plant, needing to control various pumps, valves, and monitoring equipment—sounds challenging, right? Don’t worry, I’ll help you simplify these complexities!

System Overview and Hardware Preparation

The water treatment automation system may seem complex, but it essentially consists of a combination of sensors, actuators, and control logic. The core equipment we need includes:

  • S7-1500 PLC main unit (such as CPU 1515F-2 PN)

  • Digital input/output modules (for detecting water levels and controlling motors)

  • Analog input/output modules (for measuring pH, temperature, and other parameters)

  • HMI touchscreen (I recommend the TP1200 Comfort panel)

  • PROFINET network devices

A little tip when selecting hardware: don’t rush to buy the most expensive CPU! Choose a suitable model based on your IO point count and program complexity. For a small to medium-sized water plant, the 1515 CPU is usually sufficient and leaves you with a 30-40% performance margin.

Creating a TIA Portal Project

Open TIA Portal V16 (or higher), and let’s create a new project:

1. Click "Create New Project"
2. Enter the project name "WaterTreatmentSystem"
3. Choose your preferred folder path
4. Click "Create"

When adding devices, don’t make the mistake I did years ago—forgetting to select the correct CPU firmware version. This can lead to inexplicable compatibility issues during programming.

Hardware Configuration is the most fundamental step. Drag the CPU into the device view, then add various IO modules and communication modules. Remember to assign the correct addresses to each module!

1 Digital input: %I0.0 - %I3.7 (4 bytes)
2
3 Digital output: %Q0.0 - %Q1.7 (2 bytes)
4
5 Analog input: %IW64 - %IW72 (5 words)
6
7 Analog output: %QW64 - %QW68 (3 words)

Tip: When assigning addresses, leave some “wiggle room” for yourself; don’t fill them all up. Your future self will thank you when the system needs expansion!

Water Level Control Logic Programming

One of the core tasks of the water treatment system is to control the water levels in various tanks. We will use SCL language to implement a simple water level control:

1 // Water level control function block
2
3 FUNCTION_BLOCK "WaterLevelControl"
4
5 VAR_INPUT
6
7     actualLevel : REAL;    // Current water level, in meters
8
9     setPoint : REAL;       // Target water level, in meters
10
11     manualMode : BOOL;     // Manual mode switch
12
13 END_VAR
14
15 VAR_OUTPUT
16
17     pumpOn : BOOL;         // Water pump start signal
18
19     alarmHigh : BOOL;      // High water level alarm
20
21     alarmLow : BOOL;       // Low water level alarm
22
23 END_VAR
24
25 VAR
26
27     hysteresis : REAL := 0.1;  // Hysteresis value to avoid frequent pump starts and stops
28
29 END_VAR
30
31
32
33 BEGIN
34
35     // Alarm logic
36
37     IF actualLevel > setPoint + 0.5 THEN
38
39         alarmHigh := TRUE;
40
41         alarmLow := FALSE;
42
43     ELSIF actualLevel < setPoint - 0.5 THEN
44
45         alarmLow := TRUE;
46
47         alarmHigh := FALSE;
48
49     ELSE
50
51         alarmHigh := FALSE;
52
53         alarmLow := FALSE;
54
55     END_IF;
56
57
58
59     // Pump control logic (considering hysteresis to avoid frequent starts and stops)
60
61     IF NOT manualMode THEN
62
63         IF actualLevel < setPoint - hysteresis THEN
64
65             pumpOn := TRUE;
66
67         ELSIF actualLevel > setPoint + hysteresis THEN
68
69             pumpOn := FALSE;
70
71         END_IF;
72
73     END_IF;
74
75 END_FUNCTION_BLOCK

This code may look simple, but there’s a little wisdom behind it: I added a hysteresis value. Without it, the pump would stop as soon as the water level reached the set point, and start again with a slight drop, causing the pump to twitch like it had too much coffee! With hysteresis, the pump only changes state when the water level difference exceeds a certain range.

Analog Signal Processing Techniques

Water quality monitoring requires processing various analog signals, such as pH and turbidity. A common pitfall in analog processing is the conversion from raw values to engineering values.

1 // Analog value conversion function
2
3 FUNCTION "ScaleAnalogValue" : REAL
4
5 VAR_INPUT
6
7     rawValue : INT;         // Raw ADC value (0-27648)
8
9     engLow : REAL;          // Engineering unit lower limit
10
11     engHigh : REAL;         // Engineering unit upper limit
12
13 END_VAR
14
15 VAR
16
17     result : REAL;
18
19 END_VAR
20
21
22
23 BEGIN
24
25     // Considering possible over-range situations
26
27     IF rawValue <= 0 THEN
28
29         result := engLow;
30
31     ELSIF rawValue >= 27648 THEN
32
33         result := engHigh;
34
35     ELSE
36
37         // Linear proportional conversion
38
39         result := ((REAL_TO_REAL(rawValue) / 27648.0) * (engHigh - engLow)) + engLow;
40
41     END_IF;
42
43
44
45     RETURN result;
46
47 END_FUNCTION

Using this function is super simple: for example, if you have a 4-20mA pH sensor with a range of 0-14 pH, just call:

1 "Tank1_pH" := "ScaleAnalogValue"("pH_Raw_Value", 0.0, 14.0);

Remember when I first dealt with analog signals, I mistakenly wrote the full-scale value as 32767 (the maximum value of INT), resulting in all readings being too low. The standard full scale for Siemens is 27648, which is a strange number, but you need to remember it!

Data Logging and Trend Analysis

The water treatment system needs to log historical data for analysis. TIA Portal supports data logging functionality, allowing important parameters to be stored in a DataLog:

1 // Create hourly water quality records
2
3 "DataLogCreate_DB".CREATE := TRUE;
4
5 "DataLogCreate_DB".NAME := 'WaterQuality';
6
7 "DataLogCreate_DB".ID := "DataLogID";  // UDInt variable
8
9 "DataLogCreate_DB".HEADER := 'Timestamp,pH,Turbidity,Temperature';
10
11 "DataLogCreate_DB".FORMAT := 'CSV';
12
13 "DataLogCreate_DB".TIMESTAMP := 'DTL';
14
15 "DataLogCreate_DB".DELIMITER := ',';
16
17 "DataLogCreate_DB".SIZE := 2048;
18
19 "DataLogCreate_DB".RECORDS := 24;  // Save 24 hours of data
20
21 "DataLogCreate_DB".BUSY := "CreateBusy";
22
23 "DataLogCreate_DB".DONE := "CreateDone";
24
25 "DataLogCreate_DB".ERROR := "CreateError";
26
27 "DataLogCreate_DB".STATUS := "CreateStatus";

A little tip for data logging: don’t write too frequently, as it will shorten the lifespan of the PLC storage card. For water treatment processes that change relatively slowly, logging every 5-15 minutes is sufficient.

Visualization and Alarm Settings

HMI design is key to making operators love your system! We can create an intuitive water treatment system screen on the TP1200:

  1. Add HMI devices in the project tree

  2. Create a new screen named “MainOverview”

  3. Add graphical elements like tanks, pipes, and pumps

  4. Link variables with element properties (such as water level height, pump status)

Alarm configuration is also important:

1. Open HMI alarm configuration
2
2. Add analog alarms (e.g., pH value exceeding limits)
4
3. Add discrete alarms (e.g., pump failure)
6
4. Set alarm levels and acknowledgment options

Here’s a subtle but super useful tip: use different colors to distinguish different types of alarms. For example, red indicates serious issues that need immediate attention, yellow indicates warnings, and blue indicates informational prompts. This way, operators can quickly assess the severity of the situation at a glance.

Practical Application Exercise

Now that you have mastered the basics, let’s do a little exercise:

Design a simple water treatment system that includes:

  • 1 raw water tank (with water level control)

  • 1 dosing system (to control pH)

  • 1 clean water tank (with water level control)

  • Corresponding HMI screen

Try to implement these functions:

  1. Automatic water level control

  2. pH monitoring and adjustment

  3. Key data logging

  4. Operational status visualization

  5. Basic alarm functionality

Remember, programming is like learning to swim; you can’t learn without practice. Hands-on experience is the key! It’s normal to encounter problems while programming, so don’t get discouraged; debugging is part of the skill enhancement process.

Leave a Comment