You are on page 1of 10

Automating with

STEP7 in STL and SCL


Programmable Controllers
SIMATIC S7-300/400

by Hans Berger

3rd revised edition, 2005

Publicis Corporate Publishing


Table ofContents

Table of Contents

Introduction . . . . . . . . . . . . . . . . 21 2 STEP 7 Programming Software . 47

1 SIMATIC S7-300/400 2.1 STEP 7 Basic Package . . . . . . . 47


Programmable Controller . . . . 22 2.1 .1 Installation . . . . . . . . . . . . . 47
1 .1 2.1 .2 Automation License Manager . . . 47
Structure ofthe
2.1 .3 SIMATIC Manager . . . . . . . . . 48
Programmable Controller . . . . . 22
2.1 .4 Projects and Libraries. . . . . . . . 49
1 .1 .1 Components . . . . . . . . . . . . 22 2.1 .5 Multiprojects . . . . . . . . . . . . 51
1 .1 .2 S7-300 Station . . . . . . . . . . . 22 2.1 .6 Online Help . . . . . , . . . . . , . 52
1 .1 .3 57-400 Station . . . . . . . . . . . 24 2.2 Edng Projects . . . . . . . . . . . 52
1 .1.4 Fault-Tolerant SIMATIC . . . . . 25
1 .1 .5 2 .2 .1 Creating Projects . . . . . . . , . . 52
Safety-Relevant SIMATIC . , . , 26
2.2.2 Managing, Rearranging and
1 .1 .6 CPU Memory Areas . . . . . . . . 27 Archiving . . . . . . . . , , , . . . 54
1 .2 Distributed UO. . . . . . . . . . . 31 2.2.3 Project Versions . . . . . . . . . , 54
1 .2.1 DP Master System . . . . . . . . , 31 2.2.4 Creating and Editing Multiprojects . 55
1 .2.2 DP Master . . . . . . . . . , . . , 32 2 .3 Configuring Stations . . . . . . . . 56
1 .2.3 DP Slaves . . . . . . . . . , . . . 32 2.3.1 Arranging Modules . . . . . . , . . 58
1 .2.4 Further Network Components . . . 33 2.3.2 Addressing Modules . . . . . . . . 58
1 .2.5 Connection to PROFIBUS PA . . 34 2.3 .3 Parameterizing Modules . . . . . . 58
1 .2.6 Connection to AS-Interface . . . . 34 2.3 .4 Networking Modules with MPI . . 59
1 .2.7 Connection to a Serial Interface . . 35 2 .3 .5 Monitoring and Modifying
1 .3 Modules . . . . . . , . , . , , , , , 59
Communications . . . . . . . . , . 36
2 .4 Configuring the Network . . . . . 59
1 .3.1 Introduction . . . . . . . , , . , . 36 '
1 .3.2 Subnets . . . , . . . . , . , , , , 37 2 .4.1 Configuring the Network View. . , 60
1 .3.3 Communications Services . . . . . 39 2.4.2 Configuring a DP Master System
1.3.4 Connections . . . . , . . , , , , , 40 with the Network Configuration . . 61
2.4.3 Configuring Connections . . , . , . 62
1.4 Module Addresses . . . . , . . . . 41 2.4.4 Network Transitions . . . . . . . . 65
1 .4.1 Signal Path. . . . . . . . . . . , , 41 2.4.5 Loading the Connection Data , . . 66
1 .4.2 Slot Address . . . . . . , , , , , , 42 2 .4.6 Adjusting Projects in the
1 .4.3 Module Start Address . . . . . . . 42 Multiproject . . . . . , . , , , , , , 66
1 .4.4 Diagnostics Address . . . . . . . . 43 2 .5 Creating the S7 Program , , , , , , 68
1 .4.5 Addresses for Bus Nodes . . . . . 43 2.5.1 Introduction . . . . . . . , , , , , , 68
1.5 Address Areas , . . . . . . . . . , 43 2.5.2 Symbol Table . . , . , . , . , , , , 68
2.5.3 STL Program Editor , . , , , , , 70
1,5,1 User Data Area . , . . . . . . . . 43 2.5.4 SCL Program Editor . . , . , , . , 74
1 .52 Process Image . . . . . . . , . . 44 2.5 .5 Rewiring . . . . . . . , , , , , , , 77
1 .5.3 Consistent User Data . . . , , . , 45 2.5.6 Address Priority . , . . , , , , , , 78
1 .5.4 Bit Memories , . . . . . . . , . . 46 2.5 .7 Reference Data . . . , , , , , , , , 79
Table of Contents

2.5 .8 Multilingual Comments and 3.5 Programming Code Blocks


