Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It...

63
https://support.industry.siemens.com/cs/ww/en/view/109482830 Application Example 12/2016 SIMATIC Target 1500S: Calling Simulink® Models STEP 7, S7-1500 Software Controller, SIMATIC S7 1500 ODK

Transcript of Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It...

Page 1: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

https://support.industry.siemens.com/cs/ww/en/view/109482830

Application Example 12/2016

SIMATIC Target 1500S: Calling Simulink® Models STEP 7, S7-1500 Software Controller, SIMATIC S7 1500 ODK

Page 2: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

Warranty and Liability

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 2

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Warranty and Liability

Note The Application Examples are not binding and do not claim to be complete regarding the circuits shown, equipping and any eventuality. The Application Examples do not represent customer-specific solutions. They are only intended to provide support for typical applications. You are responsible for ensuring that the described products are correctly used. These Application Examples do not relieve you of the responsibility of safely and professionally using, installing, operating and servicing equipment. When using these Application Examples, you recognize that Siemens cannot be made liable for any damage/claims beyond the liability clause described. We reserve the right to make changes to these Application Examples at any time without prior notice. If there are any deviations between the recommendations provided in this Application Example and other Siemens publications – e.g. Catalogs – the contents of the other documents have priority.

We do not accept any liability for the information contained in this document. Any claims against us – based on whatever legal reason – resulting from the use of the examples, information, programs, engineering and performance data etc., described in this Application Example shall be excluded. Such an exclusion shall not apply in the case of mandatory liability, e.g. under the German Product Liability Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life, body or health, guarantee for the quality of a product, fraudulent concealment of a deficiency or breach of a condition which goes to the root of the contract (“wesentliche Vertragspflichten”). However, claims arising from a breach of a condition which goes to the root of the contract shall be limited to the foreseeable damage which is intrinsic to the contract, unless caused by intent or gross negligence or based on mandatory liability for injury of life, body or health. The above provisions do not imply a change of the burden of proof to your detriment.

It is not permissible to transfer or copy these Application Examples or excerpts of them without first having prior authorization from Siemens AG in writing.

Security informa-

tion

Siemens provides products and solutions with industrial security functions that support the secure operation of plants, systems, machines and networks.

To protect plants, systems, machines and networks against cyber threats, it is necessary to implement (and continuously maintain) a holistic, state-of-the-art industrial security concept. Products and solutions from Siemens are only one part of such a concept.

The customer is responsible for preventing unauthorized access to the customer’s plants, systems, machines and networks. Systems, machines and components should be connected to the company network or the Internet only if and to the extent necessary and if appropriate protective action (e.g., use of firewalls and network segmentation) was taken.

In addition, Siemens’ recommendations regarding appropriate protective action should be followed. For more information about industrial security, visit http://www.siemens.com/industrialsecurity.

Siemens’ products and solutions undergo continuous development to make them even more secure. Siemens strongly recommends to perform updates as they become available and use only the latest product versions. Using versions that are out of date or no longer supported can increase the risk of cyber threats.

To stay informed about product updates as they occur, subscribe to the Siemens Industrial Security RSS feed at http://www.siemens.com/industrialsecurity.

Page 3: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

Table of Contents

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 3

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Table of Contents Warranty and Liability ................................................................................................. 2

1 Introduction ........................................................................................................ 4

1.1 Overview............................................................................................... 4 1.2 Principle of operation ............................................................................ 6 1.2.1 Encoding with SIMATIC Target 1500S ................................................ 6 1.2.2 Overview of the overall solution ........................................................... 7 1.2.3 Simulink External mode ........................................................................ 9 1.2.4 Manipulating model parameters using STEP 7 .................................. 10 1.3 Components used .............................................................................. 11

2 Engineering ...................................................................................................... 12

2.1 Model simulation with Simulink .......................................................... 12 2.1.1 Temperature process ......................................................................... 12 2.1.2 PID controller ...................................................................................... 13 2.1.3 Complete control loop (PID controller and temperature process) ...... 16 2.1.4 Simulation of the complete control loop ............................................. 20 2.1.5 Preparations for External mode ......................................................... 21 2.2 Code generation with SIMATIC Target 1500S ................................... 22 2.2.1 Settings for code generation .............................................................. 22 2.2.2 Encoding with SIMATIC Target 1500S .............................................. 26 2.3 Hardware configuration ...................................................................... 28 2.3.1 Overview............................................................................................. 28 2.3.2 Hardware configuration with STEP 7 ................................................. 29 2.4 Creating the program and downloading it to the CPU ....................... 34 2.4.1 Overview............................................................................................. 34 2.4.2 Description of the generated function blocks ..................................... 35 2.4.3 Integrating the Simulink model into the S7 program .......................... 36 2.5 Loading the SO file to the web server ................................................ 43 2.6 Commissioning with STEP 7 .............................................................. 46 2.7 External mode .................................................................................... 48 2.7.1 Monitoring ........................................................................................... 48 2.7.2 Changing model parameters .............................................................. 50 2.8 Changing model parameters with STEP 7 ......................................... 52 2.8.1 Block for changing the model parameters.......................................... 52 2.8.2 Changing model parameters with the watch table in STEP 7 ............ 53 2.8.3 Permanently changing model parameters with the data block .......... 56

3 Valuable Information ....................................................................................... 60

4 Appendix .......................................................................................................... 62

4.1 Service and Support ........................................................................... 62 4.2 Links and literature ............................................................................. 63 4.3 Change documentation ...................................................................... 63

Page 4: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 4

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

1 Introduction

1.1 Overview

Requirement

In automation and control engineering, the MATLAB/Simulink software from MathWorks is frequently used to simulate processes and create algorithms. The requirement is to have the model, algorithm or function run on an ODK-capable CPU (SIMATIC S7-1500 Software Controller or CPU 1518 ODK) in just a few steps.

