0% found this document useful (0 votes)
25 views77 pages

Programming Recommendation 081021

Uploaded by

Dang Hoang Sinh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views77 pages

Programming Recommendation 081021

Uploaded by

Dang Hoang Sinh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Programming recommendations for

SIMATIC S7
Advanced Workshop

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


S7-1500 with TIA Portal : Objective and consequence

Objective for S7-1500 and S7-1200 LAD/FBD


▪ Increase of performance
▪ Effective instruction set for all languages SCL
▪ Symbolic programming
▪ Data handling without absolute access with ANY Pointer
▪ Multiple use of program code
▪ Consequence OS
▪ Optimized program blocks GRAPH
▪ STL is no longer the root of LAD and FBD
▪ Each language compile direct to the operating system
▪ Data handling done symbolic with ARRAY index STL
▪ Using multi-instances
OS : Operating system
Program blocks: Generally

For each application the right program block and the right program language

The SIMATIC world provide:

▪ Various program languages

LAD/FBD STL SCL GRAPH

▪ Different kind of program blocks

OB FC FB DB
DB Global
Local
Program block
OB – Organization block

OBs are the interface between operating system and user program

FB FC
Local

HW OS OB FC

FC
Global

OS : Operating system
HW: Hardware configuration
Program block: OB – Organization block

OB – Organization block:
OB
▪ Interface between CPU operating system and user
program
▪ OBs including the user program
▪ Organization blocks are called from CPU operating
system if an event occurs
▪ Startup program
▪ Cyclic program
▪ Event triggered program
▪ Error triggered program

OB selection while add


new organization blocks
Program block: Function (FC)

Function:
FC ▪ Code blocks with temporary program memory
▪ For the programming of often needed complex
functions
▪ Parameter should be shared via the interface
▪ For storing data permanently, functions have to use
data blocks
▪ Several outputs are possible
▪ SCL can use a Function in a formula
<Operand> := <FC-Name> (Parameter list) …...;
Call of a
function in the
block editor
Program block: Function block (FB)

Function block :
▪ Code blocks that store their values so that they remain available
FB
even after the block has been executed.
Local
▪ All data are stored in the instance DB - the instance is the static
program memory of the FB.

Instance

Call of an Function block


Program block: Instance

The Instance will be created like the FB interface description


The structure is like the FB definition and can not be changed on the instance

FB
DB Instance
Local

Input
Output
InOut

Static
Program block: Instance – Data Block

Data block conduce to store user data

Instance-Data Block:
▪ IDBs are assigned to a specific FB
▪ IDBs should only be accessed from their owner-FB and not from all over the
program
▪ IDBs are created when calling an FB. The structure can not be modified

My_FBD_BLOCK_DB
Instance-
DB

Data for
“My_FBD_Block“
Program blocks: Multi-instance

Multi-instance:
▪ A FB (FB_b) can also call other FBs (FB_a) (embedded) and will be used as one unity. The
instance will be created if the FB are used (DB_b)
▪ A multi-instance DB (DB_b), is a data block that includes other instance data block of other
FBs

FB_b
FB_a
FB
FB_b FB_a
DB_b
_a

DB_b
Local Data FB_b

Data FB_a_Instance
Program block: Global Data-Block

Data block conduce to store user data

Global data blocks :


▪ DBs include data which can be accessed from all program
blocks
▪ DBs are created direct with the Program editor or
OB corresponding of a PLC Data type
DB
Global

FB
DB
Local FC
TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


Only for compatibility issues “not optimized” block access exists
“Not optimized” blocks
▪ Blocks for migrate projects or non-Siemens HMI
▪ The memory location is visible
▪ Therefore absolute access is possible
▪ Indirect absolute access with STL register
▪ with much effort changes on the structure possible

Optimized (Default setting)

▪ Fast optimized memory access


▪ Clearly symbolic access
▪ Clear symbolic access
▪ Secure indirect access with index to array elements
▪ No risky STL program access with register to absolute
addresses
Higher performance due to optimized data placement
STEP 7 handle the optimization