Display Texts . . . . . . . . . . . 80 with SCL . . . . . . . . . . . . . 117
2 .6 Online Mode . . . . . . . . . . . . 81 3.5 .1 Structure of an SCL Statement . . 117
2 .6 .1 Connecting a PLC . . . . . . . . . 81 3.5 .2 Programming SCL Code Blocks . 117
2 .6 .2 Protecting the User Program . . . . 82 3.6 Programming Data Blocks . . . . 121
2 .6 .3 CPU Information . . . . . . . . . . 83 3 .6.1 Programming Data Blocks
2 .6 .4 Loading the User Program into
Incrementally . . . . . . . . . . . 121
the CPU . . . . . . . . . . . . . . 83 3 .6.2 Source-Oriented Data Block
2.6 .5 Block Handling . . . . . . . . . . 84
Programming . . . . . . . . . . . 124
2.7 Testing the Program . . . . . . . . 87 3 .7 Variables and Constants . . . . . 126
2.7 .1 Diagnosing the Hardware . . . . . 87
3.7.1 General Remarks Concerning
2.7 .2 Determining the Cause of a STOP . 87
Variables . . . . . . . . . . . . . 126
2.7 .3 Monitoring and Modifying
3.7.2 General Remarks Regarding
Variables . . . . . . . . . . . . . . 87
Data Types . . . . . . . . . . . . 126
2.7 .4 Forcing Variables . . . . . . . . . 89
3.7.3 Elementary Data Types . . . . . . 127
2.7 .5 Enabling Peripheral Outputs . . . . 90
3.7.4 Complex Data Types . . . . . . . 127
2.7 .6 STL Program Status . . . . . . . . 91
3.7.5 Parameter Types . . . . . . . . . 130
2.7 .7 Monitoring and Controlling Data
Addresses . . . . . . . . . . . . . 93 Basic Functions . . . . . . . . . . . . . 131
2.7 .8 Debugging SCL Programs . . . . . 93
4 Binary Logic Operations . . . . 132
3 SIMATIC S7 Program . . . . . . 96
4.1 Processing a Binary Logic
3.1 Program Processing . . . . . . . . 96
Operation . . . . . . . . . . . . . 132
3 .1 .1 Program Processing Methods . . . 96
4.2 Elementary Binary Logic
3 .1 .2 Priority Classes . . . . . . . . . . 97
Operations . . . . . . . . . . . . . 134
3 .1 .3 Specifications for Program
Processing . . . . . . . . . . . . . 98 4.2 .1 AND Function . . . . . . . . . . 135
4.2 .2 OR Function . . . . . . . . . . . 135
3 .2 Blocks . . . . . . . . . . . . . . 100
4.2 .3 Exclusive OR Function . . . . . . 135
3 .2 .1 Block Types . . . . . . . . . . . 100
4.3 Negating the Result of the
3.2 .2 Block Structure . . . . . . . . . 101
Logic Operation . . . . . . . . . . 137
3.2 .3 Block Properties . . . . . . . . . 103
3.2 .4 Block Interface . . . . . . . . . . 105 4.4 Compound Binary Logic
Operations . . . . . . . . . . . . . 137
3.3 Addressing Variables . . . . . . 107
4.4.1 Processing Nesting Expressions . 138
3.3 .1 Absolute Addressing of Variables 107
3.3 .2 Indirect Addressing . . . . . . . 108 4.4.2 Combining AND Functions
According to OR . . . . . . . . . 140
3.3 .3 Symbolic Addressing of Variables 108
4.4.3 Combining OR and Exclusive OR
3.4 Programming Code Blocks Functions According to AND. . . 140
with STL . . . . . . . . . . . . . 110 4.4 .4 Combining AND Functions
3.4 .1 Structure of an STL Statement . . 110 According to Exclusive OR . . . . 140
3.4 .2 Programming STL Code Blocks 4.4 .5 Combining OR Functions and
Incrementally . . . . . . . . . . 110 Exclusive OR Functions . . . . . 141
3.4 .3 Overview Window . . . . . . . . 111 4.4 .6 Negating Nesting Expressions . . 141
3.4 .4 Programming Networks . . . . . 112
5 Memory Functions. . . . . . . . 142
3 .4 .5 Source-File-Oriented Program-
ming of STL Code Blocks . . . . 113 5.1 Assign . . . . . . . . . . . . . . . 142
Table ofContents

