Siemens CPU 948 Programming Manual

Page 1
Contents
Introduction
1
User Program
2
Program Execution
3
Operating Statuses and Program Execution Levels
4
5
Integrated Special Functions
6
Extended Data Block DX 0
7
Memory Assignment and Memory Organization
8
Memory Access Using Absolute Addresses
9
Multiprocessor Mode and Com­munication in the S5-155U
10
PG Interfaces and Functions
11
Appendix
12
Indexes: Abbreviations Key Words
13
The List of Operations, order no. 6ES5 997-3UA22, is included with this manual.
10/98 C79000-G8576-C848 Release 04
S5-155U CPU 948
Programming Guide
This manual has the order number:
6ES5 998–3PR21
SIMATIC S5
Page 2
!
Danger
indicates that death, severe personal injury or substantial property damage will result if proper precautions are not taken.
!
Warning
indicates that death, severe personal injury or substantial property damage can result if proper precautions are not taken.
!
Caution
indicates that minor personal injury or property damage can result if proper precautions are not taken.
Note
draws your attention to particularly important information on the product, handling the product, or to a particular part of the documentation.
Qualified Personnel
The device/system may only be set up and operated in conjunction with this manual. Only qualified personnel should be allowed to install and work on this equipment. Qualified persons are defined as persons who are authorized to commission, to ground, and to tag circuits, equipment, and systems in accor­dance with established safety practices and standards.
Correct Usage
Note the following:
!
Warning
This device and its components may only be used for the applications described in the catalog or the technical description, and only in connection with devices or components from other manufacturers which have been ap­proved or recommended by Siemens.
This product can only function correctly and safely if it is transported, stored, set up, and installed correctly, and operated and maintained as recommended.
Trademarks
SIMA TICR, SIMA TIC NETR and SIMATIC HMIR are registered trademarks of SIEMENS AG. Third parties using for their own purposes any other names in this document which refer to trademarks might infringe upon the rights of the trademark owners.
We have checked the contents of this manual for agreement with the hardware and software described. Since deviations cannot be precluded entirely, we cannot guarantee full agreement. However, the data in this manual are reviewed regularly and any necessary corrections included in subsequent editions. Suggestions for improvement are welcomed.
E Siemens AG 1998
Subject to change without prior notice.
Disclaimer of LiabilityCopyright E Siemens AG 1998 All rights reserved
The reproduction, transmission or use of this document or its contents is not permitted without express written authority. Offenders will be liable for damages. All rights, including rights created by patent grant or registration of a utility model or design, are reserved.
Siemens AG
Bereich Automatisierungs- und Antriebstechnik Geschaeftsgebiet Industrie-Automatisierungssysteme Postfach 4848, D-90327 Nuernberg
Siemens Aktiengesellschaft
6ES5 998-3PR21
Safety Guidelines
This manual contains notices which you should observe to ensure your own personal safety, as well as to protect the product and connected equipment. These notices are highlighted in the manual by a warning triangle and are marked as follows according to the level of danger:
Page 3
1 Introductio n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 3
1.1 Area of Application for the S5-155U with the CPU 948 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 4
1.2 T yp ic a l Mode of Operation of a CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 5
1.3 The Programs in a CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 7
1.4 Which Operands are available to the User Program?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 11
1.5 How much Memory is available for the User Program? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 14
1.6 How to T ackle Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 15
1.7 Programming Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 18
1.8 Converting User Programs of the CPU 928B for the CPU 948. . . . . . . . . . . . . . . . . . . . . . . . . 1 - 19
2 User Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 3
2.1 STEP 5 Programming Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 4
2.1.1 The LAD, CSF, STL Methods of Representation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 4
2.1.2 Structured Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 5
2.1.3 STEP 5 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 6
2.1.4 Number Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 8
2.1 .5 STEP 5 Blocks and Storing them in Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 12
2.2 Program , Organi zation and Seq uence Block s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 16
2.2.1 Organization Blocks as User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 18
2.2.2 Organiz at ion Blocks for Special Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 22
2.3 Function Bl ocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 23
2.3.1 Structu re of Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 24
2.3.2 Programming Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 26
2.3.3 Calling Function Blocks and Assigning Parameters to them . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 28
2.3.4 Special Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 33
2.4 Da ta Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 35
2.4.1 Creating Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 37
2.4.2 Opening Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 38
2.4 .3 Spec ial Data Bl o cks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 41
Contents
CPU 948 Program ming Guide C79000-G85 76 -C848-04
iii
Page 4
3 Progra m Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 3
3.1 Principle of Program Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 4
3.2 Program Or ganization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 5
3.3 Storing Program and Data Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 10
3.4 Processing the User Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 11
3.4.1 Definition of Terms used in Program Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 12
3.5 STEP 5 Operations with Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 15
3.5 .1 Basic Oper ations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 19
3.5.2 Programming Examples in the STL, LAD and CSF Methods of Representation. . . . . . . . . . . 3 - 34
3.5.3 Supplementary Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 49
3.5.4 Executive Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 59
3.5.5 Semaphore Operation s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 75
4 Operating Statuses and Program Execution Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 3
4.1 Program Execution Levels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 4
4.2 STOP Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 9
4.2.1 SOFT STOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 9
4.2.2 HARD STOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 13
4.2.3 OVERALL RESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 14
4.3 START-UP Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 16
4.3.1 MANUAL and AUTOMATIC COLD RESTART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 17
4.3.2 MANUAL and AUTOMATIC WARM RESTART. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 18
4.3.3 Comparison betwee n COLD REST ART and WARM REST ART . . . . . . . . . . . . . . . . . . . . . . . 4 - 21
4.3.4 RETENTIVE COLD RESTART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 22
4.3.5 Comparison of COLD REST ART and RETENTIVE COLD REST A RT . . . . . . . . . . . . . . . . . 4 - 23
4.3.6 User Interfaces for Start-Up. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 24
4.3.7 Extended AUTOMATIC WARM RESTART with the CPU 948 (HOT RESTART). . . . . . . . . 4 - 27
4.3.8 Interruptions during START-UP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 28
4.4 RUN Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 29
4.4.1 Cyclic Program Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 30
4.4.2 Specifying Time and Interrupt-Driven Progra m Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 32
4.4.3 Time-Controlled Program Execut ion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 33
4.4.4 Interrupt-Driven Program Executio n. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 - 41
5 Interrupt and Error Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 3
5.1 Frequent Errors in the User Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 4
5.2 Error Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 5
5.3 Procedu r e for E rro r A nalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 8
5.4 Control Bits and Interrupt Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 9
5.4 .1 Control Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 10
5.4.2 ISTACK Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 14
5.4 .3 Example of Erro r Diagnosis usi ng the ISTACK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 19
Contents
CPU 948 Programming Guid e
iv C79000-G85 76-C84 8-04
Page 5
5.5 Error Handling Using Organization Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 20
5.6 Causes of Error and Reactions of the CPU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 23
5.6.1 OB 19: Calling a Logic Block That Is Not Loaded (KB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 24
5.6.2 OB 19: Calling a Data Block That Is Not Loaded (KDB). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 24
5.6.3 OB 23/24, OB 28/29:Tim eout Error (QVZ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 25
5.6.4 OB 25: Addressing Error (ADF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 26
5.6.5 OB 26: Cycle Tim e Excee ded Error (ZYK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 27
5.6.6 OB 27: (Substitution Error SUF). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 28
5.6.7 OB 30: Parity Error and Timeout Error in the User Memory (P A R E) . . . . . . . . . . . . . . . . . . . 5 - 28
5.6.8 OB 32: Load and Transfer Error (TRAF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 29
5.6.9 OB 33: Collision of Timed Interrupts Error (WEFES/ WEFEH) . . . . . . . . . . . . . . . . . . . . . . . . 5 - 30
5.6.10 OB 34: Error with G DB/GX DX (FEDBX) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 32
5.6.11 OB 35: Communication Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 32
5.6.12 OB 36: Error in Self-test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 33
5.7 Self-Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 34
5.7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 34
5.7.2 Description of the Test Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 35
5.7.3 Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 37
5.7 .4 Erro r Ha ndling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 - 38
6 Integrated Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 3
6.1 In t roduct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 4
6.2 OB 121: Set/Read System Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 8
6.3 OB 122: "Disable Interrupts" On/Off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 12
6.4 OB 12 4 : Delete STEP 5 Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 14
6.5 OB 125: Generate STEP 5 Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 17
6.6 OB 126: Define, Transfe r Process Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 20
6.7 OB 129: Battery State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 25
6.8 OB 131: Delete ACCUs 1, 2, 3 and 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 26
6.9 OB 132/133: Roll- Up ACCU/ Roll-Down ACCU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 27
6.10 OB 141: "Disable Single Cyclic Timed Interrupts" On/Off. . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 29
6.11 OB 142: "Delay All Interrupts" On/Off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 32
6.12 OB 143: "Delay Single Cyclic Timed Interrupts" On/Off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 35
6.13 OB 150: Set/Read System Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 38
6.14 OB 151: Set/Read Time for Clock-Controll ed Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 43
6.15 OB 153: Set/Read Time for Delayed Interrupt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 50
6.16 OB 180: Va ri ab le Data Block Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 53
6.17 OB 181: T est Data Blocks (DB/DX) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 57
6.18 OB 182: Copy Data Area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 59
6.19 OB 202 to 205: Multiprocessor Communicatio n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 62
Contents
CPU 948 Program ming Guide C79000-G85 76 -C848-04
v
Page 6
6.20 OB 222: Restart Cycle Monitoring Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 63
6.21 OB 223: Compare Start-Up Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 64
6.22 OB 254/255: Copy/Duplicate Data Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 - 65
7 Extended Data Block DX 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 3
7.1 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 4
7.2 St r ucture of DX 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 5
7.2 .1 Example of Input in DX 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 7
7.3 Parameters for DX 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 8
7.4 Examples of Par ameter Assig n ment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 12
7.4.1 STEP 5 Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 12
7.4.2 Paramete r Assignment using the PG Screen Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 - 14
8 Memory Assignme nt and Memory Organization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 3
8.1 St r ucture of the Memory Area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 4
8.2 Memory Assignment in the CPU 948 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 5
8.2.1 Memory Assignment for the System RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 6
8.2.2 Memory Assignment for the Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 8
8.3 User Memory Organization in the CPU 948. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 10
8.3 .1 Block Header s in User Me mory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 12
8.3 .2 Block Address L i st in Da ta Block DB 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 13
8.3.3 RI/RJ Ar ea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 14
8.3 .4 RS/RT Area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 15
8.3.5 Bit Assignment of the System Data Words. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 18
8.3.6 Addressable System Data Are a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 - 42
9 Memory Access U sing Absolute Addr e sses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 3
9.1 In t roduct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 4
9.2 Memory Access via Address in ACCU 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 8
9.2.1 LIR/TIR: Loading to or Transferring from a 16-Bit Memory Area Indirectly . . . . . . . . . . . . . . 9 - 9
9.2.2 Exa m ples of Acce ss to DW > 255 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 15
9.2.3 LDI/TDI: Loading to or Transferring from a 32-Bit Memory Area Indirectly . . . . . . . . . . . . . 9 - 17
9.3 Transferring Memory Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 19
9.4 Operations with the Base Address Register (BR Register) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 22
9.4.1 Operation s for Transfer between Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 23
9.4.2 Accessing the Local Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 24
9.4.3 Accessing the Global Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 25
9.4.4 Accessing the Dual-Port RAM Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 29
10 Multipr ocessor Mode and Communication in the S5-155U . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 3
10.1 Multiprocessor Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 4
10.1.1 When to use the Multiprocessor Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 4
10.1.2 What Co mmunications Mechanisms a re Available?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 4
Contents
CPU 948 Programming Guid e
vi C7 9000-G85 76-C84 8-04
Page 7
10.1.3 Exch anging Data via IPC Flag s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 5
10.1.4 Exchanging Data via Handling Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 8
10.1.5 What needs to be Programmed for the Multiproce ssor Mode? . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 9
10.1.6 How to Create Data Block DB 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 9
10.1.7 Star ti ng up in the Multiprocesso r Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 13
10.1.8 Test Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 14
10.2 Multiproce ssor Communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 15
10.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 15
10.2.2 How the Tra nsmi tte r and Receiver are Identified . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 16
10.2.3 Why Data is Buffered . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 17
10.2.4 How the Buffer is Processed and Managed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 18
10.2.5 System Start-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 21
10.2.6 Calling Communication OBs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 22
10.2.7 How to Assign Parameters to Communication OBs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 23
10.2.8 How to Evaluate the Output Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 24
10.3 Runtimes of t h e Com m unica tion OBs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 31
10.4 INITIALIZE Function (OB 200). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 33
10.4.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 33
10.4.2 Call Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 35
10.4.3 Input Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 35
10.4.4 Outp u t Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 38
10.5 SEND Function (OB 202) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 40
10.5.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 40
10.5.2 Call Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 40
10.5.3 Input Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 40
10.5.4 Outp u t Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 42
10.6 SEND TEST Function (OB 203) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 45
10.6.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 45
10.6.2 Call Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 45
10.6.3 Input Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 45
10.6.4 Outp u t Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 45
10.7 RECEIVE Function (OB 204). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 0 - 47
10.7.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 47
10.7.2 Call Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 47
10.7.3 Input Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 47
10.7.4 Outp u t Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 48
10.8 RECEIVE TEST Function (OB 205) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 51
10.8.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 51
10.8.2 Call Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 51
10.8.3 Input Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 51
10.8.4 Outp u t Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 51
Contents
CPU 948 Program ming Guide C79000-G85 76 -C848-04
vii
Page 8
10.9 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 53
10.9.1 Calling the Special Function OB using Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 53
10.9.2 Transferring Data Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 60
10.9.3 Ext ending the IPC Flag Area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 66
11 PG Interfaces and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 3
11.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 4
11.2 PG Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 5
11.2. 1 Inf o 11 - 6
11.2.2 Ins tallation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 7
11.2.3 Program Test. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 8
11.3 Seri al Link PG - PLC via 1st or 2nd Serial Interf ac e. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 16
11.4 Paral lel Operation of Tw o Ser i al PG Inter faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 17
11.4.1 Ins tallation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 19
11.4.2 Operatio n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 19
11.4.3 Sequence in Certain Operating Situations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 21
11.5 PG Functions via the S5 Bus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 27
11.5.1 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 27
11.5.2 How the PG Functions W ork via the S5 Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 29
11.5.3 Ins tallation and Getting Start ed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 31
11.5.4 Condition Codes Indicating Problems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 - 35
12 Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 - 3
13 Indexes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 - 3
Contents
CPU 948 Programming Guid e
viii C79000-G85 76-C84 8-04
Page 9
Cont ent s of Chapt er 1
1.1 Area of Application for the S5-155U with the CPU 948 . . . . . . . . . . . . . . . . . . . . . . . . 1 - 4
1.2 T yp ic a l Mode of Operation of a CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 5
1.3 The Programs in a CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 7
1.4 Which Operands are available to the User Program? . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 11
1.5 How much Memory is available for the User Program? . . . . . . . . . . . . . . . . . . . . . . . 1 - 14
1.6 How to Ta ckle Programming? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 15
1.7 Programming Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 18
1.8 Converting User Programs of the CPU 928B for the CPU 948. . . . . . . . . . . . . . . . . . 1 - 19
1
Introduction
CPU 948 Program ming Guide C79000-G85 76 -C848-04
1 - 1
Page 10
Contents
CPU 948 Programming Guid e
1 - 2 C79000-G85 76-C84 8-0 4
Page 11
1Introduction
Aims of the manual
This manual is intended to provide specialized information about programm ing the CPU 948 fo r user s who alre ad y have basic knowledg e of progr amm in g PLCs and wa nt to use the CPU 948 in the S5-155U progra m m ab le co ntr oll er. If you do not yet hav e this ba sic knowledg e, we strong ly advi se yo u re ad the docum e nta tion introduc i ng th e progra m m ing langua ge ST EP 5 /3/ or take par t in a course at our training cent er . SIEME NS prov ides co mp re hensive training for SIMATIC S5. For m ore deta ile d informa tion, contac t your local SIEMENS of fice.
Contents of Chapter 1
Chapter 1 expl ai ns how to use the ma nua l and de a ls wit h th e are as of applicati on of the S5-155U prog ra mma bl e cont rol ler wi th the CPU 948 and its structure. The chapter explains the typical mode of operation of a CPU and the structure of the CPU prog ram. You will also fin d a few sugge sti ons about how to tackle programm ing and will learn som e of the fe ature s of th e CPU 948 which are import an t for progr amm in g. If you have already work ed with the CPU 946/947 and would like to know the di fferences between t hese module s and the CPU 948, re fer to Section 1.8.
Chapter 1 also in form s you a bou t diffe re nc e s betwee n ve rsi ons A01 and A02 of the CPU 948 and explains points you should remembe r when converti ng "928B" pr ograms for the CPU 948.
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 3
Page 12
1.1 Area of Application for the S 5-155U with the CPU 948
SIMATIC S5 family
The S5-155U prog ramm abl e cont rol le r bel ongs to the fa mily of SIMATIC S5 progr am m a ble c ont rol le rs. With the CPU 948, it is the most powerful multiprocessor uni t fo r proce s s autom atio n (ope n and closed loop c ont rol, signall in g, mon itoring, logging). Owing to its modularity and high perform an ce , it can be used for medium to extre m ely l arge con tro l system s as well as for comp le x automation tasks at the pla nt and process supervision level.
Suitability
The S5-155U wit h the CPU 948 is particu larl y suit able for the following:
•• Tasks requiring fast bit and word-oriented processing and fast
reaction times, i.e. with extremely fast open and closed loop controls. Examples of this are fa st proce sses i n m ec hanical engineering (bottling plant, packing machines or s im ilar s ystems) and in the automobile industry.
•• Tasks requiring an extremely high storage capacity and fast access
times, e.g. in the autom obi le industry , proc ess an d plant engineering.
•• Tasks requiring fast communication with other CPUs installed in
the PLC and ope rati ng in the mult ipr oc essor mode a nd with CP modules (e.g . when conn ec ted to bus system s, host compu ters, for visuali zat io n, ope ra tion a nd m oni tor ing).
•• Complex tasks which can be handled e ffi cie nt ly and clea rl y using
the high level languages C and SCL.
Area of Application for the S5-155U with the CPU 948
CPU 948 Programming Guide
1 - 4 C79000-G8576-C848-04
Page 13
1.2 Typical Mode of Operation of a CPU
Mode of operation of a CPU
The followi ng mode s of ope ra tion are possib le in a CPU:
Cyclic processing
This is the main part of all ac t iviti e s in the CPU. As the name already says, the sam e op er at io ns are re pe a te d in an endl e ss cyc le .
Cyclic pro ce ssing can be divide d into three ma in phases, as follows:
Phase Sequence
1
All the input mo dul es assi gne d to the CPU are scanned by the system program and the valu es re a d in are stored in the process image of the inputs (PII).
2
The va lue s contained in the PI I ar e processed by the use r progra m and the values to be output are entered in the process ima ge of the out put s (PIQ).
3
The values contained in the process image of the outp uts a re outp ut by the system program to the output modules assigned to the CPU.
Cyclic processing
Interrupt-driven processing
Time-controlled processing
1. 2. 3.
Read in process image of the inputs
Output process image of the outputs
&
&
=
1
I1.5
I1.6
I1.4
I1.3
Q3.1
Evaluate input signals, set output signals
Input I 1.3
Input I 1.4
Input I 1.5
Output Q 3.1
Output Q 2.0
Output Q 4.7
CPU Process
Typical Mode of Operat ion of a CPU
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 5
Page 14
Time-controlled processing
In addition to the cyclic processing, time-controlled processing is also avail able for proce sse s req uir ing contro l sign als at con sta nt interval s, e. g. non-t im e cr itic a l moni tor ing func tions pe rfo rm ed every second.
Interrupt-driven processing
If the reaction to a pa rticular process signa l m ust be pa rticularly fast, this should be handled with interrup t-d riven proc essing. W ith, for example, a system interrupt, triggered via an interrupt generating module, you can activate a special processing section within your program.
Processing according to priority
The types of proc essin g liste d above are handled by the CPU according to their priority.
Since a fast reaction is required to a time or interrupt event, the CPU interrupts cyclic processing to handle a time or interrupt event. Cyclic processing the refo re has the lowe st pri ori ty.
Whether or not the time-controlled processing is more important than the interrupt co ntr oll e d proce s sing de pe nd s, amo ng ot he r things, on the particu lar task. For th is reason , the priorit y of time and interrupt -dri ven pro cessing on the CPU 948 can be selec ted .
Typical Mode of Operation of a CPU
CPU 948 Programming Guide
1 - 6 C79000-G8576-C848-04
Page 15
1.3 The Programs in a CPU
The program exi stin g on every CPU is divid ed into the fol lowing :
•• the system program
and
•• the user program.
System program
The system program organize s all the func tions a nd s equence s of t he CPU which do not involve a speci fic cont rol t ask (re fer to Fig. 1-2).
Update process image of the inputs
Output process image of the outputs
System
program
Call user processing (inter­faces)
Execute start-up
Handle errors
Communication with the PG
Manage memory
Fig. 1-1 Tasks of the system program
The Programs in a CPU
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 7
Page 16
Tasks
The tasks include the following:
1)
•• cold and warm restart,
•• updating the process im a ge of the input s and ou tpu tt ing the
proce ss ima ge of th e outpu ts,
•• calling the cyclic , time-con trolled and int errupt-driven program s,
•• detection and handling of errors,
•• memory management,
•• communication with the programmer (PG).
User interfaces
As the user, you can influence the react ion of the CPU to particular situations a nd error s via specia l interfa ce s to the system pro gra m .
Storing the system program
After switching on the powe r supply to the PLC (POWER UP) the system program is read from the EPROM to the internal operati ng system RAM.
System program defaults
The following chapters, except for Chapter 7, describe the default system reaction to proce ss event s or er rors. Depen din g on th e
defaults, the CPU cha nge s to the stop mode if an opera ti on code error occurs and th e erro r orga ni zat io n blo ck is not loade d.
Modifying the defaults
You can modify the system response by assignin g pa rame ter s for the data bl oc k D X 0. Chapter 7 describes the system response following modif ication.
1)
When operating with several CPUs (multiprocessing) further tasks are involved.
The Programs in a CPU
CPU 948 Programming Guide
1 - 8 C79000-G8576-C848-04
Page 17
User program
Tasks
The user program cont ai ns all the func tions re qui re d for proc e ssing a specific control task. In gene ra l terms, these functi ons can be assigned t o the in terfa c e provi de d by the system pro gra m for th e various ty pes of proce ssi ng, as follows:
Type of processing Task
Cold and warm rest ar t To provide the co ndi tions unde r whi c h
the other processing functions can start from a define d statu s foll owin g a cold or warm restart of the control system (e.g. assigning spec if ic va lues to signa ls).
Cyclic processing Constant ly repeated si gnal processin g
(e.g. logic operations on bi nary s ignals, readi ng i n and analyzing analog values, specifying binary signals for output , outputt ing analog value s) .
Time-c ont rol le d processing
Special, ti me-dependent processing with the following time conditions:
- faster than the average cycle,
- at a time interval greater than the averag e cyc le time,
- at a specified point in time.
Interrupt-driven processing Special, fast re actions to certain process
signals.
Error reaction Handling pro blem s with in the norm a l
sequenc e of the pr ogra m .
The Programs in a CPU
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 9
Page 18
Structure
Storing the user program
After programm i ng the user pro gra m, you mu st load it in the user memory of the CPU 948 (di rec tly from the PG) or via a memo ry car d whose contents are copied to the user memory by an OVERALL RESET of the CPU.
Interfaces to the system program
Organiza tio n blocks a re availa bl e as inter fa ces to the system progra m for the special type s of proc essi ng.
User memory
Code blocks
Data blocks
Organization blocks
OB
DB
DX
PB
FB/FX
SB
FB 8 SEGMENT 1
NAME :TRANS 0005 :L IB 3
0006 :T FW 200 0007 :C DB 5 0008 :DO FW 200 0009 :L DW 0 000A :T QW 6 000B :BE
1: KH = 0101; 2: KF = +120; 3: KS = xy; 4: KY = 4.5; 5: KG = 6: KM = 7:
1: KH = FFFF; 2: KH = FFFF; 3: KH = FFFF; 4: KH = FFFF; 5: KH = FFFF; 6: KH = FFFF; 7:
STEP 5 operations
static or dynamic data (bits, bytes, words, double words)
static or dynamic data (bits, bytes, words, double words)
STEP 5 operations
STEP 5 operations
STEP 5 operations
Program blocks
Function blocks
Sequence blocks
&
&
=
1
I1.5
I1.6
I1.4
I1.3
Q3.1
=
1
F 50.1
F 50.2
F 50.3
Q5.3
F1.7
I2.6
S
RQ
I1.3
User program
Fig. 1- 2 Struct ur e of a ST E P 5 use r pr ogr am
The Programs in a CPU
CPU 948 Programming Guide
1 - 10 C79000-G8576-C848-04
Page 19
1.4 Which Operands are av aila ble to t he User P rogr am?
The CPU 948 provi de s the foll owi ng ope ra nd area s for pro gra m ming:
•• process image and I/Os
•• flags (F flags and S flags)
•• timers/counters
•• data block s
Process image of the inputs and outputs PII/PIQ
Character istics Size
The user progra m can ac ce ss the followi ng da t a type s in the process image extremely quickly:
- single bits,
- bytes,
- words,
- double words
128 bytes each fo r inputs and outputs
I/O area (P area)
Character isti c s Size
The user progra m can ac cess t he I/O m odu les directly via the S5 bus.
The following da ta ty pe s are possible:
- bytes,
- words.
256 bytes each fo r inputs and outputs
Extended I/O area (O area)
Character isti c s Size
The user progra m can ac cess t he I/O m odu les directly via the S5 bus.
The following da ta ty pe s are possible:
- bytes,
- words.
256 bytes each fo r inputs and outputs
Which Operands are available to the User Program?
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 11
Page 20
F flags
Character isti c s Size
The flag ar ea is a mem ory a re a whic h th e user program can acc e ss extr em e ly quickl y with c er tain operations. The flag area should be used idea ll y for wor kin g data require d often.
The following data types can be accessed :
- singl e bits,
- byte s,
- words,
- double words.
Single flag bytes can be used as inter pr oc essor communicati on fl ags (IPC fla gs) to exc ha nge data between the CPUs in the multiprocessor mode (refe r to Chapter 10). IPC flags ar e update d by the system program at the end of the cyc le via a buffer i n the coordina to r or CP/IP.
2048 bits
S flags (extended flag area)
Character isti c s Size
The CPU 948 also contains an additiona l flag area, the S flag area. The user progra m can also a c cess thi s are a extremely quickl y as wi t h the F flag s.
S flags cannot howe ver by used as actual ope r ands with function bloc k ca ll s nor as IPC fla gs for data exchange bet ween the CPUs. T he bit te st operations of the CPU 948 can also not be used with the S flags.
These flags can only be used with the PG syste m software "S5-DOS" from versio n 3.0 upwa rds or "S5-DOS/MT" from versio n 1.0 upwa rds.
32 768 bits
Which Operands are available to the User Program?
CPU 948 Programming Guide
1 - 12 C79000-G8576-C848-04
Page 21
Timers (T)
Character isti c s Size
The user program loads ti mer cells with a time value between 10 ms and 9990 s and by means of a start operation, decrements the timer from this value at the preselec ted inte rval s until it rea che s the value ze ro.
256 timer
cells
Counters (C)
Characteristics Size
The user progra m loads c ount e r cel ls wit h a start value (max. 999) and t hen increments or de crements them.
256
counters
Data words in the current data block
Character isti c s Size
A data block contains constants and/or variables in the byte, word or double word format. With STEP 5 operations, you can always access the "current" data block (refer to Section 2.4.2). The following data types can be accessed:
- single bits,
- bytes,
- words,
- double words.
256
words
1)
1)
In data blocks with a length greater than 256 words, you can only access data words with the numbers > 255 with operations for absolute memor y access (refer to Chapter 9).
Which Operands are available to the User Program?
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 13
Page 22
1.5 How much Memory is available for the User Program?
For stori ng lo gic and da ta bloc ks, t he CPU 948 onl y ha s the user memory in the internal RAM.
The CPU 948 is avail able wit h two ver sions of t he user m emo ry:
•• Version 1: with 640 Kbytes,
•• Version 2: with 1,664 Kbytes.
How much Memory is available for the User Program?
CPU 948 Programming Guide
1 - 14 C79000-G8576-C848-04
Page 23
1.6 How to Tackle Pr ogramming
If you are an experi enc ed user, you have proba bl y foun d the most suitable me tho d for cre a ti ng pro gra m s for yourse lf an d you ca n skip this section.
Less experi en ce d rea de rs wil l find ti ps for de sig nin g, program m in g, testing and star ti ng up yo ur ST EP 5 pr ogra m .
Implementation stages
The implementation of the STEP 5 control program can be divided into three stag es :
Stage Activity
1 Determining the technological task 2 Designi ng th e progra m 3 Crea ting, testi ng a nd sta rt ing the prog ram
Recursive procedure
In practice, you will recognize that certain steps must be repeated (recursi ve procedure), e.g. wh en you realize that more signals are required to improve the handling of the task.
Stage 1
Dete r m ining the te c h n o l ogical tas k:
Stage Activity
1 Creat e a general block diag ram outlining the con tro l
tasks of your process.
2 Creat e a list of t he inpu t and out put signa l s re qu ire d
for the task.
3 Improve the bl ock di agra m by assign ing the signa ls
and any particular time conditions and/or counter statuse s to the individual blocks.
How to Tackle Programming
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 15
Page 24
Stage 2
Designing the program
Stage Activity
1 Based on the improved block diagra m , dec id e on the
types of processing requir ed of your program (cyc lic proce ssing, time-controlled processi ng e tc. ) an d sel ect the OBs required for this.
2 Divide the typ es of proc essin g into tec hno log ica l
and/or functional units.
3 Check whether the un its can be assigned to a program
or funct ion bloc k and se le c t th e bloc ks you re quire (PB x, FB y etc.)
4 Find out which timers, counters and data or results
memory yo u re qui re.
5 Specify the tasks for each of the propose d lo gic bloc ks
and the da ta for fl ags an d data bloc ks whi ch may be required. Create flow diagrams for the logic blocks.
Notes on the scope of cyclic processing
When deciding on the types of proc essin g, keep the followi ng conditions in mind:
•• The cycle must run through qui ck ly enou gh. Th e proc ess sta tuse s
must not change more qui ck ly than the CPU c an reac t. Oth erwise the proc e ss can get out of control.
•• The maximum reaction time should be taken as twice the cycle
time. The cycle time is determined by the cyclic processing of the system program and the type and scope of the user progra m. It is often not consta nt , sinc e the cycl ic user progr am may be interrupt e d whe n time a nd inte rru pt- dri ve n prog ra m sect ions are called.
How to Tackle Programming
CPU 948 Programming Guide
1 - 16 C79000-G8576-C848-04
Page 25
Stage 3
Creating , test ing and starti ng up the program :
Stage Activity
1 Decide on the type of representation for the logic
blocks (LAD, CSF or STL, refer to Chapter 2). Remember that function blocks can only be created in the STL method of representation.
2 Program all logi c and da t a bl ocks (please refer to your
STE P 5 manual).
3 Start up the blo ck s one aft er the oth er (you ma y ha ve
to program a different OB for each individual step, to call the logic bl oc ks): 1a: load the block(s) 1b: test the block(s)
(For more deta ile d inf orm a tion pl ea se refer to your STEP 5 manual and Chapter 11).
4 When you ar e certai n t hat all th e logic bl ocks run
correctly and all the data can be correctly calculated and store d, you c an sta rt up your who le prog ra m.
Note on test strategies
When you ac tu al ly star t up yo ur pro gra m for th e fi rst tim e in genuine process ope ra tion, i.e . with real inpu t and m ore impor ta nt ly outpu t signals, is a decisio n that must be left up to your sel f or to a tea m of expert s. The more compl ex the pro cess, t he great er the ri sk and there for e the greater the care required when starting up.
How to Tackle Programming
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 17
Page 26
1.7 Programming Tools
Suitable PGs
The following programmers a re available for creating your user program, PG 685, PG 710, PG 730, PG 750 and PG 770. You can check on the performance and characteristics of these devices in the catalog ST 59 /9/.
Note
If you wish to use the full range of performance of the CPU 948 in your automati on softwar e, (part icul a rly the DX 0 scree n, the "Output ISTACK" screen, the display with the "memor y configu rati on" fu nc ti on and the PG functions via the ba ckpl an e bus) you require the PG syste m softwa re "STEP 5/ST" from version 6.3 upward s or "STEP 5/ MT" from version 6.0 upwa rds plus the "Delta diske tte CPU 948" a nd a PG 7xx.
Suitable software
You can create user programs for SIMATIC S5 progr am mabl e controller s as follows:
•• I n th e STEP 5 programming langua ge,
Here you req uir e the STEP 5 prog ra mmi ng pa c ka ge al ong wi th the system software STE P 5/ST or STEP 5/MT (de script ion, refer t o /3/ in Further Rea din g),
or
•• In a higher program ming l an gua ge:
If you are familiar with programming in higher programming languages, you can also form ula te your S T EP 5 program for the CPU 948 as follows:
- SCL (refer to /12/ in Further Read ing , the SCL compi le r is
contained in the PG software "S5-DOS/MT " fr om version 6 upwards. ) or
- C with S5 C compiler (refer to /13/ in Further Reading).
You can also c re ate prog rams for seque nc e contr ol systems in a graphic representat ion usi ng t he GRAPH 5 programming package (descri ption, refe r to /4/ in Further Re a din g).
Depending on the task, you can also incorporate "off-the-peg" standar d funct ion blocks in your use r pro gra m. The performance an d characteristics of these blocks are described in the catalog ST 57 /11/.
Programming Tools
CPU 948 Programming Guide
1 - 18 C79000-G8576-C848-04
Page 27
1.8 Converting User Programs of the CPU 928B for the CPU 948
The following section inform s y ou about the poi nts you should remember when you conve rt user progr ams writ te n for the CPU 928 B for use on the CPU 948.
Operations
In the fol lowing operations, note the differences in the execution and handli ng (a m ong ot her things the differ en t m emo r y uti li z at io n).
Operations CPU 928B CPU 948
IA/RA (disa ble/ en ab le interrupt s )
All proce s s interrupts are disabled or enabled
Only the process int errupts via input byte IB 0 are disabled or enabled. Instead of these op erations, use the special func tion OBs OB 122 or OB 142.
LIR/TIR 16 bit long addresse s are used. 20 bit long addresse s are use d.
Adaptation is nec essa ry.
Block transfe r ope ra ­tion TNB
16 bit long addr esse s are used. The opera ti on do es not exist.
Use TNW for block transfer from the 8-bit to the 8-bit area.
Block transfe r ope ra ­tion TNW
- 16 bit long addresses are used.
- Block transfe rs from the 8- bit to the 8-bit area and vi ce versa are possible.
- 20 bit long addr esse s are used . Adaptation is necessary.
- only block transfe rs fro m the 8-bit to th e 8- bit ar ea a nd from the 16-bit to the 16-bi t are a s possi ble with TNW.
- for the block transfer from
the 8-bit to the 16-bi t are a use the operation TXB,
- for the block transfer from
the 16-bit to the 8-bi t are a use the operation TXW.
(TXB and T XW do not e xi st on a CPU 928B)
All operations with the BR register
The BR regist er is 20 bits wide. The BR regi ste r is 32 bi ts wide .
Adaptation is nec essa ry.
Converting User Programs of the CPU 928B for the CPU 948
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 19
Page 28
Timer processing
CPU 928B CPU 948
The timers are updated during start-up.
The timers are only updated in the RUN mode (Reason: compatibility with CPU 946/947)
FB 0 as cycle block
CPU 928B CPU 948
If no cycle bloc k OB 1 exist s, the system program cal ls FB 0 cyclically, provided it is loaded.
Only OB 1 can be used for cyclic processing. If you have programmed FB 0, cr eat e an OB 1 in whi c h F B 0 is ca l led.
Default priorities
CPU 928B CPU 948
Process inte rrupts have higher priority than t imed interrupts.
Timed interrupts have priority over process int er rupt s via IB 0 or system interrupts. You can change the pri ori ty w i th t he parameters in DX 0.
Data block DB 0 (block address list)
CPU 928B CPU 948
The block address li st contai ns the direct star t addre sses of the blocks.
The block addre ss l ist conta in s the seg ment addresses of the blocks. T o obt ain th e sta rt addres s of a bloc k, its se g me nt address must be shifte d 4 bits to the left.
Converting User Programs of the CPU 928B for the CPU 948
CPU 948 Programming Guide
1 - 20 C79000-G8576-C848-04
Page 29
Data block DX 0
You must crea te a new DX 0 data bloc k (see Cha pt e r 7), since the DX 0 for the CPU 928B has a different stru cture and set tings.
Using the RT area
With the CPU 928B, the RT area is not used by the system program, with the CPU 948 it is used to some extent by the handling bloc ks. You can only use the RT area for yo ur use r progra m whe n you do not use any standard FBs a nd any PG funct ion s via SINEC H1 and the S5 bus.
Organization blocks
The numbe r and function of th e erro r an d spec ial func t ion OBs are not the same on the CPU 928B and CPU 948:
Error OBs
The followi ng erro r OBs of the CPU 948 respo nd diffe re ntly fr om their namesakes on the CPU 928B:
OB Function Error IDs
OB 19 OB 26 OB 27
Same as on CPU 928
Different from CPU 928B
OB 28 OB 29 OB 30 OB 31
Func ti on di ffe rent from that on CPU 928B
Special function OBs
OB Note
OB 110 OB 152
OB 160 to 163
OB 170 OB 190 to 193 OB 216 to 218
OB 220 and 221
OB 224 OB 226 to 228 OB 240 to 242
OB 250 and 251
These OBs do not exist on the CPU 948
OB 111
OB 112
OB 113
OB 120
OB 121
OB 122
OB 123
On the CPU 948, the OB is replaced by :
OB 131 OB 132 OB 133 OB 122 OB 141 OB 142 OB 143
Converting User Programs of the CPU 928B for the CPU 948
CPU 948 Programming Guide C79000-G8576-C848-04
1 - 21
Page 30
OB Note
OB 122 Parameter assign ment is differe nt from that of the
CPU 928B OB 122 (reason: compatibility with CPU 946/947).
OB 180 In contrast to the CPU 928B , the acc ess wind ow of
the CPU 948 can only be shifted by a multiple of
16.
OB 200 OB 202 to 205
(multiprocessor
communication)
In contrast to the CPU 928B, these CPU 948 OBs change the content of ACCU 4.
R64 controller software
The R64 controller software canno t be run on the CPU 948.
Standard FBs
Generall y, the sta nda rd func tion bloc ks used on the CPU 928 B (e.g. for IPs) must be rep la c ed by those for the CPU 948. The HDBs are an exception the se can be taken from the CPU 928B (see Sect io n 1.8.1).
Converting User Programs of the CPU 928B for the CPU 948
CPU 948 Programming Guide
1 - 22 C79000-G8576-C848-04
Page 31
Cont ent s of Chapt er 2
2.1 STEP 5 Programming Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 4
2.1.1 The LAD, CSF, STL Methods of Representation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 4
2.1.2 Structured Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 5
2.1.3 STEP 5 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 6
2.1.4 Number Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 8
2.1 .5 STEP 5 Blocks and Storing them in Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 12
2.2 Program , Organi zation and Seq uence Block s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 16
2.2.1 Organization Blocks as User Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 18
2.2.2 Organiz atio n Blocks for Special Function s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 22
2.3 Function Bl ocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 23
2.3.1 Structu re of Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 24
2.3.2 Programming Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 26
2.3.3 Calling Function Blocks and Assigning Parameters to them . . . . . . . . . . . . . . . . . . . . 2 - 28
2.3.4 Special Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 33
2.4 Data Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 35
2.4.1 Creating Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 37
2.4.2 Opening Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 38
2.4 .3 Spec ial Data Bl o cks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 - 41
2
User Program
CPU 948 Program ming Guide C79000-G85 76 -C848-04
2 - 1
Page 32
Contents
CPU 948 Programming Guid e
2 - 2 C79000-G85 76-C84 8-0 4
Page 33
2User Program
The fol lowing chapter exp la ins the comp onents th at make up a STEP 5 user progra m for the CPU 948 a nd how it can be struc tur ed .
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 3
Page 34
2.1 STEP 5 Programming Language
With the STEP 5 programming language, you convert automation tasks into programs that run on SIMATIC S5 programmable controllers. You can program simple binary functions, complex digital functions and arithmetic operations including floating point arithmetic using STEP 5.
Types of operation
The operations of the STE P 5 pr o gra m mi ng l an guage are divide d int o the followin g groups:
Basic operations
•• you can use these operations in all log ic block s
•• methods of represen ta ti on: ladde r di a gra m (LAD), control syste m
flowcha rt (CSF), statement list (STL).
Supplementar y oper ations and system operat ions:
•• can only be used in function bloc ks
•• only statement list (STL ) m e tho d of re pre se nta t ion
•• system operations: only exper ienc e d STE P 5 progra m me rs shoul d
use system opera ti ons
2.1.1 The LAD, CSF, STL Methods of Representation
When programming in STEP 5, you can choose between the three methods of representation ladder diagram (LAD), control system flowchart (CSF) and statement list (STL) for each individual logic block. You can choose the m ethod of re present ation that best suits your particular application. The machine code MC5 that the programm e rs (PGs) gener ate is the same for all thre e metho ds of re pre sen tati on. If you follo w cert ai n rul es when pr ogra m m ing in STEP 5 (se e /3/), the programmer can tran slate your user pr ogram from one method of repr ese nt at ion into any other.
Graphic representation or list of statements
While the ladder diagra m (LAD) and control syste m flo wchart (CSF) methods of re pre sen tati on re pr ese nt your ST EP 5 program graphically, statement list (STL) represents STEP 5 operations individ ua lly as m ne mo nic a bbre vi a tions.
STEP 5 Programming Language
CPU 948 Programming Guide
2 - 4 C79000-G8576-C848-04
Page 35
Graphic representation of sequential controls
GRAPH 5 /4/ is a programming language for graphic represen tati on of sequential controls. It is at a higher level than the LAD, CSF, STL methods of represen tation. A program writt en in GRAPH 5 as a graphic representation is automatically converted to a STEP 5 program by the PG.
2.1.2 Structured Prog rammin g Using STEP 5, you can structure your program by divi din g it into
self-conta i ned prog ra m sect ions (blo ck s) . This divi sion of your program cl a rifies the essential program structures making it easy to recognize the system part s that are rela ted wi thin the softwa re .
Ladder diagram
Statement list
Control system flowchart
Programming with graphic symbols like a circuit diagram
Programming with graphic symbols
IEC 117-15 DIN 40700 DIN 40719 DIN 19239
DIN 19239 DIN 19239
STL CSFLAD
A AN A ON O =
&
> = 1
I I I I I Q
Programming with mnemonic abbreviations of function designations
complies with complies with complies with
Fig. 2-1 Methods of repres enta tion in the STEP 5 programm i ng langua ge
STEP 5 Programming Language
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 5
Page 36
Structured programming offers you the followin g adva ntage s:
•• simple and clear cre a ti on of pr ogra m s, e ve n larg e on es
•• standardization of progr am pa rt s
•• simple program organization
•• easy program changes
•• simple, section by sect ion progr am test
•• simple system start-up
What is a block?
A block is a part of th e user pro gra m that is disti ngui shed by its function, struct ure or application. You c an differentiate between blocks that contain statements (code) i.e. organization blocks, program blocks, function blocks or sequence block s, and blocks t hat contain dat a (da ta blocks).
2.1.3 STEP 5 Operations A STEP 5 operation is the s ma llest independe nt unit of the user program.
It is the work specification for the CPU. A STEP 5 operation consists of an operation and an ope rand as s hown in the following exa mpl e:
Example
Operation code
Operation
Operand
Parameter
:O F 54.1
(what is to be done?)
(with what is the operation to be done?)
STEP 5 Programming Language
CPU 948 Programming Guide
2 - 6 C79000-G8576-C848-04
Page 37
Absolute and symbolic operands
You can enter the operand absolutely or symbolically (using an assignme nt list ) as shown in the follo wing exam pl e:
Absolute representation: :A I 1.4 Symbolic representation: :A -Motor1
For more infor mat ion on abso lute and symbo lic programming, refer to your STEP 5 m a nua l.
Application of STEP 5 operations
The STEP 5 operation set enables you to do the following:
•• set or reset and c om bin e bi na ry va l ue s l ogi ca l ly
•• load and transfer values
•• compare value s an d proc e s s the m ari thmetically
•• specify timer and count e r va lues
•• convert number represent at io ns
•• call blocks and execute jumps within a block
and
•• influence progra m exec ut io n
Result of logic operation RLO
The central bit for controlling the program is the result of logic oper ation RLO. This is obta in ed as a re sult of binary logic op er at io n s and is infl ue nc ed by some opera t ions. Section 3.5 describes the whole S T EP 5 operation set and explains how the RLO is obtained. This section a lso inc ludes programm ing examples for individual STEP 5 operations.
STEP 5 Programming Language
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 7
Page 38
2.1.4 Number Representation To allow the CPU to logically combine , mod ify or comp are nume ric al
values, th ese values must be located in the ac cumulators (working registers of the CPU) as binary numbers. Depending on the operations to be carried out, the following number represen tations are permitted in STEP 5: Binary numbers: 16-bit fixe d poi nt num be rs
32-bit fixe d poi nt num be rs
32-bit floa ti ng po int num be rs (wit h a 24-bi t mantissa)
Decimal numbers : BCD-code d numb er s (sign and 3 digit s)
Numerical input on the PG
When you use a program m er to input or di spla y numbe r val ue s, you set the data fo rm at on th e progra m m er (e.g. KF or fixe d poi nt) in which you inte nd to ente r or display the value s. The progra m me r conver ts the in te rna l rep re sent a ti on in to t he form you ha ve re que ste d.
Permitted operations
You can carry out all arithmetic operations with the 16-bit fixed point num bers and floating point numbers, incl uding compariso n, addition, subt ra ct io n, multi pl ica ti on a nd di visi on.
Note
Do not use BCD-coded numbers for a rithmet ical opera tions, since this leads to incorre ct result s.
Use 32-bit fi xed poi nt num be rs to e xe cu te co mp ar ison op er at io ns. These are also necessar y as an inte rmed iate leve l when conve rting numbers in BCD c ode to floati ng po int numbe rs. With t he ope ra tio ns +D and - D they can also be use d for addition an d su b tr action. The STEP 5 programming language also has conversion operations that enable you to convert num bers di rec tly to t he most i mportant of the other numeric al representations.
STEP 5 Programming Language
CPU 948 Programming Guide
2 - 8 C79000-G8576-C848-04
Page 39
16-bit and 32-bit fixed point numbers
Fixed point numb er s are whole bina ry numb er s with a sign.
Coding of fixed point numbers
Fixed point nu mbers are 16 bit (= 1 word) or 32 bit (= 2 words) in binary representation. Bit 15 or bit 31 contain s the sign.
•• ’0’ = positive number
•• ’1’ = negati ve number
The two’s com plem e nt repre sent a ti on is use d for nega t ive num bers.
PG input
Input of 16-bit fixed po int numbe r data forma t at the PG:KF
Input of 32-bit fixed po int numbe r data forma t at the PG:DH
Permitted numerical range
16-bit fixe d point nu mb er
-32768 to +32767 (16 bits)
32-bit fixe d point nu mb er
-214748364 8 to +2147483 647 (32 bits) (8000 0000H to 7FFF FFFFH)
Using fixed point numbers
Use fixed po int num be rs for sim pl e calc ul a tions an d for c om pa ri ng number value s. Si nc e fixed poi nt numbe rs are alwa ys whol e numb er s, rememb er tha t the resul t of divi di ng two fixe d po int num be rs is also a fixed point num be r without decimal plac e s.
Floating point numbers
Floating point numbers are positive and ne gative fractions . They always occ upy a double word (32 bit s). A floating po int num ber is represent ed as an expone nt ia l numb er . The mant issa is 24 bits long and the exp one nt is 8 bits long. In the CPU 948, the defa ul t m anti s sa is 24 bits lo ng (bits 0 to 23) for adding, subt ra ctin g, multi pl yin g and div idi ng. The exponent indicates the order of magnitude of the floating point number. The sign of the exponent tells you whether the value of the floating point number is greater or less than 0.1.
STEP 5 Programming Language
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 9
Page 40
Using floating point numbers
Use floating point num be rs for solving e xte nsi ve calcul a tions, especiall y for mul ti plic atio n and div isio n or when you are working with ver y la rge or ve ry sm al l nu mbers!
Accuracy
The mantissa indi cat e s the acc ura c y of the floa ting po int numbe r a s follows:
•• Accuracy with a 24-bit mantissa:
2
-24
= 0.000000059604 (corresponds to 7 decimal places)
If the sign of the mantissa is "0" the nu mber is positive ; if the sign is "1" it is a negative number in its two’s complement representation. The floating point value ’0’ is represented as the binary value 80000000H (32 bits, see below).
Coding floating point numbers
Coding a floating poi nt numbe r:
31 30 24 23 22 0
V26 ... . ... 20V2-1 .... . . . . . ... 2
-23
Exponent Mantissa
Specification of the data format for floating point numbers at the PG: KG
Permissible numerical range
± 0.1469368 x 10
-38
to ± 0.1701412 x 10
39
Input/output on PG
a) in a logic block:
You want to load the num be r N = 12.34 567 a s a floa ti ng poi nt number.
Input:
:LKG1234567+ 2
STEP 5 Programming Language
CPU 948 Programming Guide
2 - 10 C79000-G8576-C848-04
Page 41
b) in a data block:
You want to define the num be r N = - 0.005 as a floati ng po int constant .
Input:
6: KG = - 5 - 2
Numbers in BCD code
Decimal numbers are represented as numbers in BCD code. With their sign and three digits, they occupy 16 bits (1 word) in an accumulator as shown in the following example: 15 12 11 8 7 4 3 0
V V V V hundreds tens ones
The individual digits are positive 4-bit binary numbers between 0000 and 1001 (0 and 9 decimal). The left bits are reserved for the sign as follows: Sign for a positive number: 0000 Sign for a negative number: 1111
Permissible numerical range
-999 to +999
PG display after you e nt er the line :
:L KG + 1234567 + 02
Mantissa wit h sign Expo ne nt (base 10)
with sign
Value of the number input: +0.1234567 x 10
+2
= 12.34567
PG display after you e nt er the line :
6: KG =- 5000 000 - 02
Mantissa wit h sign Expo ne nt (base 10)
with sign
Value of the number input : - 0.5 x 10
-2
= 0.005
STEP 5 Programming Language
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 11
Page 42
2.1.5 STEP 5 Blocks and Storing them in Memory
Identification
A block is identif ie d as foll ows:
•• the block type (OB, PB, SB, FB, FX, DB , DX )
and
•• the block number (number between 0 and 255).
Block types
The STEP 5 programming language differentiates between the following blo ck types:
Organization blocks (OB)
Organizati on blocks are the i nte rface betwe e n the system program a nd the user progra m. They ca n be divide d in to two grou ps as fol lows:
With OB 1 to OB 39, you can control program execution, the restart procedure of the CPU and the reacti on in the eve nt of an error. You program these blocks you rself accordin g to yo ur auto ma t ion task . These OBs are called by the system progra m.
OBs 40 to 100 are block s bel ongi ng t o the ope ra ting system. You must not call t he se bl oc ks.
OBs 121 to 255 contain specia l func tions of t he system progra m . You can call these blo ck s, if req uir ed , in your user pr ogra m .
Program blocks (PB)
You require program blocks to structure your program. They contain program parts di vid ed acc ordi ng t o te chnol ogical and functional criteria. Progra m blocks re pre sen t the heart of the user program.
Sequence blocks (SB)
Sequenc e blocks were originally spe cial program blocks for ste p by step processin g of seque ncer s. In the mea ntim e, howe ve r, seq uenc er s can be programme d with GRAPH 5/4/. Seque nce blocks ha ve therefore lost their origin al si gnificance in STEP 5 . Sequence blocks now represent an ext ension of the program blocks and are used as program bloc ks.
STEP 5 Programming Language
CPU 948 Programming Guide
2 - 12 C79000-G8576-C848-04
Page 43
Function blocks (FB/FX)
You use functio n blo cks to prog ra m freq ue ntly re c urri ng and/ or complex functions (e.g. digital functions, sequence control systems, closed loop c ont rols and signa llin g func t ion s) .
A function blo ck can be cal led sev er al time s by highe r ord er blocks and supplied with new operan ds (assig ned para met ers) at each call. Using block type FX doubles t he ma ximum num ber of pos sible function blocks.
Data blocks (DB/DX)
Data blocks con ta in the (fi xed or vari ab le ) data with whi ch the user program works. Th is typ e of block c ont a ins no ST E P 5 state ment s and has a disti nc tl y different func ti on from the othe r bl ocks. Using block type DX doubl es the number of possible data blo ck s.
Formal structure of the blocks
All blocks consist of the following two parts:
•• a block header
and
•• a block body
Block header
The block header is always 5 words long and contains information for block management in the PG a nd data for the system program.
Block body
Dependi ng on the blo ck type, the block body contains the fol lo w ing:
•• STEP-5 operation s (in OB, PB, SB, FB, FX),
•• variable or constant data (in DB, DX)
and
•• a formal operand list (in FB, FX).
STEP 5 Programming Language
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 13
Page 44
Block preheader
The progra mme r also ge ne ra tes a block preheader (DV, DXV, FV, FXV) for block types DB, DX, FB and FX. These block prehea ders contain infor ma tion abo ut the data form a t (for DB and DX) or the jump labels (for FB and FX). Only the PG can eval uate this informat ion . Conseq ue ntly the bloc k pre he ade rs ar e not tran sfer re d to the CPU memory. You c annot influence the c ontents of the block heade r di rectly.
Maximum length
A STEP-5 blo ck can oc c upy a ma xi mum of 32 767 words in the program mem ory of the CPU (1 word corre spond s to 16 bits).
Available blocks
You can progra m the fol lowi ng bl oc k ty pe s:
Data blocks DB 0, DB 1, DB 2, DX 0, DX 1 and DX 2 contain parameters. These are re served for s pecific functions and you cannot use them as normal data blocks. Data block DX 2 is reserved for the 2nd serial interface and you should not use it.
OB 1 to 39
FB 0 to 255
total 512
FX 0 to 255
PB 0 to 255
SB 0 to 255
DB 2 to 255
total 508
DX 3 to 255
STEP 5 Programming Language
CPU 948 Programming Guide
2 - 14 C79000-G8576-C848-04
Page 45
Block storag e
The programm er stor es all program m ed blo ck s in the progra m memory in the orde r in whic h the y ar e tra nsfe rre d (Fi g. 2-2). Wit h the PG function "tran sf er data blocks A" th e logi c bloc ks are tra nsfe rre d first foll owe d by th e dat a bl oc ks.
The start addr esse s of all stored bloc ks a re pla ced in an addre s s list in data bl oc k D B 0.
Correcting and deleting bl o c k s
When you correct blocks, the old block is declared invalid in the memo ry a nd a new bl oc k is e ntered. Simi larly, when b locks are delete d, they are not really deleted, instead they are decla re d inva li d. Th e spac e they oc cu py is, howe ver, not released and is not available for blocks loaded later.
Note
You can use the COMPRESS MEMORY online func tion to make space for new bloc ks. Th is func t ion opti miz e s the utiliza t ion of the memory by deleting bl ocks marked a s inva l id and shi fti ng valid bl ocks together.
Location of blocks in the user memory
Address 0
FB1
OB1
SB10
DB1
PB1
PB2
Fig. 2-2 Example of block storage in the user memory
STEP 5 Programming Language
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 15
Page 46
2.2 Program, Organization and Sequence Blocks
Program blocks (PBs), org an izati on blocks (OBs) an d sequen ce blocks (SBs) are the sam e with respe c t to prog ramm i ng and c al ling. You can program all three types in the LAD, CSF and STL methods of representation.
Programming
When programming organization, program and sequence blocks, proceed as follows:
Step Action
1 First indicate the typ e of block and t he n the numbe r of the
block that you want to progr am.
The following numbers are available for the type of block l iste d:
- program block s 0 to 255
- sequence blocks 0 to 255
- organization blocks 1 to 39
2 Enter your program in the ST EP 5 pr ogra mm ing langua ge .
When progra mm ing PBs, OBs and SBs, yo u can on ly use the STEP 5 basic operations!
A STEP 5 block should always be a self-co ntai ne d program section. Logic ope ra tions m ust a lwa ys be compl e ted with in a blo ck .
3 Complete your pr ogra m inp ut wi th the bloc k end
operati on "BE".
Block calls
With th e exc e ption of OB 1 to OB 39 you must cal l th e bl oc ks to process them . Use the spe cia l STEP 5 bl oc k call op er atio ns to cal l the blocks. You can progra m block ca lls inside an orga ni zat io n, progr am , function or sequence block. They can be compared with jumps to a subroutine. Eac h ju mp causes a block change. T he ret urn address within the call ing block i s buffe red by the system .
Program, Organization and Sequence Blocks
CPU 948 Programming Guide
2 - 16 C79000-G8576-C848-04
Page 47
Block calls can be unconditi onal or conditio na l as follows:
Unconditional call
The "JU" statemen t belo ngs to the uncondi tiona l opera ti ons. It has no effect on the RLO. The RLO is carried along with the jump to the new block. With in t he new bl oc k, it can be ev aluated but no longe r combined logically.
The addressed block is processed regar dl es s of th e previous resul t of logic oper at io n (RL O - see Sec t ion 3.4).
Exam ple: JU PB 100
Conditional call
The JC statement belon gs t o the conditional operati ons. The addressed block is processed only if the previous RLO = 1. If the RL O = 0, the jump is not executed.
Example: JC PB 100
Note
After the condi ti ona l jump ope ra t ion is exec uted , the RLO i s set to "1" regardless of whether or not the jump to the block is executed.
PB 1 PB 5 PB 10
PB 6
BE
BE
BE
BE
AA
O
I1.0 I2.0
I3.0
JU PB 5 OI5.3
AI1.5 JC PB 6 AI3.2
JC PB 10
OF1.5
Fig. 2-3 Block calls that enable processing of a program block
Program, Organization and Sequence Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 17
Page 48
Effect of the BE statement
After the "BE" stat eme nt (block end), the CPU continue s the user program in the block i n which t he block ca ll was prog ramm e d. Program exe cut ion con tinue s at the STEP 5 sta te me nt fo llowin g the block c al l. The "BE" statement is executed regardless of the RLO. After "BE", the RLO c a n no lo nge r be co mbined logical ly. How e ve r, the RLO or arithm eti c resul t occ urr ing dire ctl y be for e exe c uti on of the BE operation is transfe rr ed to the block whe re the c all origina ted a nd can be evaluated there. When program executio n returns from the bloc k that has been called, the contents of ACCU 1, ACCU 2, ACCU 3 and ACCU 4, the condition codes CC 0 and CC 1 and the RLO are not change d. (Re fe r t o Sect ion 3.5 for more de ta ile d inf orm a ti on a bout the ACCUs, CC0 /C C1 and RLO).
2.2.1 Organization Blocks as User Interfaces
Organiza ti on blocks form the interfaces between t he syst em program and the user pr ogra m. Orga niz ati on bl oc ks OB 1 to OB 39 belong to your user progra m just a s progra m blo ck s. By progra m m ing these OBs, you can inf luenc e the be ha vi or of the CPU duri ng sta rt -up, program ex ecution and in the event of an er ror. T he orga ni za t ion blocks are effe c ti ve as soon as the y are loade d in the PLC mem ory.
This is also possible while the PLC is in the run mode.
Once the syste m program has ca ll e d a spe c ifi c organizat ion block, the user progra m it cont a ins is exe cu te d.
Note
You can progra m blocks OB 1 to OB 39 as user int erfaces and they are call ed autom ati cal ly by the syste m progra m as a reac ti on to certain events.
For test purpose s, you can a lso c all t he se org an iz ati on bl ocks from the user program (JC/JU OB xx x). It i s, however, not possible to trigger a COLD RESTART , e.g. by c alli ng OB 20 .
The followi ng t ab le prov ide s you wi th an ove rv iew of th e use r interfaces (OBs).
Program, Organization and Sequence Blocks
CPU 948 Programming Guide
2 - 18 C79000-G8576-C848-04
Page 49
Organization blocks for controlling program execution
Block Function and cal l criter ion
OB 1 Organizat io n of cyc lic pr ogra m exec utio n; fi rst ca ll afte r a start-up , the n cy clic cal l.
OB 2 OB 3 OB 4 OB 5 OB 6 OB 7 OB 8 OB 9
With DX-0 setting "Proc e ss interr upt se rvic ing via input byte IB 0 =on":
(interrupt ab ilit y at block bound arie s, ca n be set in DX 0)
Call with signal state change in input byte IB 0 in bit: I 0.0 I 0.1 I 0.2 I 0.3 I 0.4 I 0.5 I 0.6 I 0.7
OB 2 OB 3 OB 4 OB 5
OB 6 OB 9
With DX-0 setting "Proc e ss interr upt se rvic ing via input byte IB 0 = off":
(interruptability at operation or block boundaries, can be set in DX 0)
Call via inte r ru pt l ines of the S5 bus: System interrupt INT X (INT A, B, C or D, depends on slot ) System interrupt INT E System interrupt INT F System interrupt INT G
Dela y e d i n terrupt Clock-c ont rolled interrupt
OB 10 OB 11 OB 12 OB 13 OB 14 OB 15 OB 16 OB 17 OB 18
Organizat ion of tim e- contr oll e d progra m exe c ution (t ime d inte rru pt) with selectable basic clock rate (default T = 100 ms) and clock distri but or (d ef au lt cor resp onds to 150U) in da ta blo ck DX 0; Calls as follows:
Default setti ng 150U clock di stri but or 2
n
clock distributor
0.1 s
0.2 s
0.5 s
1.0 s
2.0 s
5.0 s
10.0 s
20.0 s
50.0 s
T* 1 T* 2 T* 5 T*10 T*20 T*50 T * 100 T * 200 T * 500
T* 1 T* 2 T* 4 T* 8 T*16 T*32 T*64 T * 128 T * 256
Table 2-1 Overview of the organiz ati on bloc ks of the CPU 948 for program execu tion
Program, Organization and Sequence Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 19
Page 50
Organiza tio n blocks to contr ol the start-up pr oc edure
Block Function and call criterion
OB 20 Call on request for COLD RESTART (manual and automa tic) OB 21 Call on request for MANUAL WARM RESTART/COLD REST ART WITH
MEMORY
OB 22 Call on request for AUTOMATIC WARM RESTART/COL D RESTART
WITH MEMORY
Organiza tio n blocks to contr ol the start-up pr oc edure
Block Function and call criterion
OB 38 Organizati on of the star t-u p proc e dur e fo r comm un ic ati on in the
"soft stop" mode.
OB 39 Organization of the cyclic progra m for commun ica tion in the
"soft stop" mode.
Organiza tio n blocks f or reac ti on to devic e or prog ra m error s
1)
Block Function and call criterion
OB 19 Runtime error (LZF): called bloc k not loaded (PB , SB, FB, FX)
or attempt to open a data block that is not loaded (DB, DX)
OB 23 Timeout (QVZ) in user progra m (during di re ct acc es s to I/O modu les )
OB 24 Timeout (QVZ) when updating the process image and transferring
interprocessor communication flags.
OB 25 Addressing error (ADF)
OB 26 Cycle time exceeded (ZYK)
Table 2-4 continued:
OB 27 Substitution error (SUF)
Table 2-2 Overview of the organizat ion bl oc ks of the CPU 948 for start -up
Table 2-3 Organizatio n block s of the CPU 948 for a SOFT STOP
Table 2-4 Overview of the organiz ati on bloc ks of the CPU 948 for error handl ing
Program, Organization and Sequence Blocks
CPU 948 Programming Guide
2 - 20 C79000-G8576-C848-04
Page 51
Organiza tio n blocks f or reac ti on to devic e or prog ra m error s
1)
Block Function and call criterion
OB 28 Timeout input byte IB 0
(process in terru pts)
OB 29 Timeout distrib uted I/ Os, e xt ende d ad dre s s volume
OB 30 Timeout and parity error (PARE) accessing the user memory
(OB 31) (set cycle monitoring time)
2)
OB 32 Load and transfer error accessing data blocks (TRAF)
OB 33 Collision of timed int errupts (WEFES/W E FE H )
OB 34 Error setting up a data blo ck (G DB/GX DX )
OB 36 Error in self test
1)
If the OB is not programmed, the CPU changes to the stop mode in the event of an error. EXCEPTION: if OB 19 (logic block not loaded), OB 23 or OB 24, OB 29 (timeout) or OB 33 (collision of timed interrupts) do not exist, there is no reaction!
2)
OB 31 only exists in the CPU 948 for the sake of compatibility. To set the cycle monitoring time, you should use data block DX0 (refer to Chapter 7) OB 31 is called once during the start-up, if loaded. You can also use it to set the cycle monitoring time by programming the following STEP 5 operations in it:
:L KF +nnn :BE
nnn is a decimal number. The cycle monitoring time is obtained from "nnn
*
10 ms".
Operating system org aniz at ion bl oc k s of the CPU 948
Block Func tion
OB 0 Interna l bloc k bel ongi ng t o ope ra ting syste m
Program, Organization and Sequence Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 21
Page 52
2.2.2 Organization Blocks for Special Functions
The followi ng or ga niz a tion blocks contain special func tions of the system progra m. You c annot program these blocks, but simply call them (this applie s to all OBs with numbe rs betwe en 121 and 255!). They do not contain a STE P 5 progra m. Spec ial fu ncti on OBs can be called in all logic blocks.
Integrated or gani zati on bloc ks with spe ci al funct ions
Block: Bloc k func tion:
OB 121 Set/read time of day (com pa t ible with CPU 946/ 947) OB 122 "Disable interrup ts" on/ off OB 124 Delete STEP 5 blocks OB 125 Generate STEP 5 blocks OB 126 Define/tra nsfe r proc es s image s OB 129 Battery sta t e OB 131 Delete ACCU 1 to ACCU 4 OB 132 Roll up ACCU OB 133 Roll down ACCU OB 141 Enable/ di sabl e "disa bl e i ndi vid ua l tim ed inter rupt s" OB 142 Enable/ di sabl e "de lay a ll inter rupt s" OB 143 Enable/di sable "de lay sing le timed i nterr upt s" OB 150 Set/read syste m time (compat ib le wit h CPU 928B) OB 151 Set/rea d cloc k-c on tro lled inter rupt time OB 153 Set/read time for delaye d inte rrup t OB 180 Variable data block access OB181 Test data blocks (DB/DX) OB 182 Copy data are a OB 200, 202 to 205 Functions for multiprocessor communication OB 222 Restart cycle monitoring time OB 223 Compare start -up types of CPUs in mul tiproc e s sor mode OB 254, 255 Copy/duplicate DB a nd DX da ta block s from memory ca rd to user me mo ry
These spec ial fu nc tions ar e desc rib ed in detai l in Cha pter 6.
Table 2-5 Overview of the organiz ati on bloc ks of the CPU 948 for specia l functions
Program, Organization and Sequence Blocks
CPU 948 Programming Guide
2 - 22 C79000-G8576-C848-04
Page 53
2.3 Functio n Bloc ks
Functio n block s (FB /FX) a re also pa rts of the user pr ogra m just lik e program blocks. FX function blocks have the sam e structure as FB function blocks and are programmed in the same way. You use function blocks to implement frequently recurring or very complex f unctions. I n the us er p rogram , each function bloc k represents a complex complete function. You ca n obta in function bloc ks as follows:
•• as a software product from SIEMENS (standard function blocks
on diskette - see /11 /); wit h the se func tion blocks you can generate user progra m s for fa st a nd sim pl e op en loop con tro l, signa l li ng, closed loop contro l and lo ggi ng;
or
•• you can program function bloc ks you rsel f.
Compar ed with organiza t ion , pr ogra m and se qu en ce blocks, function blocks have the followi ng fo ur e sse nt ial di ffe r enc e s :
OB, PB, SB FB/FX
1. Range of operatio n s
only basic ope ra ti on s - basic oper ations,
- supplementary operations
- system operations
2. Method of representation
program mi ng a nd c a ll in STL, LAD, CSF
programm in g only in AWL
3. Name
name envi ron me nt not possible (only number)
in additi on to the num be r a name with max. 8 chars. can be assigned
4. Operands
none forma l operands (block
parame ters). When the block is called formal operands are assigned actual operands
Function Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 23
Page 54
2.3.1 Structure of Fun ctio n Bloc ks The block header (five word s) of a function block has the same
structure as the headers of the other STEP 5 block types.
The block body on the other hand, ha s a different structure from the bodies of th e othe r bl oc k typ es. Th e bloc k bod y co nta i ns the func tion to be executed in the form of a statement list in the STEP 5 program ming langua ge. Between the bloc k he ader and the STEP 5 stateme nt s, the fu nc ti on bl oc k ne eds additiona l mem ory spa c e fo r its name and for a list of form a l oper an ds. Since this list contains no statements for the CPU, it is skipped with an uncon ditio nal jump that the program m e r gene ra te s aut om a tica l ly. T his ju mp state me nt is not displaye d whe n the func ti on bl oc k is di sp laye d on t he PG!
When a func ti on bl oc k is cal le d, onl y the bl oc k bod y is proc e s sed.
Absolute or symbolic operands
You can enter operan ds in a func tion bloc k in absol ute fo rm (e.g. F 2.5) or symbolically (e.g. MOTOR1) . You must store the assignme nt of the symbol ic operands in an assignment list be fore you enter the operands in a fun ct ion block (see /3/).
Fig. 2-4 shows the structure of a funct ion block in the mem or y of a program mable controller.
JU
Name of the FB/FX
Formal operand 1
Formal operand 2
Formal operand n
5 words
1word
4 words
3 words
Block header
Block body
BE
3 words
Skip formal operand list
1st STEP 5 user operation
3 words
List of formal operands
STEP 5 user program
Fig. 2-4 Structure of a function block (FB/FX)
Function Blocks
CPU 948 Programming Guide
2 - 24 C79000-G8576-C848-04
Page 55
The mem ory contain s a ll the information that th e programmer needs to represent the function block graphically when it is called and to check the operand s durin g para met er assign ment and progra mmi ng of the functi on bl oc k. Th e progra m m er reje ct s incorrect input.
When handl in g func t ion blocks, dist ing uish be t wee n t he foll owi ng procedures:
•• programming FB/FX
and
•• calling FB/FX and then assigning actual value s to the parameters.
Distinction: "programming" – "calling and assigning parameters"
When programming, you specify the function of the block. You must decide whi ch inp ut op er an ds the funct ion req uir es a nd whi ch output results it should transfe r to the cal li ng pro gra m . You def ine th e input operands an d output re sul ts as for ma l opera nds. These function as tokens.
When a block is called by a higher order block (OB, PB, SB, FB, FX), the formal operands (block pa ramet ers) a re replace d by actual operands; i.e. par ameters are assigned to the function block.
How to program
IF... THEN...
You want to program a functio n block "d i re ct ly", i.e. without formal operands.
Program it as you wou ld a program or sequence block.
You want to use forma l opera nd s in a funct io n blo ck.
Proceed as explained on the follow i ng pa ges. Make sure you keep to the required order: First program the FB/FX with the forma l ope ra nd s and keep it on the PG (offlin e) or in the CP U memory (o nline) Then program the block(s) to be called with the actual operands.
Function Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 25
Page 56
2.3.2 Programming Fun c t ion Bloc k s
You can program a function block only in the "statement list" method of re pre se nta t ion . Whe n e nteri ng a func t ion block a t a program m er, perform the following steps:
Step Action
1 Enter the block type (FB/F X) and the number of the
function block.
Numb er your fu nc ti on bl oc ks in de sce nding order starting with FB 255, so that they do not collide with the standard function bloc ks. T he sta nda rd fu nc ti on blocks are num be re d from FB 1 to FB 199.
2 Enter the name of the function block.
The name can have a maximum of eight characters and must start with a letter.
3 If the function block is to process formal operands:
Enter the formal opera nds you req uir e in the bloc k as block parameters.
Enter the fol lo wing inform atio n for e ach form a l operand:
- the na me of the block paramete r (m a ximum 4 charac te rs),
- the type of block paramete r a nd th e da t a type of the block parameter (if applicable)
You can define a maximum of 40 formal ope rands.
4 Enter your STEP 5 program in the form of a statement
list (STL). The formal operands are preceded by an equality sign (e.g. A = X1). They can also be referenced more than once at various position s i n the function blo ck.
5 Terminate your p rogram input with the block end
operati on "BE".
Function Blocks
CPU 948 Programming Guide
2 - 26 C79000-G8576-C848-04
Page 57
Note
If you cha nge the orde r or the number of formal operan ds in the formal operand list, you must al so update all STEP 5 st atements in the function block that reference a formal operand and a l so the block parameter list in the calling block!
Progra m or ch an ge function blocks only on disket te or ha rd di sk and then transfer the m to your CPU!
Formal operands
The following parameter and data types are permitted as the formal operands of a function block (also known as block parameters):
Parame ter type Data type
I = input paramet er Q = output parameter
BI/BY/W/D
D = data KM/KH/KY/KS/KF/
KT/KC/KG
B = block operation T = timer C = counter
none (no type can be specified)
I, D, B, T or C are parameters that are indicated to the left of the functi on sym bol in graph ic representation. Parameters labelled with Q are indicated on the right of the function symbol.
The data typ e indi ca t es whe th er you are worki ng wit h bi ts, bytes, words or double words for I and Q parame ters an d which dat a form at applie s to D pa ra m et e rs (e. g. bit pa tt e rn or he xadecimal pat te rn ) .
Table 2-5 Permitted formal operands for function blocks
Function Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 27
Page 58
2.3.3 Calling Function Blocks and Assignin g Para meters to them
You can call every functi on bloc k as often as you want anywhe re in your STEP 5 pr ogra m . You can c a ll func ti on bl oc ks in a sta tem en t list or in one of the graphic methods of represen tati on (CSF or LAD) .
To call a funct ion block a nd a ssign pa ra m e ters to i t, pe rfor m the following steps:
Step Action Reaction on PG
1 Make sure that the ca lle d func t ion block e xi sts ei ther
in the PG memory (offl in e) or in the CPU me mory (onli ne).
none
2 Enter the call statement for the function block in the
block where the call is to originate.
You can program a func t ion block ca ll in an organiza ti on, program or seque nce block or in another function block.
After you ente r th e ca ll stat e ment (e.g. JU FB200), the name of the releva nt func ti on block and the form al operand l ist a ppe a r automatically.
3 Assign the actual operand re le vant to this call to each
of the forma l oper ands, i.e. you assign parame ters to the function block.
These actual operands can be di ffere nt for separate calls (e.g. inputs and output s for the first call of FB 200, flags for the second call). Using the formal operand list, you assign the required actual operands for ea ch function block call.
none
Unconditional/conditional call
Unconditio nal cal l Conditional cal l
"JU FBn" for FB function blocks or "DOU FXn" for FX ex te nde d function blocks :
the refer en ce d fu nc tion block is processed regardle ss of the previous result of logic operat io n (RL O).
"JC FBn" for FB func tion bl oc ks or "DOC FXn" for FX extended function blocks:
the refe re nced function blo ck is only processed when the re su lt of log ic ope ra ti on RLO = 1. If RLO = 0 the block call is not executed. Regardless of whether the block call is ex ec u t ed or no t , t he RL O is a lsways set to "1".
After the unconditiona l or conditio nal call, th e RLO can no longer be combine d logica lly. Howe ver, it is carried over to the called function block with the jump and can be evaluated there.
Function Blocks
CPU 948 Programming Guide
2 - 28 C79000-G8576-C848-04
Page 59
Permitted actual operands
Which opera nds ca n be assi gne d as actual operands is shown in the following table.
Parameter type
Data type Actual operands per mitte d
I, Q
BI for an operan d
with bit addre s s
BY for an operand
with byte add re ss
W for an operand
with word address
D for an operand
with double word address
I n.m input Q n.m output Fn.mflag
IB n input byte QB n output byte FY n flag byte DL n data byte left DR n data byte righ t PY n peripheral byte OY n byte from extended peri phery
IW n input word QW n output word FW n flag word DW n data word PW n peripheral word OW n word from extended periphery
ID n input double word QD n output double word FD n flag double word DD n data double word
D
KM for a bi na ry pa tt e rn (1 6 bit s)
KY for two absolute numbers,
one byte each, each in the range from 0 to 255
KH for a hexa de c imal pattern
with a maxi mu m of four digits
KS for two alphanumeric
characters
KT for timer value (BCD-
coded) units .0 to .3 and values 0 to 999
KC for a counter value
0 to 999
Constants
Table 2-6 Permitted actual operands for function blocks
Function Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 29
Page 60
Parameter type
Data type Actual operands per mitte d
Table 2-6 continued:
D
(Cont.)
KF for a fixed point number
-32768 to +32767
KG for a floating point
number
1)
Constant s
B Data type designati on not possible DB n Data block; the operation
C DB n is executed
FB n Function block (permitted
only without parameters) called unconditionally (JU . .n)
OB n Organization block called
unconditionally (JU . .n)
PB n Program blocks - called
unconditionally (JU . .n)
SB n Sequence blocks - called
unconditionally (JU . .n)
T Data type designati on not possible T 0 to 255 Timer C Da ta type designa tion not possib le Z 0 to 255 Counter
1)
±0.1469368 x 10
-38
to ±0.1701 412 x 10
39
Note
S flags are not perm it ted a s actu al opera nds for func ti on bl ocks.
After the jump to a function block, the actual operands from the block then called are used in the fun ctio n blo ck progr am in stead of the formal operands. This featu re of progra mm abl e fu nc tion bl oc ks al low t hem t o be used for a wide variety of purposes in your user pro gra m .
When th e program re turns from the called function block, the list of actual ope ra nds in the callin g blo ck is skippe d by a jump opera ti on activa ted im plic i tl y by STEP 5 i n MC-5 code .
Function Blocks
CPU 948 Programming Guide
2 - 30 C79000-G8576-C848-04
Page 61
Examples
Example 1: the following (complete) example is intended to further clarify
the programming and calling of a function block and the assign­ment of parameters to it. You yourself can easily try out the example.
Programming the function block FB 202:
FB 202
SEGM ENT 1 NAME
EXAMPLE
DECL : INP1 I/Q/D/B/T/C: I BI/BY/W/D: BI DECL : INP2 I/Q/D/B/T/C: I BI/BY/W/D: BI DECL : OUT1 I/Q/D/B/T/C: Q BI/BY/W/D: BI
:A= INP1 :A= INP2 :== OUT1
: :BE
Function block FB 202 is called and has parameters assigned to it in program block PB 25:
STL method of representation CSF/LAD method of representation
PB 25 SEGM ENT 1
: JU FB 202 FB 202 NAME : EXAMPLE EXAMPLE INP1 : I 13.5 I 13.5 INP1 OUT1 Q 23.0 INP2 : F 17.7 F 17.7 INP2 :BE OUT1 : Q 23.0
:BE
The following operations are executed after the jump to FB 202
Formal operand list
STEP 5
state-
ments
Formal operands
Parameter type
Data type
Formal operands
Actual operands
Function Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 31
Page 62
Example 2: calling a function block and assigning parameters to it with
the STL and CSF/LAD methods of repre sentatio n in a program block.
STL method of representation
PB 25 SEGM ENT 1
:
:CDB5
:
: JU FB 201 NAME : REQUEST
DATA :
DW 1
RST : I 3.5 SET : F 2.5 MTIM : T2 TIME : KT 010.1 TRAN : DW 2
BEC : Q 2.3
LOOP : Q 6.0
:BE
CSF/LAD method of representation
PB 25 SEGM ENT 1
FB 201
REQUEST
DW1 DATA TRAN DW 2 I 3.5
RST BEC Q 2.3
F2.5
SET LOOP Q 6.0
T2
MTIM :BE
KT 010.1 TIME
Formal operands
Actual operands
Function Blocks
CPU 948 Programming Guide
2 - 32 C79000-G8576-C848-04
Page 63
2.3.4 Special Function Blocks Apart from the functi on bl ocks tha t you prog ra m yourse lf, you can
order standard func tion bloc ks as a finish ed softwa re produc t. These contain sta nd ar d funct ion s for ge nera l use (e.g. sign alli ng fu nc tio ns and seque nce contro l). Standard fun ctio n blo cks are assigne d num bers FB 1 to FB 199.
If you order standard function blocks, remember the special instructio ns in the ac co mp an yin g desc ri pt ion (i.e. are a s assigne d a nd conventions et c.) .
The standard function blocks for the S5-155U are listed in catalog ST 57 /11/.
Example
Floating point root extractor RAD:GP FB 6
The function block RAD:GP extracts the root of a fl oating point number (8-bit exponent and 24-bit mantissa). It forms the square root. The result is also a floating point number (8-bit expon ent and 24-bit mantissa). The least significant bit of the mantiss a is not rounded up or down.
If applicable, for the rest of the processing, the function block sets the "rad icand negati ve" identifier.
Nume rical range:
Radicand - 0.1469368 Exp. -38 to +0.1701412 Exp. +39
Root +0.3833434 Exp. -19 to +0.1304384 Exp. +20
Function: Y = √
A
Y = SQRT; A = RADI
Calling the function block FB 6:
In the exa mple , th e ro ot is extracted from a float ing poin t number that is located in DD5 of DB 1 7 with an 8-bit exponent and a 2 4-bi t mantissa. The result, an othe r 32 -bit floating point number, is w ritt en t o DD 10. Prior to this, the appropri ate data block must be opene d. The parameter VZ (parameter type: Q, data type: BI) indica tes the sign of the radicand : VZ = 1 for a negative r adic and.
Function Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 33
Page 64
"Floating point root extractor" continued:
STL method of representation LAD method of representation
Seg- : C DB 17 ment : SEGMENT 2 1:***
: JU FB 6 FB 6 Seg- NAME : RAD : GP RAD ment RADI : DD 5 DD 5 RADI VZ F 15.0 2 VZ : F 15.0 SQRT DD 10 *) SQRT : DD 10 :BE
DD= data double word
*) Must be located in separate segments, since the operation "C DB 17" in
segment 1 cannot be converted to LAD/CSF.
Function Blocks
CPU 948 Programming Guide
2 - 34 C79000-G8576-C848-04
Page 65
2.4 Data Blocks
Data blocks (DB) or exten ded da ta block s (DX) are used to store the fixed or variable da ta wit h which the user progr am works. No STEP 5 operations are processed in data bloc ks.
The data of a data block i nclud es th e foll owin g:
•• various bit patterns (e .g. for sta tus of a contr oll e d proc es s)
•• numbers (hexadecimal, binary, decimal) for timer values or arith-
metic results
•• alphanumeric cha ra ct e rs, e. g. for messa ge te xts.
Structure of a data block
A data block (DB/DX) co nsists of the followi ng parts:
•• block preheader (DV, DXV),
•• block hea de r
•• block body.
Block preheader
The block preheader is created automatically on the hard or floppy disk of the PG and not transferr ed to the CPU. It conta ins the data formats of the data words enter ed in the block body. You have no influence over the creation of the block preheader.
Note
When you transfer a data block from the PLC to diskette or hard disk, the corre spond ing block preh ea der c an be dele te d. For this reason, you m ust ne ve r modi fy a da ta blo ck with diff er en t data formats in the PLC and then transfe r it back to diskette , oth erwise all the data word s in the DB a re aut om a ti cally assigned the data format you se le c ted in the pre set s scre e n form .
Data Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 35
Page 66
Block header
The block header occupies five words in the me mory and conta in s the fo llowing:
•• the block ide ntifier
•• the programmer i dentifier
•• the block typ e an d the bl ock number
•• the library number
•• the block length (including the length of the block header).
Block body
The block body contains the data words with which the user progra m works. These data words are in ascending order in the block body, starting with data word DW 0. Each data word occupies one word (16 bits) in the mem or y.
Maximum length
A data block can occupy a total of maximu m 32 767 words (includin g header) i n the CPU mem or y. When yo u use your pro grammer to enter and transfer data block s, rem embe r the size of your CPU memor y!
Data Blocks
CPU 948 Programming Guide
2 - 36 C79000-G8576-C848-04
Page 67
2.4.1 Creating Data Blocks To create a data block, p er form the followin g steps:
Step Action
1 Enter the block type (DB/DX) and data block number (2
or 3 to 255).
2 Enter indiv idu al data word s in the data format you
require.
(Do not complete your input of the data word s wi th a BE statem e nt !)
Note
Data bl oc k s DB 0, DB 1, DX 0, DX 1 a nd D X 2 a r e res e rv e d f o r specific functi ons and you canno t use them fre ely for other functions (see Se ction 2.4.3)!
Type Data format Examples
KM Bit pattern 0 0100 110 00 1111 11
KH Hexadecimal 263F KY 2 Bytes 038,06 3
KF Fixed poi nt numb er +09791
KG Floating point numbe r +1356123+12
KS Character ?!ABCD123-+.,% KT Timer value 055.2 KC Coun ter value 234
Table 2-7 Data formats permitted in a data block
Data Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 37
Page 68
2.4.2 Opening Data Blocks You can only open a data block (DB/DX) unconditional ly. T his is
possible wit hi n an orga ni za tion, program , seque nc e or fun ct io n blo ck . You can open a specific data bl ock mo re than once in a program.
To open a data block , pe rform the following step s:
IF... THEN...
You want to open a DB data block Type in the STEP 5 operation
"C DB.."
You want to open a DX data block
Type in the STEP 5 operation
"CX DX."
Validity of a data block
After you open a data bloc k, all state m e nts th at follow with the oper an d area ’D’ refer to the ope ned data block.
The opened da ta bl ock also re ma ins v alid when the progra m is continue d in a dif fere nt bl ock fol lo wing a bloc k cal l.
If a second da ta block is opened in this ne w block, the second data block is onl y valid in the newly called block from the point at which it is called. Afte r progra m exe cuti on ret urns to the calli ng bloc k, the old data bl oc k is onc e ag ai n valid.
Access
You can access the data stor ed in the opened d ata block during program execution using binar y lo gic ope rati ons, se t/r e set operations, load or transfer operations (refer t o Cha pt er 3 for m ore detailed infor ma t ion ).
With a binary operation, the addres sed data wor d bit is used to form the RLO. The conte nt of the da ta word is not changed.
With a set/reset ope ra tion, the addr esse d da ta word bi t is assigne d the value of the RLO. The content of the data word may be changed.
A load ope ration transfers the conten ts of the refere nce d data word into ACCU 1. The contents of a data word are not changed.
A transfer operation transfers data from ACCU 1 to the referenced data word. The old content s o f the data word are ove rwritten.
Data Blocks
CPU 948 Programming Guide
2 - 38 C79000-G8576-C848-04
Page 69
Note
Before acc essin g a dat a wor d, you m ust ope n the data block yo u require in your pr ogra m . This is the only way that t he CPU ca n find the correct data word. The referenced data word m ust be co nta i ne d in t he ope ne d blo ck , otherwise th e syste m program detect s a loa d or transfer error .
With load and transfe r operati on s, you can only access data word numbers up to 255!
An opened data block remai ns valid until one of the follo wing events occur:
a) a second data block i s opened
or
b) the block, in which the data block was
opened, is completed with ’BE’, ’BEC’ or ’BEU’.
Examples
Example 1: transferring data words
You want to transfer the contents of data word DW 1 from data block DB 10 to data word DW 1 of data block DB 20.
Ente r the followin g statements:
:C DB 10 (open DB 10) :L DW 1 (load the contents of DW 1 into : ACCU 1) :C DB 20 (open DB 20) :T DW 1 (transfer the contents of ACCU 1 to : DW 1) :
Data Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 39
Page 70
Example 2: range of validity of data blocks
(Fig. 2-5)
Data block DB 10 is opened in program block PB 7 (C DB 10). During the subsequent program execution, the data of this data block are processed.
After the call (JU PB 20) program block PB 20 is processed. Data block DB 10, however, remains valid. The data area only changes when data block DB 11 (C DB 11) is opened. Data block DB 11 now remains valid until the end of program block PB 20 (BE).
After the jump back to program block PB 7, data blo ck DB 10 is once again valid.
PB 7
CDB11
BE
PB 20
CDB10
JU PB 20
BE
Range of validity of DB 10 Range of validity of DB 11
Fig. 2-5 Range of validity of an opened data block
Data Blocks
CPU 948 Programming Guide
2 - 40 C79000-G8576-C848-04
Page 71
2.4.3 Special Data Blocks On the CPU 948 data blocks DB 0, DB 1, DX 0, DX 1 and DX 2 are
reserve d for special functions. They are manag ed by the system program and you c a nnot use the m fr eel y for ot he r fun ctions.
DB 0
•• Data block DB 0 (see Section 8.3.2)
Data block DB 0 cont ai ns the addre ss list with the start addr esses of all blocks that are located in the data block RAM of the CPU. The system progr am ge nera te s this add re ss list during initi aliz ati on (followi ng e ach POWE R UP or OVE RAL L RESE T ) an d it is up­dated automatically when you use a programmer to change data blocks or generate a new data block.
DB 1
•• Data block DB 1 (see Sec ti on 10. 1. 6)
Data block DB 1 contains the list of digital inputs/outputs (P periphe­ral with relative byte a ddresses from 0 to 127) and the interproce ssor communication (IPC) flag inputs and output s that a re assigned t o the CPU. If applicable, the block may also contain a timer field length.
DB 1 can have para me ters assigned and be load ed as follows:
to reduce the cycle time in single processor operation, since only the input s, output s or ti mers e nte re d in DB1 a re upda te d.
DB 1 must be assigned paramete rs and load ed as follows:
a) for multiprocessing b) when IPC flags exi st wit h CP s
DX 0
•• Data block DX 0 (see Chapter 7)
If you assign parameters to data block DX 0 and load it, you can chan­ge the defaults of certain s ystem program functions (e.g. the start-up procedure) and adapt the performance of the system program t o your particular application.
DX 1
•• Data block DX 1
Reserve d.
DX 2
•• Data block DX 2
Reserved for the second serial interface.
Data Blocks
CPU 948 Programming Guide C79000-G8576-C848-04
2 - 41
Page 72
Data Blocks
CPU 948 Programming Guide
2 - 42 C79000-G8576-C848-04
Page 73
Cont ent s of Chapt er 3
3.1 Principle of Program Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 4
3.2 Program Organization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 5
3.3 Storing Program and Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 10
3.4 Processing the User Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 11
3.4.1 Definition of Te rm s used in Program Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 12
3.5 STEP 5 Operations with Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 15
3.5.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 19
3.5.2 Programming Examples in the STL, LAD and CSF Methods of Representation . . . . . 3 - 34
3.5.3 Supplementary Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 49
3.5.4 Executive Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 59
3.5.5 Semaphore Operation s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 75
3
Program Execution
CPU 948 Program ming Guide C79000-G85 76 -C848-04
3 - 1
Page 74
Contents
CPU 948 Programming Guid e
3 - 2 C79000-G85 76-C84 8-0 4
Page 75
3Program Execution
This cha pter is intended fo r readers who do not ye t ha ve an y great experie nc e in usin g the pro gra m ming l an gua ge . The cha pte r the re fore deals wi th the basi c s of STE P 5 pro gra m ming a nd e xpl a ins i n de ta il (with exampl es) the STEP 5 opera tion s for the CPU 948.
Experie nc ed reade rs w ho req uir e more in form a tion a bou t a sp eci fic STEP 5 operation listed in the Pocket Guide can refer to the reference section in 3.5.
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 3
Page 76
3.1 Principle of Program Execution
You can process your STEP 5 user program in various w ays.
Cyclic progra m exec ut ion is most com mo n wit h progra mm abl e controlle rs (PL Cs) . The syste m progra m runs thr ough a progra m loop (the cy cl e , re fe r t o Sec t ion 3.4) and ca l ls o rg anization bloc k OB 1 cyclic al ly in each l oop (r ef er to Fig . 3-1).
Call OB1
BE
Call PB 20
BE
PB 20
OB 1
Update inter­processor comm. flag outputs
image outputs (PIQ)
Update process
Trigger cycle time
Update inter­processor comm. flag inputs
image inputs (PII)
Update process
from start-up
System program User program
Fig. 3-1 Pri nc iple of cycli c pr og r am executi on
Principle of Program Execution
CPU 948 Programming Guide
3 - 4 C79000-G8576-C848-04
Page 77
3.2 Program Organization
Program organization allows you to specify which conditions affect the processing of your blocks a nd t he order in which they are process ed. Organize your program by programming organization blocks with conditional or unconditional calls for the bloc ks you require.
You can call addi ti ona l progr am, funct ion and sequ en ce bl ocks in a ny combina tion in the progra m of indivi dua l orga niz ati on, progra m , function a nd se que nc e blocks. You c a n cal l these one afte r anot he r or nested in one anot he r.
For maximu m effi c ie ncy, you sho uld orga ni ze your prog ra m to emphasise th e most import a nt progra m struct ure s a nd in such a way that you can clea rly recog niz e parts of the co ntr olle d syste m which are related in the softwa re .
Figs. 3-2 and 3-3 are exa mp les of a progr am str uctur e.
Program Organization
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 5
Page 78
PB ‘B‘
OB 1 PB ’A’ FB
FB
Go to initia l state
Stop to the system EMERGENCY
OFF
PB ‘D‘
Message output
FB
Message output
via standard
peripherals
FB
Message output
via standard peripherals
DX
Message texts
PB ‘C‘
Individual control level
FB
Group initialization
DB
Interface flags of the individual
control
elements
FX
Individual initialization
FX
Individual initialization
Sequence control
Control of
sequence cascade
FB
SB
Sequence step
SB
Sequence step
JU PB ’A’
JU PB ‘B‘
JU PB ‘C‘
JU PB ‘D‘
BE
Operating mode program
Fig. 3-2 Example of the organization of the user program according to the program structure
Program Organization
CPU 948 Programming Guide
3 - 6 C79000-G8576-C848-04
Page 79
OB 1
JU PB ‘X‘
JU PB ‘Y‘
BE
Controlled system part ‘Z‘
PB ‘X‘
Controlled system part ‘X‘
FB
Individual control
FB
Closed loop control
FX
Signalling
Controlled system part ‘Y‘
PB ‘Y‘ F B
Sequence control
FX
Signalling
FB
Closed loop control
FB
Arithmetic
JU PB ‘Z‘
FB
Data logging output
FB ‘Z‘
Fig. 3-3 Example of the organization of the user program according to the structure of the controlled system
Program Organization
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 7
Page 80
Nesting blocks
Fig. 3-4 shows the principle of nested block calls.
Block addresses
A block start address specifies the location of a block in the user memory. For logic bloc ks, thi s is the a ddre ss of t he mem ory l oc atio n containi ng t he first STE P 5 ope ra t ion (with FB an d FX, the JU oper at io n via th e fo rm al ope rand list); with dat a bl ocks, it is the address of the fir st data word .
To enable the CPU to locate the called block in the memory, the start addresses of a ll vali d blo cks are entere d in the bl ock ad dre ss list in data block DB 0. DB 0 is managed by the system progra m, you cann ot call it yourself.
The CPU stores a return address every time a new block is called. After the new block has been processed, this return address enables the program to find the block from which the call originated. The return address is the address of the memory location containing the next STEP 5 statement after the block call. The CPU also stores the start address and length of the data block valid at this location.
OB 1
BE
PB 20
BE
PB 5
C
C
DB 20
DB 30
BE
JU
PB 5 F 200.5
*)
JU
JU
PB 20
FB 30
O
F1.5
*)
NAME:
KURV
A
I 55.0
*)
*)
Operation to which the program returns
A
1st STEP 5 op.
1st STEP 5 op.
Fig. 3-4 Nested logic block calls
Program Organization
CPU 948 Programming Guide
3 - 8 C79000-G8576-C848-04
Page 81
Nesting depth
You can only nest 40 blocks within one another. If more than 40 blocks are calle d, the CPU sign als an error and goe s to the stop mod e.
Example of nesting depth
You can determine the nesting depth of your program as follows:
- Add all the organization blocks you have programmed (in the example: 4 OBs).
- Add the nesting depth of the individual organization blocks (in the example: 2 + 2 + 1 + 0 = 5).
- Add the two amounts together to obtain the program nesting depth (in the example: 4 + 5 = nesting depth 9). I t must not e xceed a v a lue of 40.
OB 25
Nesting depth
1
2
3
4
5
6
7
89
OB 1
PB 1
FB 1
OB 13
PB 131 FB 131
OB 2
FB 21
Program processing level
Fig. 3-5 Example of block nesting depth
Program Organization
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 9
Page 82
3.3 Storing Program and Data Blocks
On the CPU 948, the user progra m runs sol ely in the inte rna l RAM. The user progra m inc lud ing data blocks m ust , there fore , be loade d in the CPU 948 user memory.
How do I load programs and data blocks in the internal RAM?
You can use th e fo l lowin g metho ds:
•• You can load the individual logic and data blocks in the RAM
using your PG.
•• You can program a memory card (flash EPROM!) with your
comple te prog ram inc lud ing data blocks on the PG and then inser t the card in the re ce pta c le on t he CPU. If you do an overall rese t on the CPU (re fe r to Chapte r 4) the comple te conte nt s of th e m emo ry c ar d ar e loa de d "1:1 " in the internal RAM.
•• You loaded your prog ram in the inte rna l RAM with the PG or
from the memory card with an OVERALL RESET. You can then load addi tional blocks with th e PG or repl a ce e xist in g blo cks.
Note
You can only program the memory card on the PG. Use the PG software from version 6 upwards. When programming, the PG must be in th e mode "WORD FI ELD" (re f er to the STEP 5 manual /3/).
Caution
If you have cha nged or added blocks using the PG after l oa din g your progra m from the me mo ry c ar d, the se changes are reversed by the next OVERALL RESET, since the memory i s overwr itten again with the cont e nts of the mem ory card.
Storing Program and Data Blocks
CPU 948 Programming Guide
3 - 10 C79000-G8576-C848-04
Page 83
3.4 Processing the User Program
The comple te software on the CPU (consisting of the system prog ram and the STEP 5 user program) has the followi ng tasks:
•• CPU START-UP
•• Controlling an automati on proce ss by cont in uousl y repe ati ng
operations (CYC LE).
•• Controlling an automation process by reacting to events occurring
sporadically or at cert ai n tim es (i nt er rupt s) a nd re a ct in g to erro rs.
For all three tasks, you can sele ct spe cia l parts of yo ur progra m to run on the CPU by programming use r interf ace s (org an iza tion bloc ks OB 1 to OB 35 - refer to Section 2.2.3).
START-UP
Before the CPU can star t cycli c progra m execut io n, an initial iza tion must be perf orm e d to esta bl ish a define d ini tia l sta tus for c yc li c program exec ut ion and, for example, to spec ify a tim e base for t he execution of certain functions. The way in which this initialization is performe d depe nds on the event that led to a START- UP and on settings that you can make on your CPU. For more deta iled informat ion , refe r to Cha pt er 4.
You can influence the ST ART -UP pro cedu re of your CPU by program ming orga ni za t ion blocks OB 20 , OB 21 and OB 22 or by assigning paramet ers in DX 0 (refer to Chapter 7).
CYCLE
Following the STAR T- UP, t he syste m progr am goe s ove r to cycl ic processing. It is responsible fo r back grou nd fun ctio ns re qui re d for the automat io n tasks (re fe r t o Fig. 3-1 at the be gin nin g of th is se ctio n). After the system functio ns ha ve been exe c uted at the beginn ing of a CYCLE, the system program ca ll s organizatio n block OB 1 or function bl oc k FB 0 as the cyc lic user prog ra m. You pr ogra m the STEP 5 operati ons for cyclic proce ssin g in this bloc k.
Processing the User Program
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 11
Page 84
Reactions to interrupts and errors
To allow you to spe cify t he reac tions t o int errup ts or e rro rs, spec i al organiza tion bl oc ks (OB 2 t o OB 18 for inter rupt ser vic ing, OB 19 and OB 23 to OB 34 for reactions to errors) are ava i lable on the CPU 948. You can store an appropriate STEP 5 program in these blocks.
When interru pts or errors a re to be proces se d, the system progra m activa te s the c orre sp o ndi ng org an iz a tion block during cyclic processing. This m e ans tha t the cycl ic proc essin g is inte rru pted to service an in terru pt or to react to an error . The nesti ng of the organiz a ti on bl oc ks has a fixed pri ori ty (for fu rther inform at io n, ref er to Chapters 4 and 5).
In addition to the organization blocks, you c an al so in flu ence the reaction of the CPU to inte rru pt servi c ing by assigning parame ters in data bl oc k D X 0.
Organiz ati on bl oc ks OB 1 to OB 39 can be cal led by t he system program as soo n as the y ar e loa de d in the progr am mem or y (al s o during operation). If the OBs are not loaded, there is either no reaction from the CPU or (in the event of errors) it goes to the stop mode (refe r also to Section
5.4).
You can also loa d da ta blo ck DX 0 into the progra m me mo ry dur ing operat io n like the organization blocks. It i s, howeve r , only effective after the next COLD RESTART. If DX 0 is not loaded, the sta nda rd settings apply (refer to Chapter 7).
3.4.1 Definition of Terms used in Program Execution
Cycle time
The cycl e beg ins whe n t he cycl e monitoring time is trig ge re d an d en d s with the next trigger. The time that the CPU require s to exec ute the program between two triggers is calle d t he cycl e tim e . The cycl e time consists of the runt ime of the system pr ogra m an d the runtime of the user program .
The cycl e time therefore includes the fol lowing:
•• the time required to process the cycl ic prog ram (sy ste m and user
program),
•• the time required to proc ess i nterr upt s (e. g. time- co ntr oll e d
interrupt ),
•• the time required to process i nterr uptions (errors).
Processing the User Program
CPU 948 Programming Guide
3 - 12 C79000-G8576-C848-04
Page 85
Cycle time monitoring
The CPU monitors the cycle time in case it exceeds a maximum value. The standard setting for thi s ma xim um value i s 200 m s . You can s e t t he cycle time monitoring yourself or restart it during user program e xec ution (refer to DX 0/Chapter 7 and special function OB OB 222/Se ction 6. 16).
Process input and output image (PII and PIQ)
The proce ss ima ge of the in put s and outp uts i s a m emo r y ar ea in the internal RAM. Before cycl ic exec ut io n of th e user pr ogra m be gin s, t he syste m program read s the sign al state s of t he inpu t peri phe ra l modu le s and transfers th em to the proce ss inp ut image . The user pr ogra m evalua te s the signal states in the process input image and then sets the appropria te signal state s for the out put s in the proc ess ou tpu t ima ge . After the user program has been proce ssed, the system pro gram transfers th e signa l st ate s of the proce ss out put ima ge to the outpu t peripher al mo dules .
Bufferi ng th e I/O sign als in t he proce ss im ag e of the inp uts a nd outputs a voi ds a cha nge in a bit withi n a progra m cy cle from causi ng the correspond ing outp ut to "flutt er ".
The proce ss im a ge is the re fore a memor y ar ea whose contents are output to the peripherals and read in from the peripherals once per
cycle.
Note
The process image only exists for input and output bytes of the "P" peripherals with byte addresses from 0 to 127! Apart from the process i ma ge integrated in the system, you ca n use OB 126 to define and t ransfer further process images (re fer to Section 6.6)
Interprocessor communicati on (IPC) flags
IPC flags exchange data between individual CPUs (multiprocessing) or between the CPU and some communication processors.
The system program reads the input IPC flags of the CPU before cyclic execution of the user program begins. After the STEP 5 program is processed, the system program transfers the output IPC flags to the coordi nat or o r to t h e com mu nic at ions pr oce ss ors .
You define the input and out put IPC flags when you create data block DB 1 (refer to Sec tion 10.1.6).
Processing the User Program
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 13
Page 86
Interrupt events
Cyclic progra m exec ut ion can be inte rrup ted by the followi ng:
•• time-controlled program execution (delayed interrupt, cyclic timed
interrupts, clock-controlled interrupts),
•• interrupt-drive n progra m exec ut ion (proce ss int errup t, system
interrupt ).
The cyclic progra m can be int errup te d or eve n aborted completely by the fo llowing:
•• a device hardware fa ult or program error
•• operator intervention (usi ng the PC stop func tion, or sett ing the
mode selecto r to "stop", mu ltipr oc esso r stop MP-STP) ,
•• a stop operation
Processing the User Program
CPU 948 Programming Guide
3 - 14 C79000-G8576-C848-04
Page 87
3.5 STEP 5 Operations with Examples
A STEP 5 operatio n consist s of the oper at ion an d an opera nd. Th e operation spe cifies what the CPU is to do (operat ion ). The opera nd specifies with what an operation is to be executed.
STEP 5 operations c an be divided into th e followin g grou ps:
•• basic operations (can be used in all logi c blocks),
•• supplementary operations,
•• executive operat io ns (can only be used in FB/FX fu nc tion bloc ks),
•• semaphore operat ion s (ca n only be used in FB/FX fun ctio n blo ck s).
Accumulators as working registers
The CPU 948 has four accum ul ators, ACCU 1 to ACCU 4. Most STEP 5 operati ons use two 32 -bi t registers (ACCU 1 and ACCU 2) as the sourc e of ope ra nds a nd t he destination for re sul ts.
The STEP 5 ope ra t ion to be carrie d out af fe ct s the acc um ul a tor s, e . g. :
•• ACCU 1 is alway s the de sti nation in load oper at ions. A load
operati on shi fts t he old cont e nts of ACCU 1 to ACC U 2 (stac k lift). Accu mu la to rs 3 and 4 ar e not cha nge d by a ny loa d ope ra ti ons.
1)
analogou s for ACCU 2 to ACCU 4
ACCU-1-H
High byte Low byte
High byte
Low byte
ACCU 1
1)
High word Low word
31
24 23 16 15
8 7
0
ACCU-1-HL
ACCU-1-LH ACCU-1-LL
ACCU-1-L
ACCU-1-HH
STEP 5 Operations with Examples
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 15
Page 88
•• Arithmetic operations c om bi ne the conte nt s of ACCU 1 with those
of ACCU 2, write the result to ACCU 1 and transfe r the content s of ACCU 3 to ACCU 2 and the contents of ACCU 4 to ACCU 3 (stack drop ). In 16-b it fixed point arit hmet ic, only the low wo rd or ACCU 3 is tran sfe rre d to the low wor d of ACCU 2 and t he low word of ACC U 4 to the low word of ACCU 3.
•• When a constant is added (ADD BF/KF/DH) to the contents of
ACCU 1, the acc um ul ators 2, 3 and 4 a re not cha nge d.
Condition codes
STEP 5 operations either s e t or eva luate condi tion code s. T he condi tion codes are w ritte n to a condition code byte. Two groups of condition codes can be distinguished: condition codes of digital operations (word condition codes - bits 4 to 7 in the condition code byte) and condition codes from binary and exe cutive opera tions (bi t condition codes - bits 0 to 3 in the condition code byte). You can see how the various condition codes are influenced or evaluated by STEP 5 operations be referring to the operation list /1/.
You can displa y the con ditio n co de byte on a prog ra mme r usi ng th e "STATUS" online func tion (re fer to Sec tion 11. 2.3) . The byte has th e following stru cture :
Word condition codes Bit condition codes
CC 1 CC 0 OV OS OR STA RL O
ERAB
Bit 7 6 5 4 3 2 1 0
Bit condition codes
•• ERAB First bit scan
A logic op er at io n s eq ue nce containing binary operation s al wa y s begins with the first bit scan, following which a new RLO is forme d. The bit c ondi tion c ode
ERAB = 1 is then set. While the remaining logic operat ions in the sequence are being performed, ERAB remains set to 1 and the RLO cannot be changed by these logic op erations.
The active sequence of logic operations is terminated by a binary set/rese t oper at io n (e.g . S Q 5.0). Th e set/re se t ope rat ion set s ERAB to 0; the RLO can be evaluated (e.g. by RLO-depe nd ent operati ons) bu t can no longe r be combi ne d logica ll y. Th e next binary logi c opera tion fol lo wing a bina ry se t/re set ope rati on i s once aga in a first bi t sc a n.
STEP 5 Operations with Examples
CPU 948 Programming Guide
3 - 16 C79000-G8576-C848-04
Page 89
Example of ERAB
Other bit condition codes
•• RLO Result of logic operation
This is the resul t of bit logic opera tions. It is the truth state ment for compari son op er at io ns (re fe r to ope ra tions li st, bina ry lo gic operati ons or c om pa ri son ope ra tions).
•• STA Status
For bit opera ti ons, this in dic a te s the l ogi cal sta tus of the bit just scanne d or set. The sta tu s is upda t ed in bi na ry lo gic opera t ion s ­except for A(, O(,), O and fo r set/r ese t ope ra tions.
•• OR Or
Internal CPU bit for hand ling "AND be fore OR" logic ope ra tions.
Word condition codes
•• OV Overflow
This indicates whether t he perm issible numbe r ra nge was exceeded during the arithmetic operation just completed.
•• OS Stored overflow
The overflow bit is stored. It can be used in several arithmetic operations to indicate whethe r a n ove rflow occurred at any point during the operations.
:A I 1.0 ERAB is set to ’1’, : the new RLO is formed by : an AND operation :O I 6.3 The RLO is influenced by : an OR operation :AN I 2.1 The RLO is influenced by : an AND NOT operation. :S Q 2.4
ERAB is set to ’0’,
: the sequence is now complete :JC FB 150 The function block is called : dependent on the RLO. : :
STEP 5 Operations with Examples
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 17
Page 90
•• CC 1 and CC 0
These are the result condition codes that you can interpret from the following table:
Note
To evaluate the condition c odes directly, comparison and jump operations are available (refe r t o S ec tions 3.5.1 and 3.5.3).
Word
condition code s
Arith-
metical
operations
Digital
logic
operatio ns
Com-
parison
operatio ns
Shift
operations
For
SED,
SEE
Jump
operations
execute d
CC 1 CC 0
0 0 Result
= 0
Result
= 0
ACCU 2
=
ACCU 1
Shifted
bit
= 0
Semaphore
is
set
JZ
0 1 Result
< 0
ACCU 2
<
ACCU 1
––JMJN
1 0 Result
> 0
Result
0
ACCU 2
>
ACCU 1
Shifted
bit
= 1
Semaphore
is
set
or
enabled
JP JN
1 1 Division
by 0
Note
When a change of level takes place, e.g. servicing a timed interrupt, all accumulators and the bi t a nd word condition codes (RLO etc.) are saved and loaded agai n w hen the interrupted level is resumed.
Table 3-1 Result condit i on co des of STEP 5 ope rati on s
STEP 5 Operations with Examples
CPU 948 Programming Guide
3 - 18 C79000-G8576-C848-04
Page 91
3.5.1 Basic Operations You can use the basic operations in all logic bl oc ks and all metho ds of
representa tion (STL , LAD, CSF).
Binary logic operations
Operation Operand Function
A
O
I 0.0 to 127.7 Q 0.0 to 127.7 F 0.0 to 255.7 S 0.0 to 4095.7 D 0.0 to 255.15 T 0 to 255 C 0 to 255
AND logic operat io n afte r scan nin g for si gna l stat e "1"
OR logic operation after scanning for signal state "1"
of an input in the PII of an output in the PIQ of a flag bi t of an S flag bit of a data word bit of a timer of a counter
AN
ON
I 0.0 to 127.7 Q 0.0 to 127.7 F 0.0 to 255.7 S 0.0 to 4095.7 D 0.0 to 255.15 T 0 to 255 C 0 to 255
AND logic operat io n afte r scan nin g for si gna l stat e "0"
OR logic operation after scanning for signal state "0"
of an input in the PII of an output in the PIQ of a flag bi t of an S flag bit of a data word bit of a timer of a counter
O Combine AND operat ion s thro ugh logic OR O
U( O( )
ANDing of expressions in parenthe ses
ORing of expressio ns in parent hese s Close parent he sis (t o comple te the br acke ted expre ssion )
Maximum of 8 levels are permitted, i.e. 7 opened brackets
RLO formatio n
The binar y logic ope rati ons ge ne ra te t he resu lt of logic opera ti on (RLO). At the begin nin g of a logi c sequ en ce , the RLO only depends on t he signal stat e sca nne d (f irst sca n) and not on the typ e of logi c opera tio n (O = OR, A = AND).
Table 3-2 Binary logic operat ions
Basic Operations
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 19
Page 92
Within a sequence of logic operations, the RLO is formed from the type of operation, previous RLO and the s canned signal state. A sequence of logic operations is completed by a n ope rat ion (e .g. set/reset operations) which retains the RLO (
ERAB = 0). Following this, the RLO can be
evaluated but cannot be further combined.
Example
Set/reset operations
Operation Operand Function
S R
I 0.0 to 127.7 Q 0.0 to 127.7 F 0.0 to 255.7 S 0.0 to 4095.7 D 0.0 to 255.15
Set if RLO = 1 Reset if RLO = 1
an input in the PII an output in the PIQ a flag an S flag a bit in the data word
=
I 0.0 to 127.7 Q 0.0 to 127.7 F 0.0 to 255.7 S 0.0 to 4095.7 D 0.0 to 255.15
The RLO is assigned to
an input in the PII an output in the PIQ a flag an S flag a bit in the data word
Program Status RLO ERAB
: =Q0.0 AI1.0 AI1.1 AI1.2 =Q0.1
0 1 1 0 0
0 1 1 0 0
0 RLO retained 1 first bit scan 1 1 0 RLO retained, end of
the log ic operati o n s sequence
Table 3-3 Set/reset operations
Basic Operations
CPU 948 Programming Guide
3 - 20 C79000-G8576-C848-04
Page 93
Load and transfer operations
Operation Operand Function
L T
IB 0 to 127 IW 0 to 126 ID 0 to 124
QB 0 to 127 QW 0 to 126 QD 0 to 124
FB 0 to 255 FW 0 to 254 FD 0 to 252
SY 0 to 4095 SW 0 to 4094 SD 0 to 4092
DR 0 to 255
DL 0 to 255
DW 0 to 255 DD 0 to 254
PY 0 to 127
PY 128 to 255
PW 0 to 126
PW 128 to 254
OY 0 to 255
OW 0 to 254
Load Transfer
an input byte from/to the PII an input word from/to the PII an input doubl e word fro m/to the PI I
an output byt e fr om /t o the PI Q an output word fr om /to the PI Q an output doub le word fr om/t o the PIQ
a flag byte a flag w o rd a flag do ubl e wo r d
an S flag by te an S flag wo r d an S flag do ubl e wo r d
the right byte of a data wor d from / to DB, DX
the left byte of a data word from/to DB,DX
a data word fr om/to DB, DX a data double word from/to DB, DX
a periph er al byte of the digital inp uts/outputs (P area)
a periphe ra l byte of the a na log or digit al inp uts/ out puts (P area)
a peripheral word of the digita l inputs/ou tpu ts (P area)
a periphe ra l word of the ana log or digit al inputs/ out put s (P area)
a byte of the extended I/O area (O area)
a word of the extende d I/O ar ea (O are a)
Table 3-4 Load and transfer operat ions /p art 1
Basic Operations
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 21
Page 94
Operation Operand Function
L
KB 0 to 255 KS 2 ASCII
characters
KF -32768 to
+32767
KG
1)
KH 0 to FFFF DH 0 to
FFFF FFFF KM 16-bi t patt e rn KY 0 to 255 for
each by te
KT 0.0 to 999.3 KC 0 to 999
T 0 to 255 C 0 to 255
Load
a constant, 1 byte a constant, 2 ASCII characters
a consta nt as fixed point number
a consta nt as floating point number a consta nt as hexadecima l number a double word consta nt as a hexade cim al nu mber
a consta nt as bit pattern a constant, 2 bytes
a constant timer value (in BCD) a consta nt counter value
a timer, binary coded a counter, binary c ode d
LC
T 0 to 255 C 0 to 255
Load
a timer a counter
in BCD
1)
±0,1469368 x 10
-38
to ±0,1701412 x 10
39
Load operations
Load operations wr ite the addressed value in to ACCU 1. The former contents of ACCU 1 are saved in ACCU 2 (stack lift).
Transfer operations
Transfer op erat ions writ e the conte nts of ACCU 1 to the addre sse d memo ry lo ca t ion .
Table 3-5 Load and transfer operat ions /p art 2
Basic Operations
CPU 948 Programming Guide
3 - 22 C79000-G8576-C848-04
Page 95
Examples of load a nd transfer operations
Example 1:
Fig. 3-6 illustrates loading/transferring a byte, word or double word from/to a memory area organized in
bytes (PII, PIQ, flags, I/O).
:L IB i load byte i of the PII into ACCU-1-LL :L IW j load bytes j and j+1 of the PII into ACCU-1-L :L FD k load flag bytes k to k+3 in ACCU 1
ACCU 1
ACCU 1
ACCU 1
j
j+1
i
k k+1 k+2 k+3
31 23 15 7 0
31 23 15 7 0
31 23 15 7 0
k+1 k+2 k+3
00jj+1
000i
70
Addresses in ascending order
k
1) 1)
1) 1)
1)
LIBi TIBi
TIWj
LIWj
TFDk
LFDk
1)
only with load operations
Fig. 3-6 Load and transfer operations in a byte-oriented memory area
Basic Operations
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 23
Page 96
Note Load operati o ns do not affect the c ondit ion code s . Transfer oper ation s cle a r the OS bit.
When a byte or word is loaded the extr a bits are cleared in ACCU 1.
Example 2:
Fig. 3-7 illustrates the loading/transfer of a byte, word or double word from/into a memory area organized in
words.
:L DR i load the right byte of data word i into ACCU-1-LL :L DL j load the left byte of data word j into ACCU-1-LL :L DW k load data word k into ACCU-1-L :L DD l load data words l and l+1 into ACCU 1
l
l+1
k
31 23 15 7 0
31 23 15 7 0
31 15 0
31
15
0
ACCU 1
ACCU 1
ACCU 1
ACCU 1
15 0
l
l+1
k
j
0
00i
000
1) 1) 1)
0
1) 1) 1)
1)
left byte
Data word j
LDRi TDRi
LDLj TDLj
LDWk TDWk
LDDl TDDl
right byte
Data word i
Addresses in ascending order
1)
only with load operations
Fig. 3-7 Load and transfer oper ati ons in a word-ori ente d mem or y area
Basic Operations
CPU 948 Programming Guide
3 - 24 C79000-G8576-C848-04
Page 97
Addressing I/Os
You can use load and t ra nsfe r ope ra tions to address the I/ O peripherals as follows:
•• directly using the following operati ons:
L../T. . ..PY, ..PW, ..OY, ..OW
or
•• using the process image with the following ope r ations:
L../T.. ..IB, ..IW, ..ID, .QB, ..QW, ..QD
and with logic and set/reset operations
Note
If you use the transfe r ope ra tions T PY 0 to 127 and T PW 0 to 126, the proce ss out put imag e is upda te d at the sam e time . Exception: command outpu t is disabled by the STEP 5 operat ion BAS (refer to Section 3.5. 4).
Note the following points about I/O peri phe ra ls:
•• A process input/ou tpu t ima ge ex ist s for 128 input a nd 128 output
bytes of t he P peripherals with byte addres se s from 0 to 127.
•• No process image exist s for t he entir e are a of the O perip he ra ls a nd
the P periph eral s wit h rela tive byt e addr esse s fro m 128 to 256. (For more inform a ti on on a ddr ess spa c e alloc a ti on se e Sec ti on 8. 2.2).
•• I/O modules with addresse s of t he O periphe ra ls ca n onl y be plu g-
ged into expa nsio n uni ts (not in the centra l cont rol le r) .
•• In one expansion unit, you can use either only P peripherals or
only O peripherals.
Caution
If you use relative addresses of the O peripherals in an expansion unit, you can no long er use t he se addr esses for I/O modul es in th e central co ntr olle r (th is would re sul t in double addre ssing ).
Basic Operations
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 25
Page 98
Timer and Counter operations
To load a timer using a start opera ti on or a counte r usin g a set operatio n, you m ust first load the value in ACCU 1.
The followi ng l oa d ope ra tions a re pre fe ra bl e:
For timers: L KT, L IW, L QW, L FW, L DW, L SW. For counters: L KC, L IW, L QW, L FW, L DW, L SW.
Starti ng a timer with the selecte d tim e r va lue re qui re s an RLO signal change .
A counter is set or started with the selected counter value when a positive-going RLO signal edge is detected.
The following table indica te s the signal edge change with corresponding arrows.
Operation Operand RLO1)Function
SP SE SD SS SF R
T 0 to 255 T 0 to 255 T 0 to 255 T 0 to 255 T 0 to 255 T 0 to 255
↑ ↑ ↑ ↑ ↓
1
Start a timer as a pulse Start a timer as extended pulse Start a timer as ON delay Start a timer as stor ed ON del ay Start a timer as OFF delay Reset a timer
S R CU CD
C 0 to 255 C 0 to 255 C 0 to 255 C 0 to 255
1
↑ ↑
Set a counte r (BCD numb er from 0 to 999) Reset a counter Count up Count down
1)
positive-going edge ( ↑ ): signal change from ’0’ to ’1’ neg ative-going ed ge (): signal change from ’1’ to ’0’
When executing the timer or counter operations SP T, SE T, SD T, SS T, SF T and S C the value in ACCU 1 is transferred to the timer or counter (as wit h the tr ansfe r ope ra tion) and the approp riat e oper at ion is started.
Table 3-6 Timer and c ount e r opera t ions
Basic Operations
CPU 948 Programming Guide
3 - 26 C79000-G8576-C848-04
Page 99
Timer value
With the operation L KT, you can load a timer value directly into ACCU 1 or indirectly from a flag or data word. The value must have the following structure (with L KT, you specify the time base after the period in the operand as shown below):
Example
Note
The start of each timer is liable to an inaccuracy of 1 time base! When using timer s, yo u should ther ef ore sele ct the smal lest possible time ba se (time base < time r va l ue):
Example:
time value 4s not: 1 s x 4 inaccuracy: 1 s
but: 0.01 s x 400 inaccura cy : 0.01 s
You want to set a time of 127 sec.:
Bit assignment:
Timer value 127
0111
0
0
0
0
0
0
0
x
x
1
1
1
1
7
22
Irrelevant
Time base 1 sec
Bit no.
Timer value 0 ... 999 in BCD
012
3
4
5
6
7
8
9
10
11
12
15
14
13
2
10
10
0
10
1
These bits are irrelevant (i.e. they are ignored when the timer is started)
Time base specified in BCD:
0: 0.01 sec 1: 0.1 sec
2: 1 sec 3: 10 sec
Basic Operations
CPU 948 Programming Guide C79000-G8576-C848-04
3 - 27
Page 100
Counter value
With the operation L KC, you can load a counter v alue dir ectly in ACCU 1 or indirectly from a flag or a data word. The va lue m ust ha ve the following structure:
Example
In the timer or counter itself, the value is in binary code. If you want to scan the tim er or count er , you can loa d the act ual tim e r or count e r value into ACCU 1 directly or in BCD code.
Counter value 127
01
1
1
0
0
0
0
0
0
x
xx
x
1
1
1
7
2
Irrelevant
Bit no.
Counter value 0 ... 999
specified in BCD
012
3
4
5
6
7
8
9
10
11
12
15
14
13
10
2
10
0
10
1
These bits are irrelevant, (i.e. they are ignored when the counter is set
)
You want to specify a counter value of 127:
Bit assignment:
Basic Operations
CPU 948 Programming Guide
3 - 28 C79000-G8576-C848-04
Loading...