Not optimized DB Optimized DB S7-1500

Copy cause rearrangement -> time-consuming


max. 64 KB max. 16 MB
In worst case there
are 2x16 Bit-
Standard Bits Optimized Bits
block block
access necessary 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 „access
to read an um optimized“
0 BYTE 3 variable
REAL value.
The processor 1 2
Placement:
works with Intel REAL a memory access is
B 2 0 B 1 32 Bit wide -> REAL
format, therefore a
Bytes swap is y 3 1
y 0 = Little-Endian is a single and fast
necessary t REAL t access no byte
4 2 1
e e WORD swap necessary
s 5 3 = Big-Endian s 0 = Little-Endian
Bit-access: 6 X X BYTE
lock the byte, read Each Bit uses
7 X
the complete Byte, one Byte!
mask the Bit, 8 X => No masking
0
change it, WORD necessary
9 1 = Big-Endian Reserve
Higher performance due to optimized data placement
Access optimizing by data alignment on optimized blocks

Alignment in optimized blocks


Optimized
block
4 byte are read at the same time Structure placed separate
0 DW DW W B W W hence can be copied easy as
one block
16 W W W B B B B X X X
32 Reserve
B
48
y Retentively:
t 64 Retentive data placed
e separate hence can be copied
80
easy as one block
s
96
On lose of voltage retentive
102 DW DW DW W W values stored CPU intern
128 W B X X MRES overwrite the actual
values with the start values
144 from the load memory
Optimized block access

Optimized block access is default setting for new blocks

Benefit:

1. The data access is as fast as possible, optimized of the system and independent of the
declaration
2. No risk of error due to inconsistent absolute access, because the access only is symbolic
3. Changes on declaration do not cause access errors. Sample: insert a variable
4. It’s possible defined single variables retentive
5. No need to change the instance DB settings. All IDB settings used from the related DB. E.g.
setting retentive)
6. Reserve allow online changes without CPU STOP, this keeps the actual values
Programming: access speed on different memory areas

1 Retentive variables
Access in S7-1200/1500 1 = fast … 3 = slow
Not structured
elementary data types
FC-Parameter 1
1
Non retentive
variables 1 Access to
optimized blocks
Temporary
variables Copies between
1 3
optimized and
“not optimized” blocks
Indexed access Access to “not
with runtime index 1 optimized“ blocks
Access which cause 3
checks on runtime 3
(register- and indirect 3 2
DB-access)
Programming: access speed on different memory areas

Access in S7-1200/1500 1 = fast … 3 = slow

▪ Temporary variables
1 ▪ Optimized blocks, which access already known during compile
▪ Global DBs, which often used
▪ Indirect access which are calculated on runtime access, (e.g. Motor[i])

2 ▪ Data access to “not optimized" DBs