5.2 Set and Reset . . . . . . . . . . 142 6.6.6 Writing into the Load Memory . . 162
5.3 RS Flipflop Function . . . . . . 144 7 Timer Functions . . . . . . . . . 164
5.3.1 Memory Functions with Reset 7.1 Programming a Timer . . . . . . 164
Priority . . . . . . . . . . . . . . 144
5.3.2 Memory Function with Set 7.1 .1 Starting a Timer . . . . . . . . . 164
Priority . . . . . . . . . . . . . . 144 7.1 .2 Specifying the Time . . . . . . . 165
5.3 .3 Memory Function in a Binary 7.1 .3 Resetting a Timer. . . . . . . . . 166
Logic Operation . . . . . . . . . 144 7.1 .4 Enabling a Timer . . . . . . . . . 166
5.4 Edge Evaluation . . . . . . . . . 145 7.1 .5 Checking a Timer. . . . . . . . . 166
7.1 .6 Sequence ofTimer Instructions . 167
5 .4.1 Positive Edge . . . . . . . . . . 146 7 .1 .7 Clock Generator Example . . . . 167
5.4.2 Negative Edge . . . . . . . . . . 146
5.4.3 Testing a Pulse Memory Bit. . . 147 7.2 Pulse Timers . . . . . . . . . . . 168
5.4.4 Edge Evaluation in a Binary 7.3 Extended Pulse Timers . . . . . . 170
Logic Operation . . . . . . . . . 147 7 .4 On-Delay Timers . . . . . . . . . 172
5.4.5 Binary Scaler . . . . . . . . . . 148
7.5 Retentive On-Delay Timers . . . 174
5.5 Example of a Conveyor Belt
Control System . . . . . . . . . 148 7.6 Off-Delay Timers . . . . . . . . . 176
7 .7 IEC Timer Functions . . . . . . . 178
6 Move Functions . . . . . . . . . 152
6 .1 7.7.1 Pulse Generation SFB 3 TP . . . 178
General Remarks on Loading
and Transferring Data . . . . . . 7.7.2 On Delay SFB 4 TON . . . . . . 179
152
7.7.3 Off Delay SFB 5 TOF . . . . . . 179
6.2 Load Functions . . . . . . . . . 154
6.2.1 General Representation of a 8 Counter Functions . . . . . . . 180
Load Function . . . . . . . . . . 154 8.1 Setting and Resetting Counters . . 180
6.2.2 Loading the Contents of 8.2 Counting . . . . . . . . . . . . . 181
Memory Locations . . . . . . . 154
6.2.3 Loading Constants . . . . . . . . 155 8 .3 Checking a Counter . . . . . . . . 182
6.3 Transfer Functions . . . . . . . . 156 8.4 Enabling a Counter . . . . . . . . 182
6.3.1 General Representation of a 8.5 Sequence ofCounter Instructions 183
Transfer Function . . . . . . . . 156 8.6 IEC Counter Functions . . . . . . 184
6.3.2 Transferring to Various Memory
8.6 .1 Up Counter SFB 0 CTU . . . . . 184
Areas . . . . . . . . . . . . . . . . . 156
8.6.2 Down Counter SFB 1 CTD . . . . 184
6.4 Accumulator Functions . . . . . 157 8.6 .3 Up-Down Counter SFB 2 CTUD. 185
6.4.1 Direct Transfers Between 8.7 Parts Counter Example . . . . . . 185
Accumulators . . . . . . . . . . 157
6.5 Exchange Bytes in Accumulator 1 . 158 Digital Functions . . . . . . . . . . . . .189
6.6 System Functions for Data 9 Comparison Functions . . . . . 190
Transfer . . . . . . . . . . . . . 159
9.1 General Representation of a
6.6.1 Copying Memory Area . . . . . 160 Comparison Function . . . . . . . 190
6.6.2 Uninterruptible Copying of
Variables . . . . . . . . . . . . . 160 9.2 Description of the Comparison
6 .6.3 Initializing a memory area. . . . 161 Functions . . . . . . . . . . . . . 191
6.6.4 Copying STRING Variables . . 161 9.3 Comparison Function in a Logic
6.6.5 Reading from Load Memory . . 161 Operation . . . . . . . . . . . . . 192
Table of Contents

10 Arithmetic Functions . . . . . . 194 Program Flow Control . . . . . . . . . 217


