Siemens recommends strongly that you regularly check for product updates. For the secure operation of Siemens products and solutions, it is necessary to take suitable preventive action (e.g. cell protection concept) and integrate each component into a holistic, state-of-the-art industrial security concept. Third-party products that may be in use should also be considered.
Optimized machine code ..............8 Block creation ..................9 Optimized blocks ................10 2.6.1 S7-1200: Setup of optimized blocks ........... 10 2.6.2 S7-1500: Setup of optimized blocks ........... 11 2.6.3 Best possible data storage in the processor on S7-1500 ....12 2.6.4...
Page 4
3.10.8 Handling of time tags ................67 Hardware-Independent Programming ............69 Data types of S7-300/400 and S7-1200/1500 ........69 No bit memory but global data blocks ..........70 Programming of "clock bits" ............... 71 The Most Important Recommendations ............72 Related Literature ....................
This helps you to create a standardized and optimal programming of your automation solutions. The examples described can be universally used for the controllers S7-1200 and S7-1500. Core content of this programming guideline...
(FBs), functions (FCs) or data blocks (DBs). I.e. already created S7-300/400 programs can be implemented on S7-1500 and already created LAD, FBD and SCL programs on S7-1200 controller without any problems. Additionally, there are many innovations that make programming easier for you and which allow a powerful and storage-saving code.
Page 7
STEP 7 Professional (TIA Portal)? http://support.automation.siemens.com/WW/view/en/62101406 PLC migration for S7-1500 with STEP 7 (TIA Portal) V12 http://support.automation.siemens.com/WW/view/en/67858106 Programming recommendations for S7-1200 and S7-1500 with STEP 7 (TIA Portal) V12 http://support.automation.siemens.com/WW/view/en/67582299 Why is it not possible to mix register passing and explicit parameter transfer with...
How can the constants be defined under STEP 7 V11 in a S7-SCL program? http://support.automation.siemens.com/WW/view/en/58065411 Optimized machine code TIA Portal and S7-1200/1500 allow an optimized runtime performance in any programming language. All languages are compiled the same, directly into the machine code.
2 S7-1200/1500 Innovations 2.5 Block creation Figure 2-3: Machine code generation with S7-300/400/WinAC and S7-1200/1500 S7-1200/1500 S7-300/400/WinAC (only S7-1500) Machine code Machine code S7-1200/1500 S7-300/400/WinAC For S7-300/400/WinAC controllers LAD and FBD programs are first of all compiled in STL before the machine code is created.
2.6 Optimized blocks Optimized blocks S7-1200/1500 controllers have optimized data storage. In optimized blocks, all tags are automatically sorted by their data type. The sorting ensures that data gaps between the tags are minimized and that the tags are stored access-optimized for the processor.
S7-1500 can directly read or write all tags with just one machine command). Boolean tags are stored as byte for faster access. The controller therefore does not have to mask the access. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
When accessing, the controller does not The complete byte is blocked for any have to mask the byte. other access. Maximum block size is 64kB. Maximum block size can be up to 16MB. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 13
Example: Setting optimized block access The optimized block accesses for all newly created blocks for S7-1200/1500 is enabled by default. Block access can be set for OBs, FBs and global DBs. For instance DBs, the setting depends on the respective FB.
Page 14
No “offset” is displayed. displayed and can be used for addressing. In optimized blocks every tag can be In non-optimized blocks only all or no tags declared with “Retain”. can be declared with “Retain”. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
In the case of type-identical allocations between two tags with different storage locations, the system converts automatically. In the case of structured tags, this conversion requires performance and should therefore be avoided, if possible. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Any tags or data blocks (derived from PLC data types) can be used as data records. Note It is also possible that the send and receive data are not defined identically: Send data Receive data optimized --> not optimized not optimized --> optimized Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Data volumes of > 64 kB can be stored in an optimized DB (max. size 16 MB) with S7-1500 controllers. New data types for S7-1200/1500 S7-1200/1500 controllers support new data types in order to make programming more convenient. With the new 64 bit data types considerably larger and more accurate values can be used.
2 S7-1200/1500 Innovations 2.8 New data types for S7-1200/1500 Table 2-9: Floating-point decimal data types Type Size Value range Real 32 bit (1 bit signs, 8 bit exponent, 23 bit mantissa), -3.40e+38 .. 3.40e+38 accurate to 7 decimal places LReal 64 bit (1 bit signs, 11 bit exponent, 52 bit -1.79e+308 ..
Page 19
2 S7-1200/1500 Innovations 2.8 New data types for S7-1200/1500 Figure 2-12: VARIANT data type as input parameter for the TSEND_C instruction VARIANT In this case includes the check of the structure TCON_IP_v4 Advantages Integrated type test Symbolic addressing for optimized blocks Recommendation Use the VARIANT data type instead of the ANY pointer.
Always use the CALCULATE instruction for mathematical calculations instead of many calls of instructions, such as, e.g. ADD, SUB, etc. 2.9.2 MOVE instructions STEP 7 (TIA) provides the following MOVE instructions. The instruction MOVE_BLK_VARIANT for S7-1200/1500 is new. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
SCL (S7-1200/S7-1500) and in STL (S7-1500). NOTE You will find further information in the following entry: With S7-1200/S7-1500, how do you measure the time of a program section or the complete program cycle at runtime? http://support.automation.siemens.com/WW/view/en/87668318 Programming Guideline for S7-1200/1500...
4. Network title comment 5. Network comment 6. Comment on instructions, blocks and functions (open, close, etc.) In the programming languages SCL and STL, it can be commented with // in every row. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
For S7-300/400 controllers the identification of hardware and software components is performed by logic address or diagnostic addresses. For S7-1200/1500 the identification is by system constants. All hardware and software components (e.g. interfaces, modules, OBs, ...) of the S7-1200/1500 controllers have their own system constants. The system constants are automatically created during the setup of the device configuration for the central and distributed I/O.
In the user program “Robot_arm_left” is interconnected with the “GET_DIAG” diagnostic block. Note You will find further information in the following entry: What meaning do the system constants have for the S7-1200/1500 in STEP 7 (TIA Portal)? http://support.automation.siemens.com/WW/view/en/78782836 2.12 Internal reference ID for controller and HMI tags STEP 7, WinCC, Startdrive, Safety and others integrate into the joint data base of the TIA Portal engineering framework.
TIA Portal. This approach makes the S7-1200/1500 controllers more fault tolerant to errors than their predecessors. Advantages There are only three fault situations that put the S7-1200/1500 controllers into the STOP mode. This makes the programming of the error management clearer and easier.
Page 26
For S7-1200/1500 controllers there are other programmable error OBs (diagnostic error, module rack failure, etc.). More information on error responses of S7-1200/1500 can be found in the online help of the TIA Portal under “Events and OBs”. Programming Guideline for S7-1200/1500...
Due to a good and structured program you get many function units that can be multiply reused within a project and also in other projects. These function units then usually only differ by a different configuration (see chapter 3.2.8 Reusability of blocks). Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
OBs are the interface between the operating system and the user program. They are called by the operating system and control, e.g. the following processes: Startup behavior of the controller Cyclic program processing Interrupt-controlled program processing Error handling Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 29
OBs, use the global DBs (see chapter 4.2 No bit memory but global data blocks). Divide all program parts that belong to each other into folders and store them for reusability in the project or global library. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
FCs are blocks without cyclic data storages. This is why the values of block parameters cannot be saved until the next call and has to be provided with actual parameters when called. Properties FCs are blocks without cyclic data storages. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 31
Temporary and out tags are undefined when called in non-optimized blocks. In optimized blocks, the values are always preset to the default value (S7-1500 and S7-1200 Firmware V4). Thus, the resulting behavior is not accidental but reproducible. In order to permanently save the data of an FC, the functions of the global data blocks are available.
Temporary and out tags are undefined when called in non-optimized blocks. In optimized blocks, the values are always preset to the default value (S7-1500 and S7-1200 Firmware V4). Thus, the resulting behavior is not accidental but reproducible. Static tags keep the value from cycle to cycle...
The following figure shows an FB that uses another FB (“IEC Timer”). All data is saved in a multi instance DB. It is thus possible to create a block with an independent time behavior, for example, a clock generator. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 34
If you require the time and counter function, use the “IEC Timer” blocks and the “IEC Counter” blocks instead of the absolutely addressed SIMATIC Timer. If possible, also always use multi-instances here. This keeps the number of blocks in the user program low. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
How do you declare the timers and counters for the S7-1500 in STEP 7 (TIA Portal) V12? http://support.automation.siemens.com/WW/view/en/67585220 3.2.6 Global data blocks (DB) Figure 3-11: “Add new block” dialog (DB Variable data is located in data blocks that are available to the entire user program. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
3.2.7 Downloading without reinitialization In order to change user programs that already run in a controller, S7-1200 (firmware V4.0) and S7-1500 controllers offer the option to expand the interfaces of optimized function or data blocks during operation. You can load the changed blocks without setting the controller to STOP and without influencing the actual values of already loaded tags.
Page 37
Define a memory reserve for blocks that are to be expanded during commissioning (e.g. test blocks). The commissioning process is not interrupted by download of new defined tags. The current values of already existing variables are kept. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 38
You can also set a default value for the size of the memory reserve for new blocks in the TIA portal. In the menu bar, navigate to "Options – Settings" and then to "PLC programming – General – Download without reinitialization“. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
The block concept offers you a number of options to program in a structured and effective way. Advantages Blocks can be used universally in any location of the user program. Blocks can be used universally in different projects. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Call-by-value with In interface type When calling the block, the value of the actual parameter is copied onto the input parameter of the block for the In interface type. For this, additional memory is required. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
3.4.1 Block interfaces as data exchange If you are encapsulating the functions and program the data exchange between the blocks only via the interfaces, you will clearly have advantages. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Note Optimized blocks: Temporary tags are initialized in any block call with the “default value” (S7-1500 und S7-1200 Firmware V4). Non-optimized blocks: Temporary tags are undefined for each call of the block. Programming Guideline for S7-1200/1500...
Access to non-optimized Access to optimized DBs blocks Fastest accesses in the S7-1200/1500 in descending order 1. Optimized blocks: Temporary tags, parameters of an FC and FB, non-retentive static tags 2. Optimized blocks whose accesses for compiling are known: –...
CPU 1511-1 PN 88 Kbytes CPU 1513-1 PN 88 Kbytes CPU 1516-3 PN/DP 472 Kbytes Table 3-6: Differences of S7-1200 and S7-1500 S7-1200 S7-1500 Retentivity can only be set for bit memory Retentivity can be set for bit memory, times and counters...
Page 46
Retentivity can be set from address 0 onward! e.g. from MB0, T0 or C0 Example: Retentive counter You can also declare instances of functions (timer, counter, etc.) retentive. As already described in chapter 3.2.5 Multi-instances Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
If the retentive memory on the PLC is not sufficient, it is possible to store data in the form of data blocks that are only located in the load memory of the PLC. The following entry is described by taking the example of an S7-1200. This programming also works for S7-1500.
Page 48
Open the program editor and open any block. Enter a symbolic name directly at the input of an instruction. Right-click next to the block and select “Define tag…” in the context menu. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Figure 3-25: ARRAY with 10 elements of the Integer (INT) data type You can indirectly access individual elements in the ARRAY with a runtime tag (array [“index”]). Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 50
Use the “GET_ERR_ID” instruction to catch access errors within the Array. Note You will find further information in the following entry: How do you implement an array access with an S7-1500 with variable index? http://support.automation.siemens.com/WW/view/en/67598676 Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
PLC data type can be used for any number of DBs. You can easily and conveniently create as many DBs of the same structure and adjust them centrally on the PLC data type. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
(%Ix.0 or %Qx.0, e.g., %I0.0, %Q12.0, …) 3. Transfer of the PLC tag as actual parameter to the function block 4. Input of the function block is of the type of the created PLC data type Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
3.6.5 Slice access For S7-1200/1500 controllers, you can access the memory area of tags of the Byte, Word, DWord or LWord data type. The division of a memory area (e.g. byte or word) into a smaller memory area (e.g. Bool) is also called slice. In the figure below displays the symbolic bit, byte and word accesses to the operands.
3.7.1 Types of libraries and library elements Generally there are two different types of libraries: "Project library" "Global library". The content consists of two storage types each: "Types" "Master Copies" Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 55
Subordinate elements are automatically typified. – Types are versioned: Changes can be made by creating a newer version. – There can only be one version of a used type within a controller. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Control elements are edited in a test HMI images and HMI scripts are edited in a environment. test environment. Faceplates and HMI - UDTs are directly edited in the library without test environment. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Define an input tag of the data type you have created. The PLC data type is therefore subordinate to the function block. Drag the function block via drag & drop into the “Types” folder in the project library. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 58
The subordinate PLC data type is automatically also stored in the library. Example: Changing a type Table 3-10: Changing a type Step Instruction Right-click the block in the “Project library” and select “Edit type” Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 59
In this place you have the option to test the change on the block by loading the project onto a controller. When you have finished testing the block, continue with the following steps. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 60
“Update instances in the project”. If older versions of the element are no longer required you can delete them by clicking “Delete unused type versions from library” Close the library view with “Close library view” Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
In the following figure you can see the configuration of a “hardware interrupt” in the hardware configuration of a digital input module. Figure 3-34: Configuring hardware interrupt Advantages Fast system response to events (rising, falling edge, etc.) Each event can start a separate OB. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 62
The input delay is used for filtering the input signal in order to, for example, compensate faults such as contact bounce or chatter. Figure 3-35: Setting input delay Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Here you can find some general recommendations that enable faster program processing of the controller. Recommendation Note the following recommendations for programming S7-1200/1500 controllers in order to achieve a high performance: LAD/FBD: Disable “generate ENO” for blocks. This avoids tests at runtime.
Call Template mode. The editor expands the call again. You can navigate with the “TAB” button through the parameters. Note: In the “Call Template” mode the writing is in italics. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Drag the tag via drag & drop to the tag in the program that is to be replaced. Hold the tag for more than 1 second before releasing it. > hold for 1 second The complete tag is replaced. Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
The compiler can optimize the program better, since it does not know the number of iterations. Example FOR #var := #lower TO #upper DO #var := #var + 1; // no effect, Compiler -> Warning END_FOR; Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
This approach is called “overload of operands”. The SCL compiler automatically uses the suitable functions. You can use a reasonable arithmetic for the time types and can therefore program more efficiently. Example TimeDifference := TimeStamp_1 – TimeStamp_2; Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Page 68
– dtl T_DIFF DTL dt – dt T_DIFF DT date – date T_DIFF DATE ltod – ltod T_DIFF LTOD date + ltod T_COMBINE DATE / LTOD date + tod T_COMBINE DATE / TOD Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
4 Hardware-Independent Programming 4.1 Data types of S7-300/400 and S7-1200/1500 Hardware-Independent Programming To make sure that a block can be used on all controllers without any further adjustments, it is important not use hardware-dependent functions and properties. Data types of S7-300/400 and S7-1200/1500 Below is a list of all elementary data types and data groups.
VOID PLC data types PLC Data Type For optimized accesses, only symbolic addressing is possible For S7-1200/1500 the TIMER and COUNTER data type is represented by IEC_TIMER and IEC_Counter. No bit memory but global data blocks Advantages Optimized global DBs are clearly more powerful than the bit memory address area that is not optimized for reasons of compatibility.
If the desired frequency is smaller or equal 0.0, then the output Q = FALSE and Countdown = 0.0. Q [Bool] TRUE Period: 2 seconds Frequency [Real] Countdown [Time] T#0S_703MS Note The complete programming example is available for free download in the following entry: http://support.automation.siemens.com/WW/view/en/87507915 Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Chapter 3.6.3 STRUCT data type and PLC data types Using libraries for storing program elements – Chapter 3.7 Libraries No memory bits but global data blocks – Chapter 4.2 No bit memory but global data blocks Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...
Extension of following chapter: 2.2 Terms 2.3 Programming languages 2.6 Optimized blocks 2.8.2 Date_Time_Long data type 2.10 Symbolic and comments 3.2 Program blocks 3.5 Retentivity 4.3 Programming of "clock bits" Several corrections in different chapter Programming Guideline for S7-1200/1500 V1.2, Entry ID: 81318674...