▪ Access on DBs which are created during runtime or opened indirect (e.g. OPN DB[i])
3 ▪ Register access or indirect memory access (e.g. L DBW[AR1, P#0.0])
▪ Copy of structures from optimized to “not optimized” blocks
▪ FB-variables with retentive setting “set in IDB”
Program optimizing for high speed performance S7-1200/1500

Performance optimizing:
▪ Indirect access only with ARRAY index
▪ Only symbolic access
▪ Reduce program loops as short as possible
▪ Call instructions only if:
Result is required and the input values has changed

▪ STL:
▪ Don’t use “status word” or flags of it – this bits are emulated if you use it (slow)

▪ LAD/FBD:
▪ Activate ENO only if it is used
▪ Deactivated ENO save time for internal check routines
Higher Performance: ENO deactivated

ENO deactivated speed up the process for LAD and FBD

Dependent on ENO the connected


instruction are executed

2
connected instruction always
executed Advantage: fast process
due to minimal checks
Interrupt: HW event Organization Block

▪ For fast reaction -> Events (Process alarm)


▪ Each hardware event can trigger an own OB
▪ Trigger due to a event on the inputs
Event

e.g. edge up
e.g. rising I6.1
edge I0.0

Hardware Hardware
interrupt interrupt_1
OB40 OBxxx
Interrupt: Fast Reaction due to short input delay time

Rising edge event will be


generated if the input signal
was continued high for
0.05ms

Default filter setting


for eliminate contact
bounce or EMC noises
Interrupt: Fast Reaction due to direct access to periphery outputs

Additional instructions:
Change relations between OB and
event
Only direct
periphery access Attach / Detach
on outputs enable events with OB
fast reactions
<output>:P

Enable / Disable
interrupt OBs
TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


Symbolic access: Interne IDs on TIA Portal

PLC_1 HMI_1
PLC tag Absolute Intern PLC Intern HMI
Interne HMI HMI tag Access Connection
name address reference ID reference ID name mode with PLC
Clock_1Hz M2.5 000123 009876 Clock_1Hz <symbolic PLC_1
access>
Valve_2 Q0.3 000138 000578 Valve_2 <symbolic PLC_1
access>

By adding any object also a reference ID is created.


This ID is used for the symbolic access between HMI and PLC
The reference is untouched although absolute address is changed.

Advantage: long symbolic names have no influence on:


Communication load between CPU and HMI
the amount of work memory on the device
Symbolic access: Intern IDs on TIA Portal

Use case and advantage of symbolic access:


PLC: Changes ▪ HMI: Download necessary

▪ Name of PLC tag:

Name changed & PLC

Tag are changed


automatically
Symbolic access: Internal IDs on TIA Portal

▪ Wile creating a tag also the ID is created


▪ The ID exist until the name is changed, type is changed or tag is deleted

Use case and advantage of symbolic access:


PLC: Changes ▪ HMI: Download NOT necessary
▪ PLC tag:

Tag change & PLC

▪ DB element (optimized and also not optimized):

Adding lines & PLC


Symbolic access: Internal IDs on TIA Portal

▪ „Connecting WinCC-tags“ is based on assigning internal Reference IDs

Using same tag name on HMI and


CPU will rename the WinCC tag
names also
Symbolic access: Create symbol

Think symbolic! Add direct the tag name and select the address later on

1. Type direct the tag


name
2. Select the address
for the tag

It is possible selecting
multiple tags with one
right mouse click.
Blocks: Auto numbering of blocks

Auto numbering of blocks

• The system declares the numbers of the


blocks automatically for the internal use
(Settings are in the properties)
• Block number conflicts, e.g. copy a block,
solves the system during compiling
automatically

Settings of automatic block numbering


in the block properties

Copy and paste; conflicts


because of identical block
numbers

During compiling, the system


re-numbers the block and solves
the conflict.
Symbolic access: Arrays

Array:
▪ Used for
▪ Recipes
▪ Monitoring material in a queue
▪ Collect process values
▪ Create a protocol

▪ A array represents a data structure of fixed number of the


same data types
▪ Arrays can defined multi dimensional
▪ Arrays can consisting of own PLC-Data types
Symbolic access: indirect access

Indirect ARRAY access possible with LAD / FBD, STL and SCL
Sample:
“Field_Data”. Syntax: <name>[„index“]
Numbers[“i”]
Access index calculated
i := DINT during runtime
(Node: temporary DINT
index gets the highest
performance!)

9
8
7
6
5
4
3
2
1
0

AWL:

SCL:
All Languages S7-1200/1500: ARRAYs in use

For indirect access on S7-1200/1500 use ARRAY


- Indirect access is possible in every language
- Possible on optimized blocks
- The use of inconvenient pointer handling is not needed
- Easy in use and easy to expand
- ARRAY range checking is a integrated feature
10

Local error handling

Index still in the ARRAY


range?
Block concept

The maximum size of blocks in the work memory is increased explicit

Max. size and numbers (work


S7-300/400 S7-1200 S7-1500
memory was not considered)
WinAC
S7-300
S7-400
64KB (nicht optimiert)
Max. size 64 kB 64 kB
16 MB (optimized)
DB
Max. number 16.000 59.999
FB
Max. size 64 kB 64 kB 512 kB
FC FB
FC
Max. number 7.999 65.535

FC FB DB Max. count 4.096 (CPU319) 6.000 (CPU412) 1.024 6.000 (CPU1516)

Use one large DB for all related data


Block concept: Declaration of variables and there use

Useable memory areas: Suggestion: Use only tags of the block interface

Available globally: 1) Variable only used in a block


- Memory area - Value only needed in this call :  temporary variable
- Value also needed in the next call :  static variable
- Timer M/C/T
- Counter 2) Variable used from more blocks
- Passing (also data from global data blocks) 
- Global data blocks Global
via block interface (IN/OUT/INOUT)