10 .1 General Representation of an 15 Status Bits . . . . . . . . . . . . 218
Arithmetic Function . . . . . . . 194
15 .1 Description of the Status Bits . . . 218
10 .2 Calculating with Data Type
INT . . . . . . . . . . . . . . . . 195 15 .2 Setting the Status Bits and the
Binary Flags . . . . . . . . . . . . 220
10 .3 Calculating with Data Type
15 .3 Evaluating the Status Bit . . . . . 222
DINT . . . . . . . . . . . . . . . . 196
15 .4 Using the Binary Result . . . . . . 224
10 .4 Calculating with Data Type
REAL . . . . . . . . . . . . . . 197 16 Jump Functions . . . . . . . . . 226
10 .5 Successive Arithmetic 16 .1 Programming a Jump Function . . 226
Functions . . . . . . . . . . . . . 198
16,2 Unconditional Jump . . . . . . . . 227
10 .6 Adding Constants to
16 .3 Jump Functions with RLO and
Accumulator 1 . . . . . . . . . . 199
BR . . . . . . . . . . . . . . . . . 227
10 .7 Decrementing and
16 .4 Jump Functions with
Incrementing . . . . . . . . . . . 199
CCO and CC 1 . . . . . . . . . . . 228
11 Math Functions . . . . . . . . . 201 16 .5 Jump Functions with
OV and OS . . . . . . . . . . . . 230
11 .1 Processing a Math Function . . . 201
16 .6 Jump Distributor . . . . . . . . . 230
11 .2 Trigonometric Functions . . . . . 202
16 .7 Loop Jump . . . . . . . . . . . . 231
11 .3 Are Functions . . . . . . . . . . 202
11 .4 Other Math Functions . . . . . . 202 17 Master Control Relay . . . . . . 232
17 .1 MCR Dependency . . . . . . . . 232
12 Conversion Functions . . . . . 204
17 .2 MCR Area . . . . . . . . . . . . . 233
12 .1 Processing a Conversion
Function . . . . . . . . . . . . . 204 17 .3 MCR Zone . . . . . , . . . . . . 233
17 .4 Setting and Resetting I/O Bits . . 234
12 .2 Converting 1NT and DINT
Numbers . . . . . . . . . . . . . 205 18 Block Functions . . . . . . . . . 236
12 .3 Converting BCD Numbers. . . . 205 18,1 Block Functions for Code Blocks . 236
12 .4 Converting REAL Numbers . . . 206 18 .1 .1 Block Calls: General . . . . . . . 237
12,5 Other Conversion Functions . . . 207 18 .1 .2 CALL Call Statement, . . . . . . 237
18 .1 .3 UC and CC Call Statements . . . 238
13 Shift Functions . . . . . . . . . 209 18 .1 .4 Block End Functions . . . . . . . 239
13 .1 Processing a Shift Function . . , 209 18 .1 .5 Temporary Local Data . . . . . . 239
18 .1 .6 Static Local Data . . . . . . . . . 242
13 .2 Shifting . . . . . . . . . . . . . . 210
18 .2 Block Functions for Data Blocks . 244
13 .3 Rotating . . . . . . . . . . . . . 212
18 .2 .1 Two Data Block Registers . . . . 244
14 Word Logic . . . . . . . . . . . 214 18 .2 .2 Accessing Data Addresses . . . . 245
18 .2 .3 Open Data Block . . . . . . . . . 247
14.1 Processing a Word Logic 18 .2 .4 Exchanging the Data Block
Operation. . . . . . . . . . . . . 214 Registers . . . . . . . . . . . . . 248
14.2 Description of the Word Logic 18 .2 .5 Data Block Length and Number . 248
Operations . . . . . . . . . . . . 216 18 .2 .6 Special Points in Data Addressing 248
Table of Contents

18 .3 System Functions for Data 20.3 Program Functions . . . . . . . . 277


Blocks . . . . . . . . . . . . . . 250
20.3 .1 Time . . . . . . . . . . . . . . . 278
18 .3 .1 Creating a Data Block in the 20.3 .2 Read System Clock . . . . . . . . 280
Work Memory . . . . . . . . . . 250 20 .3 .3 Run-Time Meter . . . . . . . . . 280
18 .3 .2 Creating a Data Block in the 20 .3 .4 Compressing CPU Memory . . . 282
Load Memory . . . . . . . . . . 251 20 .3 .5 Waiting and Stopping . . . . . . 282
18 .3 .3 Deleting a Data Block . . . . . . 252 20 .3 .6 Multiprocessing Mode . . . . . . 282
18 .3 .4 Testing a Data Block . . . . . . 252 20 .4 Communication via
18 .4 Null Operations . . . . . . . . . 252 Distributed I/O . . . . . . . . . . 283
18 .4.1 NOP Statements . . . . . . . . . 252 20 .4 .1 Addressing Distributed I/O . . . . 284
18 .4.2 Program Display Statements . . 253 20 .4 .2 Configuring Distributed I/O . . . 288
20 .4 .3 Special Functions for
19 Block Parameters . . . . . . . 254 Distributed I/O . . . . . . . . . . 294
19 .1 Block Parameters in General . . 254 20.4 .4 System Functions for
Distributed I/O . . . . . . . . . . 298
19 .1 .1 Defining the Block
Parameters . . . . . . . . . . . . 254 20 .5 Global Data Communication . . . 303
19 .1 .2 Processing the Block 20 .5 .1 Fundamentals . . . . . . . . . . . 303
Parameters . . . . . . . . . . . . 254 20 .5 .2 Configuring GD communication . 305
19 .1 .3 Declaration of the Block 20 .5 .3 System Functions for GD
Parameters . . . . . . . . . . . . 255 Communication . . . . . . . . . . 307
19 .1 .4 Declaration of the Function
Value . . . . . . . . . . . . . . 256 20 .6 S7 Basic Communication. . . . . 307