The MATLAB Coder and Simulink Coder add-on packages are used to compile the Simulink models to “C/C++” code.

This code can be integrated into the CPU via the Open Development Kit (ODK) interface.

In the CPU’s real-time environment, the code can be called and executed from the S7 program.

General task

Figure 1-1: Running the Simulink model on an S7-1500 Software Controller

2

1

1. Encode the Simulink model with the SIMATIC Target 1500S add-on and run it with the SIMATIC S7-1500 Software Controller.

2. Use Simulink External mode to monitor the model and change the parameters during operation.

Page 5: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 5

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Automation task

This application example shows you how to commission a Simulink model on the SIMATIC S7-1500 Software Controller. The automation task is a temperature control system with a simulated controlled system (temperature process).

Figure 1-2: Automation task: Temperature control system

SIMATIC IPC / Open Controller

SIMATIC S7-1500 Software Controller

Simulated

temperature process

Setpoint

Process

value

PID

outputPID

controller

For the application example, the PID controller is created using Simulink and ported to the S7-1500 Software Controller. The temperature process is simulated in the S7 program with the “LSim_PT3” function block from the “LSim” library.

Note For the “LSim” library, refer to the following entry: https://support.industry.siemens.com/cs/ww/en/view/79047707

Note The application example is deliberately kept simple to focus on the description of the use of SIMATIC Target 1500S.

Learning contents of this application example

The application example provides the following learning contents:

Simulate an example process and create the controller.

Learn how SIMATIC Target 1500S works.

Encode the Simulink model and port it to a SIMATIC S7-1500 Software Controller.

Learn how External mode with Simulink works.

Page 6: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 6

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

1.2 Principle of operation

1.2.1 Encoding with SIMATIC Target 1500S

The following figure shows the steps from creating the model in Simulink to commissioning on an S7-1500 Software Controller. Table 1-1 explains the steps in detail.

Figure 1-3: Encoding with SIMATIC Target 1500S

SIMATIC Target 1500S STEP 7MATLAB/Simulink

1 2

3

4

5

Web

Server

S7-1500

Software ControllerSO File

SCL Source

Table 1-1: Individual steps

Step Action Comment

1. Create model in Simulink.

The PID controller is created in this step.

2. Compile model with SIMATIC Target 1500S.

SCL blocks (sources) and SO file (shared object file / real-time function) are created.

3. Add SCL source in STEP 7 (TIA Portal).

Integration of the SCL blocks (sources) into the S7 program using the “External source files” function in the “Project tree”.

4. Download S7 program to S7-1500 Software Controller.

-

5. Load SO file to web server.

Upload of the SO file to the CPU’s web server using the “Filebrowser” function.

Page 7: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 7

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

During code generation with SIMATIC Target 1500S, the model’s original interfaces are applied. The SCL block has the same interfaces as the Simulink model.

The block is provided with additional parameters (EN, ENO and STATUS). The block is called via EN and ENO. The STATUS output outputs diagnostic information.

Figure 1-4: Simulink block and SCL block

Simulink block SCL block

1.2.2 Overview of the overall solution

This application example describes a temperature control system with the following structure:

A SIMATIC ET 200SP Open Controller is used as a runtime system.

The SO file is initialized in the Startup OB. The SO file is loaded to the work memory.

The temperature process is simulated in the S7 program with the “LSIM_PT3” function block.

The PID controller created in Simulink is encoded to an SO file using SIMATIC Target 1500S. The S7 program calls the SO file.

The entire temperature control system (PID controller and simulated process) is called in the cyclic OB with an interrupt time of 0.1 seconds.

Page 8: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 8

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Figure 1-5: Overview of the overall solution

SIMATIC ET 200SP Open Controller

SIMATIC S7-1500 Software Controller

S7 Program

Startup

FB (SCL source)

initialization

PID controller

Cyclic

Interrupt

ModelPIDOneStep

(PID controller)

Lsim_PT3

(simulated

process)

work

memory

web serverinitialize

call

SO file

SO file

load

Page 9: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 9

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

1.2.3 Simulink External mode

Simulink External mode allows you to monitor the model transferred to the CPU during operation and change parameters online.

To use External model, enable the “External mode” interface in the code generation settings before generating the code.

Figure 1-6: Running the Simulink model on the S7-1500 Software Controller

2

1

1. Monitor parameters

The Scope block in Simulink allows you to graphically display signals. In this case, these are the following three signals:

“setpoint” in yellow

“processValue” in red

“outPID” (manipulated variable) in blue

2. Change parameters

Simulink features blocks (here: “PIDController”) that have internal parameters, e.g. P, I, D. You can open the block’s screen form and change the parameter values during operation. The parameter change affects the simulation and you get a changed result.

Page 10: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 10

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

1.2.4 Manipulating model parameters using STEP 7

If you want to adjust the parameters to the process during operation, you can access the internal parameters in the Simulink model.

Optionally, you can create a global data block with the required parameters of the Simulink model. In the S7 program, you can use the global data block to manipulate the model parameters.

Note If you want to manipulate the model parameters using STEP 7, you have to check “Parameter access with STEP 7” before generating the code (see Chapter 2.8 Changing model parameters with STEP 7).

The following figure shows the internal parameters of the “PIDController” block from Simulink and the appropriate variables in STEP 7.

Figure 1-7: Model parameters in Simulink and STEP 7

Simulink

STEP 7

Page 11: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

1 Introduction

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 11

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

1.3 Components used

The application example was created with the following software components:

Table 1-2: Software components

Component Article number / note / link

(R2016a)

MATLAB V9.0

MATLAB Coder V3.1

Simulink V8.7

Simulink Coder V8.10

MathWorks Online Documentation:

http://www.mathworks.com/help/

STEP 7 V14 Professional

6ES7822-1..04-..

Manual: https://support.industry.siemens.com/cs/ww/en/view/109742272

SIMATIC S7-1500 ODK 1500S V2.0