Available locally: Automatic check,


- IN/OUT/INOUT FB if only local tags
- Static variables FC used
Local

- Temporary variables
Type-safe and fast access possible with optimized blocks
All languages S7-1200/1500: Slice access

Slice access Exemplary operand names


„My_B_Variable“ BYTE
Operands in
blocks, DBs „My_W_Variable“ WORD
and I/Q/M
„My_DW_Variable“ DWORD

„My_LW_Variable“ LWORD

Examples: „My_DW_Variable.W1“ „My_W_Variable.X0“


X XX X
„Slice“ Access: 63 2 1 0 Bit-wise
No definition
necessary B7 B1 B0 Byte-wise
High programming
W3 W1 W0 Word-wise
efficiency
simple access to D1 D0 DWord-wise
control bits
Block concept: parameter passing – elementary data types

Parameter passing of elementary data types (Int, Dint, Bool..)

Passing by value:
FB
„My_Int“ IN
FC
„My_Int“ Wert: '2' Wert: '2'
IN
Wert: '2'
Wert: '2'

Copy the value to input parameter

Each block has the same behavior with passed parameters:


Elementary data types always copied as value:
▪ Independent of block type
▪ Independent from memory area of actual parameter
Block concept: Parameter passing – structured data types

S7-1500 S7-1200 S7-300/400/WinAC


Passing of structured data types by reference:

FC Structured data types


#MyString
IN/OUT IN OUT IN/OUT
Value: 'test'
Value to #MyString FC call Reference Reference Reference
FB call Value Value Reference
Pointer to data storage of the variable

Structures can be passed efficiently as parameter:


▪ The system architecture of the S7-1200 / S7-1500 was optimized therefore
▪ Splitting a hierarchical structure into separate parameters is not reasonable
▪ Copying the parameters into locale variables is neither required nor useful

Advise: Use structures symbolically as actual parameters!


Variable passing with different data areas

When passing data from different data areas (e.g. standard to optimized) the adaption
of the data is done by the system:
1. Copy the data to an area of the local data of the caller in the format of the called block
2. Pass the data in the correct format to the called block

Callee block
Consequences:
Local data
➔ Called block needs more local (optimized)
data when passing data from
different data areas Variables / structures 2
1
in the standard area, Called block
➔ With parameter passing by e.g.: (optimized)
reference, the reference to the - Standard data
local data of the called (and not blocks
to actual data) is used - I/O/M/T/C
Symbolic access: Communication with optimized blocks

VARIANT:
pointer includes the length
Communication blocks sending data in well known classic format
▪ The content of optimized blocks is send in same order like “not optimized” blocks.
STEP 7 takes care about the byte order.
Examples S7-300 CPUs – S7-1500 CPUs

Indirect addressing of DB-variables

Direct, symbolic
access to DB-variable
Open DB and DB-array

Absolute access to an
element of the DBs

Access to an array-
element of the DB

• Only one DB-access, thus performance improvement in S7-300 • Symbolical access for best performance
• Absolute access on array-elements (register indirect) • Better comprehensibly and readability
➔ thus error-prone
Examples S7-300 CPUs – S7-1500 CPUs