19 .1 .5 Initializing Block Parameters . . 257 20.6 .1 Station-Internal S7 Basic


Communication . . . . . . . . . . 307
19 .2 Formal Parameters . . . . . , , , 257
20 .6 .2 System Functions for Data
19 .3 Actual Parameters . . . . . . . . 260 Interchange within a Station . . . 309
19 .4 "Passing On" Block Parameters . 263 206 .3 Station-External S7 Basic
Communication . . . . . . . . . . 310
19 .5 Examples . . . . . . . . . . . . 264
20 .6 .4 System Functions for Station-Ex-
19 .5 .1 Conveyor Belt Example . . . . . 264 ternal S7 Basic Communication . 311
19 .5 .2 Parts Counter Example . . . . . 265
20 .7 S7 Communication . . . . . . . . 313
19 .5 .3 Feed Example . . . . . . . . . . 265
20 .7 .1 Fundamentals . . . . . . . . . . . 313
Program Processing . . . . . . . . . . . 269 20 .7 .2 Two-Way Data Exchange . . . , 315
20 .7 .3 One-Way Data Exchange . . . . . 317
20 Main Program . . . . . . . . . 270 20 .7 .4 Transferring Print Data . . . . . . 318
20 .1 Program Organization . . . . . . 270 207 .5 Control Functions. . . . . . . . , 318
20 .7 .6 Monitoring Functions. . . . . . . 319
20 .1 .1 Program Structure . . . . . . . . 270
20 .1 .2 Program Organization . . . . . . 271 20 .8 PtP Communication with S7-300C 322

20 .2 Scan Cycle Control . . . . . . . 272 208 .1 Fundamentals . . . . . . . . . . . 322


20 .8 .2 ASCII Driver and 3964(8)
20 .2.1 Process Image Updating . . . . . 272 Procedure , . . . . . , , . , . . . 324
20 .2 .2 Scan Cycle Monitoring Time . . 274
20 .8 .3 RK512 Computer Link . . , . . , 325
20 .2.3 Minimum Scan Cycle Time,
Background Scanning . . . . . . 275 20 .9 Configuration in RUN . . , . . . 328
20 .2.4 Response Time . . . . . . , . . 276 20 .9 .1 Preparation of Modifications to
20 .2.5 Start Information . . . . . . . . 276 Configuration . . . . . , . . , . . 328
Table of Contents

20 .9 .2 Changing the Configuration . . . 330 21 .9 .3 Reading Additional Interrupt


20 .9 .3 Loading the Configuration . . . . 330 Information . . . . . . . . . . . . 350
20 .9 .4 CiR Synchronization Time . . . . 331
22 Restart Characteristics . . . . . 353
20 .9 .5 Effects on Program Execution . . 331
20 .9 .6 Controlling the CiR Procedure. . 332 22 .1 General Remarks . . . . . . . . . 353

21 22 .1 .1 Operating Modes . . . . . . . . . 353


Interrupt Handling . . . . . . . 333
22 .1 .2 HOLD Mode . . . . . . . . . . . 354
21 .1 General Remarks . . . . . . . . . 333 22 .1 .3 Disabling the Output Modules . . 354
21 .2 Time-of-Day Interrupts . . . . . 334 22 .1 .4 Restart Organization Blocks . . . 354

21 .2 .1 Handling Time-of-Day Interrupts 335 22 .2 Power-Up . . . . . . . . . . . . . 355