6ES7806-2CD02-0YA0

Manual: https://support.industry.siemens.com/cs/ww/en/ps/13914/man

SIMATIC Target 1500S for Simulink V1.0

6ES7823-1BE00-0YA5

Manual: https://support.industry.siemens.com/cs/ww/en/ps/24443/man

The application example was created with the following hardware components:

Table 1-3: Hardware component

Component No. Article no. Note

SIMATIC ET 200SP Open Controller

CPU 1515SP PC 4GB (WES7-P, 64-bit)

1 6ES7677-2AA41-0FB0

-

SIMATIC S7-1500 CPU 150xS manual

https://support.industry.siemens.com/cs/ww/en/view/109249299

Manual: SIMATIC S7-1500 Software Controller Additional Information on CPU 1505S/CPU 1507S

https://support.industry.siemens.com/cs/ww/en/view/104943430

Manual: SIMATIC ET 200SP Open Controller CPU 1515SP PC

https://support.industry.siemens.com/cs/ww/en/view/109248384

Documentation and sample project

The following list contains all files and projects that are used in this application example.

Table 1-4: Sample files and projects

Component Note

109482830_Target_1500S_DOC_V10_en.pdf

This document

109482830_Target_1500S_PROJ_V10.zip

This zip file contains the sample project:

Simulink model

Encoded Target 1500S files

S7 program

Page 12: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 12

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2 Engineering

2.1 Model simulation with Simulink

This chapter describes how to create the model to be simulated with Simulink.

Alternatively, open the Simulink model called “ModelProcessPID.slx” from the sample project.

2.1.1 Temperature process

This application example simulates a temperature process. As a response to a step from 0 °C to 50 °C, the process aperiodically approaches the value 50 °C (see Figure 2-1).

The following figure shows the step response of the process depending on the time (s). The y-axis corresponds to the temperature (°C).

Figure 2-1: Step response of the temperature process

As a mathematical model, there is a continuous PT3 controlled system with the following formula:

15

1

110

1

110