Copy of structures

Copy WORD from DB


to local structure

Direct, symbolical
Symbolical access to
access to DB-variable
structure which was
copied in

• Absolute access to overwrite structure – thus error- • Symbolical access for best performance
prone • Better comprehensibly and readability
Examples S7-300 CPUs – S7-1500 CPUs

Copy anonymous
structures by use of
BLKMOV

Use of indirect DB- and


variable addressing

Symbolical Symbolical assignment of


assignment of DBs the variables

• Use of user data types for DBs and I/O-variables –


• Absolute access to variables and indexed array access one central point of change
– thus error-prone • Fast access through referencing
• Better comprehensibly and readability
Information about indirect addressing

What is indirect addressing?

Using indirect addressing the address, the values Ideas to make the indirect addressing more flexible
should be read/written to, are calculated during and safe:
runtime of the program. Most of the times, the addresses that should be accessed
are already known during program creation:
Advantages: ➔ Adjoined data of same type: use array
• Reducing the programming effort ➔ Accesses to different areas or similar:
• Make the program more flexible Access-list(s) with the equivalent accesses are created
for indirect addressing
Disadvantages: e.g. program needs access to 3 variables (in different
access areas):
• Bad comprehensibility because cross-
Index Access
references are not available Access-list: access to
the respective 1 Input_Word_0 (%IW0)
• Access errors or writing in wrong areas might
variables is done by 2 „Processdata“.Temperature
happen index 3 Output_Word_4 (QW4)
Safe indirect addressing

Recommendation for indirect addressing Index Access

• Use of a FCs with input INT, returning the used data 1 Input_Word_0 (%IW0)

type 2 „Processdata“.Temperature

• Indirect accesses are defined inside of the FC and 3 Output_Word_4 (QW4)

returned via index FC for safe indirect addressing


• The indirect accesses can be used in the program
directly
Usage of the safe indirect addressing

Comprehensible, because usage of cross-references possible


Safe, because only predefined memory areas are used
Universal, because usable for standard and optimized blocks
ANY vs. symbolic programming
Use case overview

What was ANY-Pointer for? Simplification with S7-1500


Any-Pointer…for processing Arrays Using standard array functions
e. g. reading, initializing or copying of elements of the same type Reading and writing with #myArray[#index], copying with MOVE_BLK,…

Any-Pointer…for processing structures Forwarding structures as InOut parameters


performant
e. g. forwarding user defined structures via Any-Pointer to functions

Any-Pointer…for programming of
functions, which are able to process Function with Variant-Pointer as InOut
various data types parameter

Use cases can be solved clearly more intuitive.


The programming is more efficient and the code is easier to read.
Pointers are only necessary in particular use cases.
ANY vs. symbolic programming Usage of ANY (1): Arrays

Usage so far Recommendation for S7-1500


ANY-Pointer…to process Arrays Use of standard array functions

FC FC
ANY1: P#DB.DBx0.0 Byte 10 MOVE_BLOCK(Data1[0], 10, Data2[#index])
ANY2.Any_ID = B#16#10 //RID for Any
ANY2.DataType = B#16#02 //Byte Data1 : Array[0..10] of Byte
... Data2 : Array[0..50] of Byte
ANY2.Address = …… //DB + Offset calculation
BLKMOV(ANY1, ANY2)
Data1 : Array[0..10] of Byte
Data2 : Array[0..50] of Byte
Intuitive programming and less code
Long-winded, cumbersome Symbolic – Easier to read and less fault-prone
Internal CPU knowledge must be available Numerous system functions available (FILL_BLK
Fault-prone at address changes for initializing, MOVE_BLK for copying,…)
ANY vs. symbolic programming
Usage of ANY (2): Structure transfer

Usage so far Recommendation for S7-1500


ANY-Pointer is often used to process Forwarding structures as InOut parameter
structures performant