21 .2 .2 Configuring Time-of-Day 22 .2 .1 STOP Mode . . . . . . . . . . . . 355
Interrupts with STEP 7. . . . . . 336 22 .2 .2 Memory Reset. . . . . . . . . . . 356
21 .2 .3 System Functions for Time-of- 22 .2 .3 Retentivity . . . . . . . . . . . . 356
Day Interrupts . . . . . . . . . . 336 22 .2 .4 Restart Parameterization . . . . . 356
21 .3 Time-Delay Interrupts . . . . . . 337 22 .3 Types of Restart . . . . . . . . . . 357
21 .3 .1 Handling Time-Delay Interrupts . 338 22.3 .1 START-UP Mode . . . . . . . . . 357
21 .3 .2 Configuring Time-Delay 22.3 .2 Cold Restart . . . . . . . . . . . . 357
Interrupts with STEP 7. . . . . . 339 22.3 .3 Warm Restart . . . . . . . . . . . 359
21 .3 .3 System Functions for Time- 22.3 .4 Hot Restart . . . . . . . . . . . . 359
Delay Interrupts . . . . . . . . . 339 22 .4 Ascertaining a Module Address. . 360
21 .4 Watchdog Interrupts . . . . . . . 340 22 .5 Parameterizing Modules . . . . . 362
21 .4.1 Handling Watchdog Interrupts . . 340 22 .5 .1 General Remarks on
21 .4.2 Configuring Watchdog Interrupts Parameterizing Modules . . . . . 362
with STEP 7 . . . . . . . . . . . 341 22.5 .2 System Functions for Module
21 .5 Hardware Interrupts . . . . . . . 342 Parameterization . . . . . . . . . 363
22.5 .3 Blocks for Data Record Transfer . 364
21 .5 .1 Generating a Hardware Interrupt 342
21 .5 .2 Servicing Hardware Interrupts . . 343 23 Error Handling . . . . . . . . . 367
21 .5 .3 Configuring Hardware Interrupts
23 .1 Synchronous Errors . . . . . . . . 367
with STEP 7 . . . . . . . . . . . 344
23 .2 Synchronous Error Handling . . . 369
21 .6 DPV1 Interrupts . . . . . . . . . 344
23 .2 .1 Error Filters . . . . . . . . . . . . 369
21 .7 Multiprocessor Interrupt . . . . . 346
23 .2 .2 Masking Synchronous Errors . . . 370
21 .8 Synchronous Cycle Interrupts . . 347 23 .2 .3 Unmasking Synchronous Errors . 370
21 .8 .1 Processing Synchronous Cycle 23 .2 .4 Reading the Error Register . . . . 370
Interrupts . . . . . . . . . . . . . 347 23 .2 .5 Entering a Substitute Value . . . . 371
21 .8 .2 Isochrone Updating of Process 23 .3 Asynchronous Errors . . . . . . . 371
Image. . . . . . . . . . . . . . . 348
23 .4 System Diagnostics . . . . . . . . 374
21 .8 .3 Programming of Synchronous
Cycle Interrupts with STEP 7 . . 349 23 .4 .1 Diagnostic Events and
Diagnostic Buffer . . . . . . . . . 374
21 .9 Handling Interrupts . . . . . . . 349
23 .4.2 Writing User Entries in the
21 .9 .1 Disabling and Enabling Interrupts 349 Diagnostic Buffer . . . . . . . . . 374
21 .9 .2 Delaying and Enabling Delayed 23 .4.3 Evaluating Diagnostic Interrupts . 375
Interrupts . . . . . . . . . . . . . 350 23 .4 .4 Reading the System Status List . . 375
Table of Contents

Variable Handling. . . . . . . . . . . . 378' 25.4.1 Using Address Register ARl . . . 401