1)(

ssssG

In Simulink, the process is simulated in the form of three PT1 functions connected in series.

Figure 2-2: Simulink model: Temperature process

tmLag1 = 10 tmLag2 = 10 tmLag3 = 5

Page 13: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 13

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.1.2 PID controller

Creating the model with the PID controller in Simulink

Table 2-1: Creating the Simulink model

Step Instruction

1. Open “MATLAB”.

2. In the “Workspace”, create a variable for the cycle time:

In the “Command Window”, enter “ts = 0.1” for 100 ms and press “Enter” to confirm.

3. Create a new model (“Blank Model”) using Simulink and save it under the name “ModelPID”.

4. In the toolbar, open the “Simulink Library Browser”.

Page 14: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 14

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

5. Insert the following blocks from the Simulink library into the subsystem:

Input ln1: “Simulink > Sources >In1”

Input In2: “Simulink > Sources >In2”

Output Out1: “Sink > Sources > Out1”

Add block: “Simulink > Math Operations > Sum”

PID controller: “Simulink > Discrete > Discrete PID Controller”

6. Double-click the block parameters of “Sum” and change the value of the “List of signs” parameter to “ |+- ”.

7. Then close the parameterization screen form.

8. Open the block parameters of “Discrete PID controller” and apply values in the below figure.

Note

“ts” (0.1 for 100 ms) is entered in “Sample time”. The controller and the process will later be called in the CPU in the “CyclicInterrupt” OB (cycle: 100 ms).

The PID values were determined empirically for this application example. A good response to setpoint changes with little overshoot is achieved with this parameterization.

Page 15: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 15

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

9. In the “PID Advanced” tab, set a PID output limit from 0.0 to 100.0.

10. Close the parameterization screen form.

11. Connect the blocks and name them as shown in the below figure.

12. Save and close the model.

Page 16: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 16

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.1.3 Complete control loop (PID controller and temperature process)

Table 2-2: Creating the complete control loop

Step Instruction

1. Create a new model (“Blank Model”) using Simulink and save it under the name “ModelProcessPID”.

2. In the toolbar, open “Model Explorer”.

3. Use “Add MATLAB Variable” to create three variables as shown in the below figure.

4. Close “Model Explorer”.

Page 17: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 17

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

5. In the toolbar, open the “Simulink Library Browser”.

6. Insert a “model” from the “Simulink > Ports & Subsystems” category into the model.

Assign the name “ModelPID”.

The model that has already been created is referenced by Simulink based on the model name.

7. Insert three blocks of the following type from the Simulink library into the Simulink model:

“Simulink > Continuous > Transfer Fcn”

8. One after the other, open the “Transfer Fcn” blocks.

9. Parameterize three “Transfer Fcn” blocks as shown in the below figure.

10. Close the parameterization screen forms.

11. Insert the following blocks:

“Simulink > Sources > Constant” for the setpoint

“Simulink > Sinks > Scope” to visualize the control loop

“Simulink > Signal Routing > Mux” to merge the signals

12. Double-click the “Mux” block and change the value of the “number of inputs” parameter to 3.

Close the parameterization screen form.

13. Double-click the “Constant” block and change the “Constant Value” to 50.

Close the parameterization screen form.

Page 18: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 18

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

14. Connect the complete control loop and name the blocks as shown in the below figure.

For “Simulation stop time”, select 150.

15. Double-click the “Scope” block.

In the menu bar, select “View > Configuration Properties …” and make the following settings.

16. Automatically open Scope at simulation start.

17. Displayed time span of y-axis: “Time span”

Time span overrun action: “Wrap”

Scale x-axis to time: “Show time-axis label”

Page 19: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 19

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

18. Chart title

Show legend and grid

Scale y-axis for “temperature value”

19. Close the model.

Page 20: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 20

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.1.4 Simulation of the complete control loop

Table 2-3: Simulation of the complete control loop

Step Instruction

1. Open the Simulink model called “ModelProcessPID.slx” from the sample project.

2. In the Simulink model toolbar, select the “Run” button to start the simulation.

3. The simulation starts. The result you get is the temperature curve of the complete control loop over time.

Page 21: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 21

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.1.5 Preparations for External mode

To allow you to monitor the PID controller running on the CPU, Simulink provides External mode. To graphically visualize the PID controller signals, you have to insert a “Scope” block.

In the sample project, these customizations have already been implemented.

Table 2-4: Preparations for External mode

Step Instruction

1. Open the “ModelPID” model.

2. In the toolbar, open the “Simulink Library Browser”.

3. Insert the following blocks from the Simulink library into the “ModelPID” model:

“Simulink > Signal Attributes > Signal Conversion”

“Simulink > Sinks > Scope”

“Simulink > Signal Routing > Mux”

4. Double-click the “Mux” block and change the value of the “number of inputs” parameter to 3.

Close the parameterization screen form.

5. Connect the model and name the blocks as shown in the below figure.

The black & white blocks of the “ModelPID” model are for graphical visualization of the signals only and do not influence the overall simulation.

6. Now the model can be encoded for the S7-1500 Software Controller and run (see Chapter 2.2 Code generation with SIMATIC Target 1500S).

Page 22: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 22

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.2 Code generation with SIMATIC Target 1500S

2.2.1 Settings for code generation

Table 2-5: Settings for code generation

Step Instruction

1. Open the “ModelPID” model.

2. In the menu bar, click “Code > C/C++ Code > Code Generation Options…”.

3. Navigate to “Code Generation”.

1. Select the “Browse...” button to open the Target selection window.

2. Select “Target_1500S_V1_0_grt.tlc”.

3. Select “Apply” to confirm your setting.

Page 23: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 23

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

4. Navigate to “Interface”.

1. In “Interface”, select the “External mode” setting. This setting enables External mode.

2. In “MEX-file arguments”, enter the IP address of the runtime system (here: Windows interface). For the application example, enter ‘192.168.1.1’.

Note

The IP address must be entered with single quotation marks ‘192.168.1.1’.

Page 24: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 24

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

5. Navigate to “Solver”.

1. In “Start time”, keep “0”.

2. Change “Stop time” to “inf”.

This ensures that External mode is used without a defined end.

3. In “Solver”, leave the default setting “auto (Automatic solver selection)”.

4. Navigate to “Optimization > Signals and Parameters”.

Set the “Default parameter behavior:” to “Tunable”.

After code generation, this setting allows you to access all internal parameters of the model with STEP 7 (TIA Portal).

Page 25: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 25

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

6. Navigate to “Target 1500S Options”.

1. Optionally, check “Copy all referenced files (MATLAB or C files) to ODK project”.

With this setting, SIMATIC Target 1500S generates an ODK project that you can edit with Eclipse and compile even without Simulink.

2. Check “Parameter access with STEP 7”.

This setting enables parameter access to the model parameters via the S7 program.

3. Make sure that the “Hardware Interface ID (HW-Identifier)” is correct.

This value must match the HW identifier set in the STEP 7 project (here: 59 Windows interface of the open controller).

4. Select “Apply” to confirm.

1

2

3

Note

The “Heap size for dynamic memory allocation in kByte” and “Max block size for dynamic memory allocation in Byte” parameters need to be changed only when there are problems with code generation.

For more information, please refer to the Target 1500S manual https://support.industry.siemens.com/cs/ww/en/ps/24443/man

and the SIMATIC S7-1500 ODK 1500S manual https://support.industry.siemens.com/cs/ww/en/ps/13914/man.

7. Select “OK” to close the dialog.

Page 26: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 26

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.2.2 Encoding with SIMATIC Target 1500S

Table 2-6: Code generation with Target 1500S

Step Instruction

1. Open the “ModelPID” model.

2. In the menu bar, click “Code > C/C++ Code > Build Model”.

Alternatively, you can also use the “Build Model” button.

3. During code generation, you cannot use Simulink.

SIMATIC Target 1500S compiles the “PIDController” block, including its input and output variables, to “C/C++” code.

Using the ODK Compiler of SIMATIC ODK 1500S, the SO file and the SCL source are then generated from this source code.

4. As soon as code generation has started, you can click the “View...” link in the status bar of the Simulink window.

Page 27: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 27

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

5. The “Diagnostic Viewer” opens.

Click the “outputs” link. This takes you directly to the store directory of the SO file and the SCL source.

6. The directory of the Simulink model, “…\ModelPID_Target_1500S_V1_0_grt_Output\outputs”, contains the generated files.

Page 28: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 28

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.3 Hardware configuration

2.3.1 Overview

By default, the S7-1500 Software Controller is preinstalled on the ET 200SP Open Controller. The following figure shows the hardware configuration of the application.

Figure 2-3: Hardware and network configuration

SIMATIC ET 200SP

Open Controller

IP: 192.168.1.100

IP: 192.168.0.1IP: 192.168.1.1

PG/PC

Use an Ethernet cable to connect the programmer (PG/PC) to the runtime system (SIMATIC ET 200SP Open Controller).

Make the following settings:

PG/PC interface:

– Ethernet (IP address: 192.168.1.100)

ET 200SP Open Controller:

– X2P1 Windows interface (IP address: 192.168.1.1)

– X1 CPU PROFINET interface (IP address: 192.168.0.1)

The subnet mask for all interfaces is 255.255.255.0.

Note For External mode, the correct HW identifier must be parameterized in the Target 1500S Options and in the S7 program (call of the “ModelPIDCallExtMode” FB). Each interface has its own HW identifier:

Interface HW identifier X2P1 Windows interface 59 X1 CPU PROFINET interface 64

You can read out the HW identifier in TIA Portal in each CPU in “PLC tags > Show all tags > System constants”.

Page 29: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 29

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.3.2 Hardware configuration with STEP 7

The following steps describe how to configure the hardware based on the SIMATIC ET 200SP Open Controller. Alternatively, you can also open the sample project.

Table 2-7: Hardware configuration with STEP 7

Step Instruction

1. Open TIA Portal and create a new project.

2. In the project tree, click “Add new device”.

In the dialog, select an ET 200SP Open Controller.

Click “OK”.

Page 30: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 30

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

3. Activate the web server for the PC system.

Acknowledge the security dialog.

4. Click the “CPU 1505SP” and check “Activate web server on this module”.

Acknowledge the security dialog.

Page 31: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 31

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

5. Navigate to “Web server > User management”.

In “Access level”, check all check boxes for full access.

If necessary, create a password.

Note

To load the SO file to the web server or delete it, the “read files” and “write/delete files” parameters must be checked. All other parameters are optional.

Page 32: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 32

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

6. Download the hardware configuration to the ET 200SP Open Controller.

In the project tree, select “PC-System_1”.

Click the “Download to Device” button.

7. Select “PN/IE”.

Select the Ethernet interface of your PG/PC.

Select “Direct at Slot ‘2 X2’”.

Click the “Start search” button.

Click “Load”.

Page 33: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 33

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

8. Confirm all the dialogs that follow until the download is complete.

Note When downloading the hardware configuration of the SIMATIC ET 200SP Open Controller for the first time, you must use the Windows interface (here: IP address 192.168.1.1).

Make sure that the IP address of the Windows interface matches the parameterization in TIA Portal.

Page 34: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 34

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.4 Creating the program and downloading it to the CPU

2.4.1 Overview

The following figure shows all the function blocks and PLC data types generated from the SCL source created by Target 1500S. Depending on the code generation settings, some blocks are optional.

External mode

Parameter access with STEP 7

The OBs (Startup and CyclicInterrupt) are created manually. As shown in the below figure, calling the FBs is recommended.

Figure 2-4: Simulink model in the S7 program

MATLAB

SimulinkS7 Program

Startup

CyclicInterrupt

ModelPID_Unload

ModelPIDOneStep

SO File

Target 1500S

ModelPIDCallExtMode*

ModelPIDExtModeInternal*

ModelPIDReadWriteParameters*

ModelPID_Load

ModelPIDExtModeStatus*ModelPIDParams*

SCL Source

* Optional blocks (depending on parameters in Target 1500S)

Page 35: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 35

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.4.2 Description of the generated function blocks

The following table describes all blocks that are generated from the SCL source.

Table 2-8: Explanation of the blocks

Generated block / PLC data type

Functional description

FB ModelPID_Unload

The block deletes the SO file from the CPU’s work memory.

FB ModelPID_Load

The block loads the SO file from the web server to the CPU’s work memory.

FB ModelPIDOneStep

The block calls the SO file. The interfaces correspond to the original Simulink model.

FB ModelPIDCallExtMode

(optional)

The block is called for using Simulink External mode.

PLC data type ModelPIDExtModeStatus (optional)

PLC data type of the “STATUS” output of the ModelPIDCallExtMode FB.

FB ModelPIDExtModeInternal

(optional)

The block includes internal functions for using Simulink External mode. This block is called in the ModelPIDCallExtMode FB and must not be called elsewhere in the S7 program.

FB ModelPIDReadWriteParameters

(optional)

The block is called for read/write of the model parameters to be manipulated.

PLC data type ModelPIDParams

(optional)

PLC data type of the “inOutParams” in/out parameter of the “ModelPIDReadWriteParameters” FB.

Page 36: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 36

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.4.3 Integrating the Simulink model into the S7 program

Importing the SCL source

Table 2-9: Importing the SCL source

Step Instruction

1. Use TIA Portal to open the S7 program with the hardware configuration you have already created.

2. In the “Project tree”, navigate to “External source files”.

3. Click “Add new external file”.

4. Select the generated SCL source, “ModelPID_ODK.scl”, and import the file to the S7 program.

5. 1. Right-click the “ModelPID_ODK.scl” file.

2. Click “Generate blocks from source” and confirm the dialog.

From the SCL source, TIA Portal generates the blocks created by Target 1500S.

6. In “Program blocks”, you will find the generated blocks.

Page 37: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 37

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

7. In “PLC data types”, you will find the generated PLC data types.

Page 38: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 38

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Creating OBs and the global DB

Table 2-10: Creating OBs and the global DB

Step Instruction

1. Add the following organization blocks to your S7 program:

OB: “Startup”

OB: “CyclicInterrupt” (with a cyclic interrupt time of 100 ms)

DB: “GlobalParameters”

Note

The cycle of the “CyclicInterrupt” OB must match the cycle of the “PIDController” in the Simulink model (here: 0.1 or 100 ms).

2. Open the “GlobalParameters” DB.

Add the following variables and structures:

setpoint [LReal]

process [LReal]

outPID [LReal]

statusModelPID [Word]

statusExternalMode [ModelPIDExtModeStatus]

paramAccess [Bool]

writeActive [Bool]

parameters [ModelPIDParams]

statusParameters [Word]

Page 39: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 39

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

“Startup” OB

Table 2-11: “Startup” OB

Step Instruction

1. Open the “Startup” OB.

2. Call the “ModelPID_Unload” FB in Network 1.

Interconnect the “REQ” input with “TRUE”.

3. Call the “ModelPID_Load” FB in Network 2.

Interconnect the “REQ” input with “TRUE”.

4. Close the OB.

Page 40: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 40

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

“CyclicInterrupt” OB

Table 2-12: “CyclicInterrupt” OB

Step Instruction

1. Open the “Libraries” task card.

Click the “Open global library” button.

Select the extracted LSim library and open it.

(Accept the upgrade if you are using a TIA Portal version that is more recent than the provided library.)

In the “LSIM_V1x” library, “Master copies”, you will find the “LSim_PT3” PT3 block.

Note

For the “LSim” library, please refer to the following entry: https://support.industry.siemens.com/cs/ww/en/view/79047707

2. Open the “CyclicInterrupt” OB.

Page 41: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 41

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

3. Drag the “LSim_PT3” FB from the integrated library to your project.

Call the “LSim_PT3” block in Network 1.

Interconnect the FB with the variables as shown in the below figure.

The block corresponds to the temperature process from the Simulink model.

Note

The “cycle” parameter must match the cycle of the “CyclicInterrupt” OB and the “PIDController” in the Simulink model (here: 0.1 or 100 ms).

4. Call the “ModelPIDOneStep” FB in Network 2.

Interconnect the FB with the variables as shown in the below figure.

5. Call the “ModelPIDCallExtMode” FB in Network 3.

Interconnect the “EnableExtMode” input with TRUE.

Interconnect the “HW-Identifier” input with 59.

Page 42: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 42

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

6. Call the “ModelPIDReadWriteParameters” block in Network 4.

Interconnect the variables as shown in the below figure.

After calling the block, reset the “GlobalParameters”.paramAccess and “GlobalParameter”.writeActive variables.

7. Before downloading the S7 program, load the SO file to the SIMATIC S7-1500 Software Controller’s web server (see next chapter).

Page 43: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 43

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.5 Loading the SO file to the web server

Requirement

You have downloaded the hardware configuration with the activated web server to the SIMATIC S7-1500 Software Controller (see Chapter 2.3 Hardware configuration).

In the “Windows firewall” setting of the open controller, “Inbound Rules”, you have allowed access via port 81.

Web server port

This example uses the Windows interface of the open controller for loading. To open the CPU’s web server via the Windows interface, you need the correct port (default: 81).

Table 2-13: Verifying the web server port

Step Instruction

1. Establish a remote connection to the open controller

(IP address in this application example: 192.168.1.1).

2. Open the CPU display of the CPU 1500S (icon on the desktop).

3. Double-click the “Settings” button.

4. Double-click the “Web server” subitem.

5. Make sure that the “HTTP port” value is correct (default: 81).

6. Close the remote connection.

Page 44: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 44

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Note For more information, please refer to the “SIMATIC S7-1500 CPU 150xS” manual, “Configuring the web server” and “Virus scanners and firewall”.

https://support.industry.siemens.com/cs/ww/en/view/109249299

Loading the SO file to the web server

Table 2-14: Web server port of the Windows interface

Step Instruction

1. Open any browser (Internet Explorer, Firefox, etc.).

2. Open the web page: http://192.168.1.1:81

The CPU web server home page opens.

3. Click “Enter”.

4. Navigate to “Filebrowser”.

5. Click the “ODK1500S” folder.

Page 45: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 45

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

6. Click the “Browse…” button.

7. Navigate to the “ModelPID_ODK.so” file created by Target 1500S.

The file is located in the “outputs” folder of the generated Target 1500S code.

8. Select the file and click “Open”.

9. Click the “Upload file” button.

10. Close the browser.

Note When you have loaded the SO file to the web server, restart the CPU.

Only the call of the “ModelPIDLoad” block in the “Startup” OB loads the SO file to the CPU’s work memory.

Page 46: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 46

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.6 Commissioning with STEP 7

Requirement

You have downloaded the hardware configuration with the activated web server to the SIMATIC S7-1500 Software Controller (see Chapter 2.3 Hardware configuration).

Programming the S7 program is complete (see Chapter 2.4 Creating the program and downloading it to the CPU).

You have loaded the SO file to the CPU’s web server (see Chapter 2.5 Loading the SO file to the web server).

S7 program download

Table 2-15: S7 program download

Step Instruction

1. Open TIA Portal.

2. Open your project or the sample project.

3. Select “Software PLC_1” and click the “Download to Device” button.

4. Select “Load” to confirm the dialog.

5. Select “Finish” to confirm the dialog.

6. Check “Start all”.

7. Select “Finish” to confirm the dialog.

Page 47: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 47

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Commissioning with the watch table

Table 2-16 Commissioning with the watch table

Step Instruction

1. Navigate to the “Watch and force tables” folder.

2. Create the “WatchTableModelPID” watch table as shown in the below figure.

3. Click the “Monitor” button.

4. 1. In the “Modify value” column, enter the value 50.0 for the “setpoint”.

2. Click the “Modify all selected values once and now” button.

By specifying the setpoint, the “ModelPIDOneStep” block with the called SO file modifies the process to the set value.

Page 48: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 48

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.7 External mode

Simulink External mode provides you with the option to monitor the model when the CPU is running and change model parameters online.

Note When using External mode, please follow the information provided in the Target 1500S manual. https://support.industry.siemens.com/cs/ww/en/ps/24443/man

Requirement

Before generation, you have configured External mode (see Chapter 2.2.1 Settings for code generation).

When calling the “ModelPIDCallExtMode” FB, you have interconnected the “EnableExtMode” input with “TRUE”.

You have loaded the SO file to the CPU’s web server (see Chapter 2.5 Loading the SO file to the web server).

You have downloaded the S7 program to the CPU (see Chapter 2.6 Commissioning with STEP 7).

You have set the CPU to “RUN”.

You have connected your PG/PC (MATLAB/Simulink) to the CPU via Ethernet (in this application example: OpenController – Windows interface).

In the “Windows firewall” setting of the open controller, “Inbound Rules”, you have allowed access via port 17725.

2.7.1 Monitoring

Table 2-17: Monitoring with External mode

Step Instruction

1. Open MATLAB.

2. Open the “ModelPID.slx” model.

3. Set the following values:

1. “Simulation stop time”: “inf”

2. “Simulation Mode”: “External”

1 2

Page 49: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 49

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

4. Click “Connect to target”.

5. To open the “Scope” window, double-click the “Scope” icon in the Simulink model.

Using the “WatchTableModelPID” watch table, you can change the “setpoint” in STEP 7 and monitor the chart in the “Scope” window.

If you change the setpoint from 0.0 to 50.0, you get the following signal chart.

6. Click “Disconnect from target” to disconnect the connection.

Page 50: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 50

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.7.2 Changing model parameters

Table 2-18: Changing model parameters with External mode

Step Instruction

1. Open MATLAB.

2. Open the “ModelPID.slx” model.

3. Use External mode to connect to the CPU.

4. Double-click the “PIDController” block to open the parameters.

5. 1. Navigate to “PID Advanced” and, as an example, change “Upper saturation limit” to 20.

2. Click “Apply”.

Page 51: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 51

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

6. The Scope window shows that “outPID” is limited to 20. The “process Value” aperiodically approaches the value.

7. Set “Upper saturation limit” back to 100 and select “Apply” to confirm.

Then the value is modified back to 50.

8. This procedure allows you to change any value in the model.

Note When you change parameter values using External mode, these changes are valid only until a restart of the CPU. After a restart, the original values are valid again.

If you want to permanently change the values, regenerate the blocks using Target 1500S. Reload the SO file to the web server. Restart the CPU.

If you change not only parameters but also the model and the interfaces of the block (here: “PIDController”), you have to reintegrate the SCL source into the S7 program.

Page 52: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 52

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.8 Changing model parameters with STEP 7

Requirement

Before generation, you have enabled parameter access with STEP 7 (see Chapter 2.2.1 Settings for code generation).

You have loaded the SO file to the CPU’s web server (see Chapter 2.5 Loading the SO file to the web server).

You have downloaded the S7 program to the CPU (see Chapter 2.6 Commissioning with STEP 7).

You have set the CPU to “RUN”.

You have connected your PG/PC (MATLAB/Simulink) to the hardware via Ethernet (in this application example: OpenController – Windows interface).

2.8.1 Block for changing the model parameters

During operation, the model parameters can be changed using the “ModePIDReadWriteParameters” block.

The parameters are transferred using the “inOutParams” in/out parameter.

Each time it is called, the block reads/writes the model parameters depending on the “write” input.

The block is called in the “CyclicInterrupt” OB.

The block is called with the “paramAccess” variable of the “GlobalParameters” DB.

After each call of the block, the “paramAccess” and “writeActivate” variables are reset in the “GlobalParameters” DB.

Figure 2-5: “ModePIDReadWriteParameters” block

Input parameters

Table 2-19: Input parameters

Parameter Data type Description

write BOOL To write the parameters from the S7 program to the Simulink model, set this value to TRUE. The values transferred at the “inOutParams” parameter are written to the Simulink model.

To read the parameters from the Simulink model, set this value to FALSE. The current values of the Simulink model parameters are written to the variable interconnected at “inOutParams”.

inOutParams PLC data type ModelPIDParams

With the “inOutParams” in/out parameter, you can transfer the Simulink model parameters for read/write.

Page 53: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 53

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Output parameters

Table 2-20: Output parameters

Parameter Data type Description

STATUS WORD This return value is automatically generated by ODK. When the execution is successful, the return value is 0.

2.8.2 Changing model parameters with the watch table in STEP 7

Table 2-21: Changing model parameters with the watch table in STEP 7

Step Instruction

1. Navigate to the “Watch and force tables” folder.

2. Open “WatchTableModelPID”.

3. Click the “Monitor” button.

Page 54: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 54

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

4. In the “Modify value” column, insert the following values:

1. “GlobalParameters”.paramAccess = TRUE

2. Click the “Modify all selected values once and now” button.

The model parameters are read from the SO file.

The “GlobalParameters”.paramAccess variable is automatically reset.

5. In the “Modify value” column, insert the following values:

1. “GlobalParameters”.paramAccess = TRUE

2. “GlobalParameters”.writeParameters = TRUE

3. “GlobalParameters”.parameters.PIDController_Upper… = 20.0

4. Click the “Modify all selected values once and now” button.

2

The value of the “GlobalParameters”.outPID parameter is reduced to the value 20.0.

Page 55: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 55

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

6. To obtain the original state, change the value of the “GlobalParameters”.parameters.PIDController_Upper… parameter back to 100.0.

Click the “Modify all selected values once and now” button.

Note When you change values of parameters using the watch table, these changes are valid only until a restart of the CPU. After a restart, the original values are valid again.

If you want to permanently change the values from the S7 program, change the parameter values directly in the data block (see next chapter).

Page 56: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 56

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

2.8.3 Permanently changing model parameters with the data block

To permanently keep the model parameters (even after a CPU restart), set the “Global”.paramAccess and “Global”.writeActive variables of the “GlobalParameters” DB in the “Startup” OB.

Customizing the program in the “Startup” OB

Table 2-22: Preparation in the “Startup” OB

Step Instruction

1. Open the “Startup” OB.

2. In Network 3, set the “Global”.paramAccess and “Global”.writeActive parameters.

3. Select the “Startup” OB and click the “Download to Device” button.

Modifying variables in the “GlobalParameters” DB

Table 2-23: Permanently changing model parameters in the data block

Step Instruction

1. Navigate to “Program blocks” and open the “GlobalParameters” DB.

2. Expand the “parameters” variable.

Page 57: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 57

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

3. Click the “Monitor all” button.

4. Read out the current model parameters.

1. Right-click “Monitor value” of the “paramAccess” variable.

2. Click “Modify operand…”.

5. In the dialog, enter 1 and select “OK” to confirm.

6. Change the monitor value of “PIDController_Upp..” to 20.0.

7. Click the “Snapshot of the actual values” button.

Page 58: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 58

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Step Instruction

8. Click the “All values” button and confirm the dialog to copy the instantaneous values to the start values.

Now all instantaneous values have been stored in the DB as start values.

9. Only the start values for the “parameters” model parameters are to be saved.

Delete the start values in all other variables.

10. Select the “GlobalParameters” DB and click the “Download to Device” button.

11. Restart the CPU.

Page 59: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

2 Engineering

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 59

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Result:

The “ModelPIDReadWriteParameters” block is called once each time the CPU is restarted.

– The “GlobalParameters”.paramAccess and “GlobalParameters”.writeActive variables are set in the “Startup” OB.

– The variables are reset after calling the “ModelPIDReadWriteParameters” FB in the “CylicInterrrupt” OB.

With each restart, all model parameters are set with the saved values from the “GlobalParameters”.parameters variable.

Page 60: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

3 Valuable Information

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 60

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

3 Valuable Information

SIEMENS

STEP 7 (TIA Portal)

STEP 7 is the development environment for programming and commissioning SIMATIC programmable logic controllers.

http://w3.siemens.com/mcms/simatic-controller-software/en/Pages/programming-software.aspx

SIMATIC S7-1500 Software Controller

The SIMATIC S7-1500 Software Controller is a CPU for PC-based automation solutions on SIMATIC IPCs.

http://w3.siemens.com/mcms/programmable-logic-controller/en/software-controller/Pages/Default.aspx

SIMATIC 1500S ODK

The SIMATIC 1500S Open Development Kit (ODK) add-on allows you to extend the CPU functionality by user-specific C/C++ programs as a Windows or real-time function.

http://w3.siemens.com/mcms/programmable-logic-controller/en/software-controller/s7-1500-software-controller-odk/Pages/Default.aspx

SIMATIC Target 1500S

With SIMATIC Target 1500S, Simulink models can be encoded and run on SIMATIC CPUs (SIMATIC S7-1500 Software Controller and S7-1518 ODK).

http://www.industry.siemens.com/topics/global/en/tia-portal/controller-sw-tia-portal/simatic-step7-tia-portal-options/target-1500s-for-simulink/Pages/Default.aspx

MathWorks

MATLAB and Simulink are registered trademarks of MathWorks, Inc.

MATLAB

Program for solving mathematical problems and graphically visualizing the results. In MATLAB, a proprietary programming language is used for programming.

https://www.mathworks.com/products/matlab.html

MATLAB Coder

Add-on to MATLAB for generating “C/C++” code from the proprietary MATLAB programming language. MATLAB Coder requires that the MATLAB basic package be installed.

https://www.mathworks.com/products/matlab-coder.html

Page 61: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

3 Valuable Information

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 61

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

Simulink

Add-on to MATLAB for graphical programming and simulations of models. Simulink offers a comprehensive library with functions, for example, for creating control engineering applications. Simulink requires that the MATLAB basic package be installed.

https://www.mathworks.com/products/simulink.html

Simulink Coder

Add-on to Simulink for generating “C/C++” code from Simulink models. Simulink Coder requires that MATLAB, MATLAB Coder and Simulink be installed.

https://www.mathworks.com/products/simulink-coder.html

Page 62: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

4 Appendix

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 62

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

4 Appendix

4.1 Service and Support

Industry Online Support

Do you have any questions or do you need support?

With Industry Online Support, our complete service and support know-how and services are available to you 24/7.

Industry Online Support is the place to go to for information about our products, solutions and services.

Product Information, Manuals, Downloads, FAQs and Application Examples – all the information can be accessed with just a few clicks: https://support.industry.siemens.com/ .

Technical Support

Siemens Industry’s Technical Support offers you fast and competent support for any technical queries you may have, including numerous tailor-made offerings ranging from basic support to custom support contracts.

You can use the web form below to send queries to Technical Support: www.siemens.com/industry/supportrequest.

Service offer

Our service offer includes the following services:

Product Training

Plant Data Services

Spare Part Services

Repair Services

Field & Maintenance Services

Retrofit & Modernization Services

Service Programs & Agreements

For detailed information about our service offer, please refer to the Service Catalog: https://support.industry.siemens.com/cs/sc

Industry Online Support app

The “Siemens Industry Online Support” app provides you with optimum support while on the go. The app is available for Apple iOS, Android and Windows Phone. https://support.industry.siemens.com/cs/sc/2067

Page 63: Application Example 12/2016 SIMATIC Target 1500S: … · Application Example 12/2016 SIMATIC ... It is not permissible to transfer or copy ... The temperature process is simulated

4 Appendix

SIMATIC Target 1500S Entry ID: 109482830, V1.0, 12/2016 63

S

iem

en

s A

G 2

01

6 A

ll ri

gh

ts r

ese

rve

d

4.2 Links and literature

Table 4-1: Links

No. Topic

\1\ Siemens Industry Online Support

https://support.industry.siemens.com

\2\ This entry https://support.industry.siemens.com/cs/ww/en/view/109482830

\3\ Manual: STEP 7 V14 Professional https://support.industry.siemens.com/cs/ww/en/view/109742272

\4\ Manual: SIMATIC S7-1500 ODK 1500S

https://support.industry.siemens.com/cs/ww/en/ps/13914/man

\5\ Target 1500S manual https://support.industry.siemens.com/cs/ww/en/ps/24443/man

\6\ SIMATIC S7-1500 CPU 150xS manual

https://support.industry.siemens.com/cs/ww/en/view/109249299

\7\ Manual: SIMATIC S7-1500 Software Controller Additional Information on CPU 1505S/CPU 1507S

https://support.industry.siemens.com/cs/ww/en/view/104943430

\8\ Manual: SIMATIC ET 200SP Open Controller CPU 1515SP PC

https://support.industry.siemens.com/cs/ww/en/view/109248384

\9\ Application Example: Closed-Loop Control of Simulated Controlled Systems in the S7-1500

https://support.industry.siemens.com/cs/ww/en/view/79047707

\10\ MathWorks Online Documentation:

http://www.mathworks.com/help/

4.3 Change documentation

Table 4-2: Change documentation

Version Date Modifications

V1.0 12/2016 First version