FC
FC
UDT InOut: UDT
Struct IN: ANY

Performant transfer of structures at S7-300/400 Performant transfer of structures at S7-1200/1500


Data structure not directly identifiable from the Data structure is directly identifiable from the
modules interface modules interface
Data must be copied from ANY Variables can be used directly
ANY vs. symbolic programming
Usage of ANY (3): Creating of generic modules

Usage so far Recommendation for S7-1500


ANY-Pointer as an input parameter and Variant pointer as InOut parameter and system
manual interpretation of data supported processing

FC UDT FC
UDT
UDT In: Val : ANY UDT InOut: Val : Variant

Performant transfer of structured variables by S7- Flexible forwarding of various structured variables
300/400 at S7-1200/1500
Structure gets lost at module interface Instruction of type analysis of Variant variables
Bytes have to be paraphrased manually according Variables can be used type safe with the
to memory structure assistance of system functions
ANY vs. symbolic programming

• The ANY-Pointer use cases can be solved


clearly more intuitive.
• The programming is more efficient and
the code is easier to read.
• Pointers are only necessary in special
use cases.
Usage of VARIANT (1)

How can data be assigned to a VARIANT?

An assignment can be done by: Declaration of a


• Assigning an actual parameter to a VARIANT VARIANT in the block
interface

Assignment of a variable to the


VARIANT (e.g. INT, UDT, …)

• Usage of the system instruction „DB_ANY_TO_VARIANT“ to create a pointer to a DB

DB or DB_ANY is assigned
Precondition: DB of type UDT, SDT or array-DB

• A direct assignment is not possible


TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


Usage of VARIANT (2) S7-1500 S7-1200 S7-300/400/WinAC

How can the data a VARIANT is pointing to, be used? Examples to instructions
VARIANT to Target type
To use the data it must be copied to variable:
Copy single variables • UDT_1 • UDT_1
VariantGet Data type of target variable and variable the • REAL • REAL
VARIANT is pointing to have to match • DINT • DWORD

Array [0..10] Array [0..50]


Dynamic, type-safe copying of arrays of UDT_1 of UDT_1
MOVE_BLK_VARIANT …
Offset of source- and destination-structure can
be freely chosen, data types have to match

Convert variables to an array of byte UDT_1 Array [0..50]


Serialize
Values of source-variable are copied in the sequence of •INT of BYTE
standard-blocks to an array of byte •BOOL
ArrayOfByte in non-optimized memory, bad performance •BYTE …
Usage of VARIANT (3) S7-1500 S7-1200 S7-300/400/WinAC

How can data be transferred (back) to a VARIANT?

After having processed the data, the following instructions can be used to transfer them (back) to
the with the VARIANT referenced variables, if needed:

VariantPut Copy single variables

MOVE_BLK_VARIANT Copy arrays dynamically and typesafe

Deserialize Convert values from an array of byte to the target variable

A new VARIANT-Pointer cannot be initialized with these instructions!


The VARIANT-variable which is written, must have been initialized in advanced (e.g. no
uninitialized temporary VARIANT possible)
Usage of VARIANT (4) S7-1500 S7-1200 S7-300/400/WinAC

How can data be evaluated, the VARIANT is pointing to?

Possibilities for evaluation of the variable referenced by VARIANT:


• Determine the data type
EQ_Type / NE_Type Compare a VARIANT on operand 1 with any data type on
EQ_ElemType / NE_ElemType operand 2. (UDT also)

Evaluates data type or array data type.


TypeOf() / TypeOfElements() Can be used ONLY in SCL and with a comparison!
• Evaluation of array properties
IS_ARRAY Verifies if variable is an array
CountOfElements Returns the number of array-elements, the VRAIANT is pointing to.
• Evaluation of the referenced DB
VARIANT_TO_DB_ANY Creates a DB_ANY (DB-Ref)
Application example „variable data-access“
„Safe indirect addressing“ with VARIANT
Creation of a VARIANT by use of DB_ANY_TO_VARIANT
1. Selection of a DB by use of safe indirect addressing
2. Assignment of the DB to a temporary VARIANT-variable
3. Processing the data of the temporary VARIANT-variable
4. Copy the DB-data to a local UDT-variable
5. Copy the data back in the linked DB 4