25.4.2 Using Address Register AR2 . . . 403
24 Data Types . . . . . . . . . . . 379 25.4.3 Restrictions with Static Local
24.1 Elementary Data Types . . . . . 379 Data . . . . . . . . . . . . . , , , 403
24.1.1 Declaration of Elementary 26 Direct Variable Access . . . . . 405
Data Types . . . . . . . . . . . . . 379
261
.dress Lding
oa the VariableAd . . 405
24.1 .2 BOOL, BYTE, WORD,
DWORD, CHAR . . . . . . . . 380 26.2 Data Storage of Variables . . . . 406
24.1 .3 Number Representations . . . . 381 26.2.1 Storage in Global Data Blocks . . 406
24.1 .4 Time Representations . . . . . . 383 26.2.2 Storage in Instance Data Blocks . 407
24.2 Complex Data Types . . . 384 26.2.3 Storage in the Temporary Local
Data . 407
24.2.1 DATE_AND TIME. . . . . . . 384 . . . . . . . . . . . . . .
24.2.2 STRING . . . . . . . . . . . , . 385 26.3 Data Storage when Transferring
24.2 .3 ARRAY . . . . . . . . . . . . . 386 Parameters . . . . . . . . . , . . 410
24.2.4 STRUCT . . . . . . . . . . . . . 388 26.3 .1 Parameter Storage in Functions . 410
24.3 User-Defined Data Types . . . . 390 26 .3 .2 Storing Parameters in Function
Blocks . . . . . . . , , , , 412
24.3.1 Programming UDTs 26.3 .3 "Variable" ANY Pointer . . . . . 412
Incrementally . . . . . . . . . . 390
24.3 .2 Source-File-Oriented 26.4 Brief Description ofthe Message
Frame Example . . . . . . , , . . 414
Programming of UDTs . . . . . 390
25 Indirect Addressing . . . . . . 392 Structured Control Language (SCL) . .421
25.1 Pointers . . . . . . . . . . , . , 392 27
Introduction, Language
25.1 .1 Area Pointer . . . . . . . . . . , Elements . . . . . . . . . . .
392 . . 422
25.1 .2 DB Pointer . . . . . . . . . . . , 27 .1 Integration in SIMATIC . . .
392 . . 422
25 .1 .3 ANY Pointer . . . . . . . . . . . 394
27.1 .1 Installation . . . . . . . . . . , . 422
25.2 Types of Indirect Addressing 27.1 .2 Setting Up a Project . . . . . . . 422
in STL . . . . . . . , , , , . . . 395 27.1 .3 Editing the SCL Source . . . . . 422
25.2.1 General . . . . 27.1 .4 Completing the Symbol Table . . 423
395
25.2 .2 Indirect Addresses . . . . . . . . 395 27.1 .5 Compiling the SCL Program . . . 424
27.1 .6 Loading SCL Blocks . . . . . . 424
25.2.3 Memory-Indirect Addressing . . 396
27.1 .7 Testing SCL Blocks . . . . 424
25.2.4 Register-Indirect Area-Internal
27.1 .8 Addresses and Data Types . . . . 424
Addressing. . . . . . . . . . . . 396 27.1 .9 Data Type Views . . . . . . . . 426
25.2.5 Register-Indirect Area-Crossing
Addressing . . . . . . . , , , , 398 27 .2 g . . . . . . 426
25.2.6 Summary . . . . . . . . . . . . 398 27.2.1 Absolute Addressing . . . . . . . 426
25.3 Working with Address Registers 399 27.2.2 Symbolic Addressing . . . 426
2723
. .nrecressngn
Idit Addi i SCL . . . 427
25.3.1 Loading into an Address Register 399
25.3.2 Transferring from an Address 27.3 Operators . . . . . , , , , , , , , 429
Register . . . . . . . . , , . . . 399 27 .4 Expressions . . . . . , . , , , , . 429
25.3.3 Swap Address Registers . . . . . 399 27.4.1 Arithmetic Expressions . . . . . . 429
25.3.4 Adding to the Address Register . 399 27.4.2 Comparison Expressions . . . . . 431
25.4 Special Features ofIndirect 27 .4.3 Logical Expressions . . . . . , . 431
Addressing. . . . . . . . . . , . 401 27.5 Value Assignments . . . . . . . . 432
Table of Contents

27.5 .1 Assignment for Elementary 30 SCL Functions . . . . . . . . . . 447


Data Types . . . . . . . . . . . . 432
30 .1 Timer Functions. . . . . . . . . . 447
27.5 .2 Assignment of DT and STRING
Variables . . . . . . . . . . . . . 432 30 .2 Counter Functions. . . . . . . . . 448
27.5 .3 Assignment of Structures . . . 432 30 .3 Math Functions . . . . . . . . . . 449
27 .5 .4 Assigning Fields . . . . . . . . . 432
30 .4 Shifting and Rotating . . . . . . . 449
28 Control Statements . . . . . . . 433 30 .5 Conversion Functions . . . . . . . 450
28 .1 IF Statement . . . . . . . . . . . 433 30 .5 .1 Implicit Conversion Functions . . 450
28 .2 CASE Statement . . . . . . . . . 434 30 .5 .2 Explicit Conversion Functions . . 450

28 .3 FOR Statement . . . . . . . . . . 434 30 .6 Programming Your Own


Functions with SCL . . . . . . . . 452
28 .4 WHILE Statement . . . . . . . . 435
30.7 Programming Your Own
28 .5 REPEAT Statement . . . . . . . 435 Functions with STL . . . . . . . . 454
28 .6 CONTINUE Statement . . . . . 436 30.8 BriefDescription of the SCL
28 .7 EXIT Statement . . . . . . . . . 436 Examples . . . . . . . . . . . . . 454

28 .8 RETURN Statement . . . . . . . 436 30 .8 .1 Conveyor Example . . . . . . . . 454


30 .8 .2 Message Frame Example . . . . . 455
28 .9 GOTO Statement. . . . . . . . . 436 30 .8 .3 General Examples . . . . . . . . . 456
29 SCL Blocks . . . . . . . . . . . 438 31 IEC Functions . . . . . . . . . . 457
29 .1 SCL Blocks - General . . . . . . 438 31 .1 Conversion Functions . . . . . . . 457
29 .2 Programming SCL Blocks . . . . 438
31 .2 Comparison Functions . . . . . . 459
29 .2 .1 Function FC without a Function 31 .3 STRING Functions . . . . . . . . 460
Value . . . . . . . . . . . . . . . 439
29 .2 .2 Function FC with Function 31 .4 Date/Time-of-Day Functions . . . 462
Value . . . . . . . . . . . . . . . 439 31 .5 Numerical Functions . . . . . . . 463
29 .2 .3 Function Block FB . . . . . . . . 439
29 .2 .4 Temporary Local Data . . . . . . 440 Appendix . . . . . . . . . . . . . . . . 465
29 .2 .5 Static Local Data . . . . . . . . . 441
32 S5/S7 Converter . . . . . . . . . 466
29 .2 .6 Block Parameters . . . . . . . . 441
29 .2 .7 Formal Parameters . . . . . . . . 442 32 .1 General . . . . . . . . . . . . . . 466