1 5

DB
Silo_Water DB
Silo_Sugar
2 Silo_
DB
Handling
Silo_Milk
3 Precondition: Use DB of UDT
Application example „variable data-access“
„Indexed addressing“ with VARIANT

VARIANT-assignment via actual parameters


1. Create a DB with an array of UDT
2. VARIANT is supplied with array-element (selected via index)
3. Copy the data as shown in the previous example
SILOS_DB

1 Silo_Water
3
Silo_ Silo_Sugar
Handling
Silo_Milk

Precondition: Use Array of UDT


Programming: Reflexion-Instructions S7-1500 S7-1200 S7-300/400/WinAC

Efficiently generating of error messages


The reflexion instructions are used to read out the actual
symbol-, block-, and instance-name in data type STRING!
With that STRING, it is possible to create debug information
or parts of alarm texts.

GetBlockName

GetInstanceName

GetSymbolName
Status of CPU load S7-1500 S7-1200 S7-300/400/WinAC

Read Runtime Statistics – „RT_INFO“ 55 %

Percentage of Percentage of
• Analysis of the CPU work load e.g. regarding
cycle OB´s communication load
communication and user program code
✓Percentage of the communication load regarding the 45
55 %
%
cycle time
30 %
✓Percentage of program cycle Organization Blocks 40 %
(e.g. OB1,..)
regarding the cycle time höher priore
Obs (z.B. OB
✓Percentage of the cyclic interrupt Organization Blocks 3x)
(e.g. OB 3x, OB 8x) regarding the cycle time 15 %
15 % zyklisches
Programm (OB
1)
Percentage of
Basis of percentage calculations:1s cyclic interrupt
OB´s
Programming: Status of CPU-load S7-1500 S7-1200 S7-300/400/WinAC

MODE
• 1 - 3: Return actual Runtime data of an OB
configured at parameter „OB“
• 10 and 11: Part of high priorized OB´s and
communication from the main cycle time
• 30 – 32: Configured settings of the user program

Example:
▪ MODE 1: runtime of the OB, configured at parameter
„OB“ in LTIME
▪ MODE 11: Communication percentage from the main
OB / INFO cycle time in UINT

• “OB” could be declared as a constant or variable


from data type OB_ANY
• The data type of the parameter „INFO“ is
depending on the chosen mode. Configuration of RT_INFO in
Online Help!!!
TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


Multiple use: re-use of blocks, multi instance

If a FB is called on a FB you get the choice “Multi instance”. The instance-data of the called FB is embedded
on the source FB.
“Multi instance” supports multiple use and multiple call

Instances are
placed on the
interface of
calling FB

Create “Multi instance “ a FB


Multiple use: re-use blocks, Multi instance

Only multi instance support easy use of re-use blocks


FB_A
Memory bits, S5 counter, S5 Timer are global and
exist only once ->multiple use is not supported! FB
FB
Local FB
Recommendation:
FB
▪ Only use IEC timer and counter. OB FB_A

▪ Use it as multi instance. FB


FB
▪ Additional use all tags like flags for edges as Local
Static on the interface (not global). FB

▪ With calling this FB all instances of it again as one


stricture in a instance
Tasks, plant parts: Arrange multiple Program-cycle blocks (Main)

Arrange optional functions to separate Program-cycle OBs or Startup OBs

User program
Common Group
Main FB

OB1 FC
Local
Arrangement of the program in different
executable groups is possible.
Group A
A_Main FB Execution of OBs in numeric order
Local
OB200 FC

Group B
B_Main FB
Local
OB300 FC
Tasks, plant parts: Arrange multiple Program-cycle blocks (Main)