29 .3 Calling SCL Blocks . . . . . . . 442 32 .2 Preparation . . . . . . . . . . . . 467

29 .3 .1 Function FC without Function 32 .2 .1 Checking Executability on the


Value . . . . . . . . . . . . . . . 443 Target System (PLC) . . . . . . . 467
29 .3 .2 Function FC with Function 32 .2 .2 Checking Program Execution
Value . . . . . . . . . . . . . . . 443 Characteristics. . . . . . . . . . . 467
29 .3 .3 Function Block with its Own 32 .2 .3 Checking the Modules . . . . . . 469
Data Block . . . . . . . . . . . . 443 32.2 .4 Checking the Addresses. . . . . . 469
29 .3 .4 Function Block as Local Instance 444 32.3 Converting . . . . . . . . . . . . 470
29 .3 .5 Actual Parameters . . . . . . . . 444 32 .3 .1 Creating Macros . . . . . . . . . . 470
29 .4 EN/ENO Mechanism . . . . . . 445 32 .3 .2 Preparing the Conversion . . . . . 471
445 32 .3 .3 Starting the Converter. . . . . . . 471
29 .4.1 OK Variable . . . . . . . . . . .
29 .4.2 ENO Output . . . . . . . . . . . 445 32 .3 .4 Convertible Functions . . . . . . . 472

29 .4.3 EN Input . . . . . . . . . . . . . 446 32 .4 Post-Editing . . . . . . . . . . . . 473


Table of Contents

32.4.1 Creating the STEP 7 Project. . . 473 34.2 Digital Functions . . . . . . . . . 489
32.4.2 Unconvertible Functions . . . . 474 34.2.1 Comparison Functions . . . . . . 489
32.4.3 Address Changes . . . . . . . . 474 34.2.2 Math Functions . . . . . . . . . . 490
32.4.4 Indirect Addressing . . . . . . . 475
34 .2.3 Arithmetic Functions . . . . . . . 490
32.4.5 Access to "Excessively Long"
Data Blocks . . . . . . . . . . . 477 34 .2.4 Conversion Functions . . . . . . 490
32.4.6 Working with Absolute Addresses 477 34 .2.5 Shift Functions . . . . . . . . . . 490
32.4.7 Parameter Initialization . . . . . 477 34.2.6 Word Logic Operations. . . . . . 490
32.4.8 Special Function Organization 34.3 Program Flow Control . . . . . . 491
Blocks . . . . . . . . . . . . . . 477
32.4.9 Error Handling. . . . . . . . . . 477 34 .3.1 Jump Functions . . . . . . . . . . 491
34.3.2 Master Control Relay. . . . . . . 491
33 Block Libraries . . . . . . . . . 480 34.3.3 Block Functions . . . . . . . . . 491
33.1 Organization Blocks . . . . . . . 480 34.4 Indirect Addressing . . . . . . . . 491
33.2 System Function Blocks . . . . . 481 35 SCL Statement and Function
33.3 IEC Function Blocks . . . . . . 484 Overview . . . . . . . . . . . . . 492
33 .4 S5-S7 Converting Blocks . . . . 485 35 .1 Operators . . . . . . . . . . . . . 492
33 .5 TI-S7 Converting Blocks . . . . 486 35 .2 Control Statements . . . . . . . . 492
33.6 PID Control Blocks . . . . . . . 487 35 .3 Block Calls . . . . . . . . . . . . 492
33.7 Communication Blocks . . . . . 487
35 .4 SCL Standard Functions . . . . . 493
33.8 Miscellaneous Blocks . . . . . . 487
35.4.1 Timer Functions . . . . . . . . . 493
34 STL Operation Overview . . . 488 35 .4.2 Counter Functions . . . . . . . . 493
34.1 Basic Functions . . . . . . . . . 488 35.4.3 Conversion Functions . . . . . . 493
35 .4.4 Math Functions . . . . . . . . . . 494
34.1.1 Binary Logic Operations . . . . 488
35 .4.5 Shift and Rotate . . . . . . . . . . 494
34.1.2 Memory Functions . . . . . . . 489
34.1 .3 Transfer Functions . . . . . . . . 489 Index . . . . . . . . . . . . . . . . . . 495
34.1 .4 Timer Functions . . . . . . . . . 489
34.1 .5 Counter Functions . . . . . . . . 489 Abbreviations . . . . . . . . . . . . . . 503

You might also like