1. Create groups for optional tasks


2. Use multiple separate Program-cycle OB
and call al relevant blocks for this separate
task on it
3. Move the entire group to the library
TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


CPU reaction on error: Error handling – Global

Global error handling OBs

CPU stays in RUN also without error OB, Entry to diagnostic buffer

FC
S7-1200

Error in e.g. programming error:


block ▪ Without OB121: CPU went to STOP, Entry to diagnostic buffer
▪ With OB121 : CPU stay in RUN, Entry to diagnostic buffer
call of OB121
e.g. IO access error:
S7-1500 ▪ Without OB122: CPU stays in RUN, Entry to diagnostic buffer
▪ With OB122 : CPU stays in RUN, Entry to diagnostic buffer
call of OB122
▪ The CPU works „fault-tolerant“. S7-1500 only wet to STOP if OB121 or
▪ OB80 is missing, all other OB are not forcing necessary
Block concept: Error handling – Local

Local Error handling

FC
FC OB
SFC

Error in GET_ERROR or No OB call, no


block GET_ERR_ID used entry in Displayed in the properties of
in block diagnostic buffer the block in “Attributes“

Local error handling in user program


Error in front of GetError-call: Error number is displayed
Error after GetError-call: no display of number, no OB-call
Has to be used in every block separately, e.g. GetError-
calls do not apply to called or calling blocks ENO can be used for error
handling (only active when
Perfect for user-defined libraries with error handling error occurred)
TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


Hints: Intelligible SCL Program

SCL
Use instance names which
include the instruction name

Advantage:
More intelligible programs
Hints: LAD/FBD recording of network content

LAD/FBD
Use short network titles on the networks

Advantages:
If all networks collapsed, the program
structure and network contents is easily
to identify

Hot key:
<Alt+F11> expand all networks
<Alt+F12> collapse all networks
Hints: expand the editor area

▪ If possible, use a PC with multiple large screens. Not only advantageous for TIA-Portal
▪ Advantage: drag & drop can be better used if more as two editors open
▪ If only one editor or beamer with small resolution is used:
Recommendation: with double-click on the editor bar the work area can easily
expanded or collapsed
TIA Portal – Programming recommendations

• Goal 2
• Fast System reaction 13
• Symbolic access 25
• New instructions 53
• Multiple use 62
• Error handling 67
• Hints 70
• Recommendations 74

Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08


Recommendation for S7-1200 and S7-1500 with TIA Portal

▪ Use instruction as multi instance (TON TOF ..)


▪ Define tasks and arrange it as groups in separate Obs
▪ Use network titles on LAD/FBD for block overview
Advantages:
▪ Multiple use of blocks supported
▪ Network titles are a excellent instrument get an short program overview
▪ Rollout of updates can be done easily and consistent.
Useful Links

Programming recommendations for S7-1200 and S7-1500 with STEP 7 (TIA Portal)
http://support.automation.siemens.com/WW/view/en/67582299

Programming guideline for S7-1200/1500 (also in PDF as customer workshop)


http://support.automation.siemens.com/WW/view/de/81318674

Migration:
Migration production plants – http://support.automation.siemens.com/WW/view/en/83558085
Migration PLC´s – http://support.automation.siemens.com/WW/view/en/83557459
Migration Vizualisation – http://support.automation.siemens.com/WW/view/en/76878921
Migration communication – http://support.automation.siemens.com/WW/view/en/83558087
Migration periphery – http://support.automation.siemens.com/WW/view/en/83558994
Let us know if there is anything
we can support you with!
For further information and support, please contact:
Mr. Tran Van Hieu
SITRAIN Manager – Digital Industry Academy
Siemens Vietnam
Email: [email protected]

www.siemens.com.vn
www.facebook.com/Siemens.Vietnam

Page 77 Unrestricted | © Siemens 2021 | Trần Văn Hiếu | SITRAIN | 2021-10-08

You might also like