Академический Документы
Профессиональный Документы
Культура Документы
The application areas of PLCSIM can be found mainly at the test of step 7-programs for
Simatic S7-300 and S7-400, as long as they cannot be tested directly on the destination
systems. This can have several reasons:
- It concerns small program modules that yet cannot be tested in the complete process
on the machine.
- An application is so critical, that damages for persons and machine are to be feared if
programming errors occur. Such errors to be already dispelled in advance by a
simulation..
- Another widely used application area of PLCSIM is the use for training and exercise
purposes, on the one hand due to cost reasons or if there is no hardware PLC
available
Memory areas of PLCSIM
Data in an automation system can be accessed through the addressing of specific memory
areas that perform specific functions. With PLCSIM during a simulation of a S7-CPU the
following memory areas can be accessed: inputs / outputs, memory areas, data blocks,
timers, counters, local data, etc. In table 1 below, you will find a compilation and short
description of the main memory areas available of the simulated CPU:
Memory areas
Description
T: Timer
C: Counter
M: Memory
PI, PO:
Periphery-areas of
Inputs and Outputs
I, O:
Process image of Inand Outputs
L: Local data
Code- and
Data blocks
Organization-blocks
(OB)
The operating modes "STOP", "RUN" and "RUN-P" can be selected in same way
as with each real CPU. In addition, the simulation has the command "Halt" which
allows to interrupt the program execution at any time, without affecting the current
state of the program.
Of particular interest is, to automatically work with the timers. You can manually
set or reset a single time or reset all times together.
Generally, all commonly available STEP 7-tools can be used to observe the
activities of the simulated automation system, und thus to control and test the
programs.
Though the simulated system exists only in the software, but the STEP 7
programs works, except a few minor differences, as if the simulated CPU would
be a real S7 target system.
Manager has access to the computer internal PLCSIM. All programs of your STEP 7 project
are loaded into the simulated automation system.
What still is missing for testing a program is a possibility, to manipulate the program flow with
the help of simulated input signals at the addresses I0.0 - I0.2 and at the same time to
observe the impact of the program on the signal states of memory bit M1.0 and the output
Q0.0.
C
Insert Vertical Bits
Insert General Variable
Insert Counter
Insert Timer
Insert Memory
Insert Output
Insert Input
explanations of application
Insert Input
Insert Output
Insert Memory
Insert Timer
Insert Counter
Insert
general variable
Insert
vertical Bits
Data of the process image of inputs (I). Default address: Byte 0 (IB0).
Data of the process image of outputs (Q). Default address: Byte 0 (QB0).
Data of the memory area (M). Default address: Byte 0 (MB0).
Timers to be used by the program. Default timer is T0.
Counters to be used by the program. Default counter is C0.
Any operand area of the simulated CPU, including datablocks (DBs).
Any operand area of the simulated CPU, except timer and counter.
In the sub-window "Vertical Bits" only Bytes will be indicated (from inputs, outputs,
memory or data blocks). The bits of a Byte are arranged vertically. Addressing is
also possible with symbolic addressing.
In order to test the program click to the icon Insert Input (fig. 5). The address IB 0 will
automatically appear in the address field. The contents of IB 0 is automatically indicated as a
bit pattern. IB0 byte contains the inputs used in our program I0.0 to I0.2. You can also display
the inputs in the window "Vertical Bits", but have to add the address IB 0 yourself.
Insert sub-window Outputs
Click to the icon Insert Output (fig. 5). Now the address QB 0 will appear in the address
field. The contents of QB 0 is again displayed as a bit pattern. In QB 0 you will find the output
Q0.0 used in our program. You can also display the outputs in the window "Vertical Bits", but
have to add the address QB 0 yourself.
Insert sub-window Memory
In a similar way you can insert the sub-window Memory. In this window, you have access to
the variables stored in the memory area (M) of the CPU. This area is used for storing
intermediate results and auxiliary variables, which are determined and required by the
program. You can monitor and also change the status of the memory flags in this window.
The address MB 0 automatically appears in the address field and the contents of MB 0 is
indicated as a bit pattern. However as you want to monitor the status of memory M1.0 you
must change the byte address to MB 1. Now the result should be a simulator window as
shown in Figure 7.
Fig. 7: Simulator with the sub-windows for in-/outputs and a memory byte
Download of the program
Now, all preparations are made to transfer the program of OB1 into the program load
memory of the simulated CPU. To transfer the folder "Program Blocks" (in this case it
contains only the block OB1) into the simulated PLC click on the load symbol
You can find the load icon in the Editor window, see Figure 4. Now you can
program loaded into the simulated CPU.
run the
Program Execution
With a click on the control box "RUN" or "RUN-P" in the CPU you can start the simulated
CPU in the RUN mode. With another click on bit 1 of IB0 you simulate the switching on of
input I0. 1 (the signal of I0.2 is negated and therefore must be switched off). A small hook ()
in the box of I0.1 indicates that I0.1 is in the binary state "1". Now watch the effects on the
memory bit M1.0 and output Q0.0: both show the hook symbol indicating that they were
switched on. With another click on the box of input I0.1 you will reset this input variable back
to the state of "0". M1.0 and A0.0 however remain in the state "1", since M1.0 has been set
6
permanently as a bit memory. Only by clicking on I0.0 you bring the reset variable to "1", and
hence M1.0 and Q0.0 will be reset again.
Monitoring of the program in the Editor
You can monitor and test the simulation of your program in well known manner. Proceed as
follows:
- Open the editor window of OB1 with your ladder program.
- click to the spectacle icon.
If the simulated CPU is in the RUN mode, then you can watch the binary signal states by
changing colours: green for signal state "1" or dashed blue for signal state "0". Watch how
the signal changes at the inputs affect the other program variables.
With an appropriate arrangement of editor and simulator window, you can at the same time
switch the inputs in the simulator and watch the effects in the editor window. This status test
works the same way as you are used to when working with a real PLC.
The simulation processing the program can be stopped by a click on "STOP" in the CPU
window control box. At the bottom of the window, the red highlighted box confirms the STOP
mode.
Exit simulation
To exit the simulation proceed as following:
In the simulator window, click in the editor or SIMATIC Manager the simulator icon
(simulation on/off).
The chapter provides an introduction to, and overview of the data types used
to represent the variables in STEP 7 programs. The chapter first introduces
into elementary data types and corresponding constant representations. A
further section is concerned with complex data types and one more chapter
explains how to represent numbers digitally in different number formats.
PLC manufacturers. This would guarantee exchange and re-use of functions and function
blocks between the systems of different manufacturers. Though this goal is not yet achieved,
meantime most of the manufacturers are in compliance with this standard.
Data Types according to DIN EN 61131-3
All data (variables, constants etc.) of a users program must be identified and declared by
certain data types. According to the programming standard DIN EN 61131-3 there are
different types of data as:
o
o
o
By allocating a variable to an appropriate data type its size, structure and binary keying is
determined. The advantages of a consequent declaration of data are:
o
o
o
o
The elementary data types can be processed therefore either with binary logic operations for
the type BOOL, or with load- and transfer functions for the types BYTE, WORD and
DWORD.
Choice of Elementary Data Types
Each elementary data type has a defined length, a range with lower and upper limits and a
binary structure. The user may select between the following elementary types:
o
o
o
o
o
o
o
o
o
o
o
o
(*)
In table 1 the elementary data types available at STEP 7 are listed together with their ranges.
DATE_AND_TIME
STRING
ARRAY
STRUCT
UDT (User-Defined Data Types (*))
FBs and SFBs
(*)
Data
Type
Size
(bits)
Description
Example
BOOL
BYTE
1
8
Boolean
8 bit binary
number
Hexadecimal
number
One ASCII
Character
16 bit binary
number
TRUE / FALSE
2#0000_0000 to
2#1111_1111
B#16#00 to B#16#FF
16#00 to 16#FF
A, B, etc. Z
FALSE
L 2#1001_0011
CHAR
WORD
16
DWORD
32
INT
16
DINT
32
REAL
32
S5#time
16
TIME
32
DATE
16
TIME_O
F_DAY
(*)
32
16 bit HEX
number
BCD value,
Count value
Two 8 bit
unsigned decimal numbers
32 bit binary
number
32 bit HEX
number
BCD value
Four 8 bit
unsigned decimal numbers
Fixed-point
number
Fixed-point
number
IEEE Floatingpoint number
Time value in
S7 format
IEC time in
steps of 1 ms
IEC date in
steps of 1 day
Time in steps
of 1 ms
2#0000_0000_0000_0000
to
2#1111_1111_1111_1111
W#16#0000 to W#16#FFFF
16#0000 to 16#FFFF
C#000 to C#999
L B#16#3C
Printable characters,
e.g. L C
L 2#1000_1101_0001_0000
L W#16#A23F
L C#355
B(0,0) to B(255,255)
L B#(15,55)
2#0000_0000 .
0000_0000 to
2#1111_1111 .
1111_1111
DW#16#0000_0000 to
DW#16#FFFF_FFFF
+/- 000 0000 to +/- 999 9999
B(0,0,0,0) to
B(255,255,255,255)
L
2#1010_0101_1101_0010_
1001_0111_0001_0000
- 32 768 to + 32 767
L
L
L
L
L
L
L
(*)
L DW#16#AF02_BCD4
L DW#16#0350_9943
L B#(22,14,100,220)
1
L -35
-2316 L 56
L#-5
L#462 778
3.54e+7
234.17
1.28e-12
L S5T#5m30s
L T#2d3h20m0s0ms
L D#1998-5-12
L D#2003-4-16
L TOD#3:15:40.5
Time in steps of 1ms: Hours (0 -23), minutes (0 -59), seconds (0 - 59), and milliseconds (0 - 999)
10
Structures and arrays may be defined either in the variable declaration of a program block or
in a data block.
Data Type
Date_and_Time
DT
STRING
ARRAY
STRUCT
UDT
FB, SFB
Description
Defines an area with 64 bits (8 bytes).
This data type is saved in binary coded
decimal format (BCD)
Defines a group of maximum 254
characters (data type CHAR, ASCII).
The standard area reserved for a
character string is 256 bytes long. This
is the space required to save 254
characters and a header of 2 bytes.
You can reduce the memory required for
a string by defining the number of
characters that have to be stored in the
character string.
Defines a multi-dimensional grouping of
the same data type (either elementary
or complex). You access the data stored
in an array using the index . Up to a
maximum of 6 dimensions can be
defined in one array. The index can be
any integer between -32 768 to +32 767.
Defines a grouping of any combination
of data types. Up to 6 nesting levels are
possible. For example you can define an
array of structures or a structure of
structures and arrays.
Simplifies the structuring of large
quantities of data and entering data
types when creating data blocks or
declaring variables in the variable
declaration. In STEP 7 complex and
elementary data types can be combined
to create own user defined data types.
UDTs have their own name and can
therefore be used more than once.
You determine the structure of the
assigned instance data block and allow
the transfer of instance data for several
FB calls in one instance DB.
Examples
DT#2007-01-0100:00:00.000
DT#2008-12-3123:59:59.999
Error_Motor_1
Valve_5_closed
11
Instruct. Code
Operand/Variable (addr.)
O
AN
I
M
Comments
4.3
12.7
//OR combination
//memory bit 12.7
Double words
Words
Bytes
D4
D0
W0
B0 W6 B1
W1
W2
B2
W4
B3
B4
W3
B5
B6
B7
W5
12
The upper limit of the byte number is specific to the CPU in use.
IW
(**)
Consider: The byte with the lower address number MB20, IB 6 is the highorder byte (higher binary values), whereas the byte with the higher address number
MB21, IB 7 is the low-order byte (lower binary values).
Variables of type DWORD:
Variables of data type DWORD consist of four bytes. They are referenced via an
address identifier (I, Q, M.), supplemented by D (data width DWORD) and the
byte number of the high-order byte (0, 1, 2, .).
MD 40
QD 12
(***)
Consider: The bytes with the lowest address numbers MB40, QB 12 are the
highest-order bytes (highest binary values), whereas the bytes with the highest
address numbers MB 43, QB 15 are the lowest-order bytes (lowest binary
values).
Exercises:
1. The input double word ID 8 is composed of 4 bytes, see schematic below.
13
a)
b)
c)
d)
Byte no. ?
2. An Input module for 16 digital inputs includes the address bytes IB 5 and IB 6, see fig. a)
below. Some inputs have been switched to 1 , the rest is switched off .
Byte no. .?
I 5.0
Byte no. .?
Fig. b)
Represent the bit pattern of the input module (Fig. a) in the
contents of the input word IW 5 by entering the corresponding
signals 0 and 1 into Fig. b).
IB 5
I 5.7
I 6.0
IB 6
I 6.7
Fig. a)
Explanation
Loads a positive 16 Bit INTEGER (INT) constant,
Range: -32 768 to + 32 767
-5
Loads a negative 16 Bit INTEGER (INT) constant
L#+5
(L: Long integer) Loads a 32 Bit INTEGER (DINT) constant
Range: -2 147 483 648 to +2 147 483 647
2.0e+3
Loads a floating-point constant (REAL, 32 Bit)
(exponential expression)
1234.567
Loads a floating-point constant (REAL, 32 Bit)
14
L
L
L
L
L
L
L
L
L
W#16#ABCD
D#16#F1DA_B23A
ABCD
S5T#2h46m30s
C#126
2#1001 1001 1001 1001
2#1011 0111 1101 0011
0001 1010 1101 0010
B#16#7F
B#(85)
L
L
L
L
B#(12, 34)
B#(12, 34, 56, 78)
P#12.3
D#2001-02-09
15
The data type is an essential part of the definition of a symbol (see elementary data types). It
defines specific properties of the data behind of the symbol, like binary length of the data,
structure and binary encoding. The optional symbol comment can be up to 80 characters
long. See: Example of a symbol table.
No.
1
2
3
4
5
6
7
Symbol
START
AUTO
Quantity_1
Result
Delay
Duration
Mot_1_on
Address
I 2.4
M 10.0
MW 22
MD 30
T
14
MW 40
Q 4.2
Data Type
BOOL
BOOL
INT
REAL
TIMER
S5TIME
BOOL
Comment
Start operation
Automatic operation
Number of produced work pieces
Weight of produced pieces
Timer for start delay
Duration of start delay
Motor 1 running
Symbolic Addressing
AN Alarms.MOT_Stop
T
Pump_1.Speed
L
Values.Number_1
=
Alarms.Stop_Switch_4
Comments
Checking of a Data bit
Save value in a Data-Double Word
Load INTEGER-Value from DB 12
Assign the RLO to Data bit
Stop_Switch_4 of Data Block
Alarms
IB 9
IB 10
IB 11
O
O
IW 9
Examle 2:
Byte no. 5
1 0 1
Byte no. 6
0 0 0 1 0 0 1 0
0 0 0 1 1
Abstract: The chapter gives an introduction to and overview of the STEP 7 program
structure, where other, higher-ranking blocks will call program blocks conditionally
or unconditionally. Furthermore the different types of STEP 7 blocks, like
organization blocks (OB), functions (FC) and function blocks (FB) are explained.
Block parameters, enabling the data transfer between calling block and called
block, and block end operations are topics of this chapter too.
The total software of an automation system is divided into two main sections:
-
The operating system is responsible for all functions and tasks of the CPU, which are not
associated with a specific user application. These tasks include:
-
The periodic processing of the process images for the input and output ranges
(PII, PIQ)
The call of cyclical, time and alarm-driven organization blocks (OBs)
Start-up routines when switching on the mains power or actuating the mode
switch on the CPUs front panel from STOP to RUN (OB 100, OB 101)
Error detection and error handling
Communication with the peripheral modules (input/output) and the programming
device via the MPI-interface
Management of the users and system memory areas
User program
The entity of all code blocks like functions (FC) or function blocks (FB) forms the user
program. Blocks are defined components of the user program by their function, their
structure or their way of use. In order to be executed, they have to be called from
17
organization blocks, or other blocks. Thus, organization blocks form the interface between
the operating system of CPU and the user program.
User Blocks
Depending on the type of application there is a choice of different block types like
-
which are processed by the CPU dependent on certain events. Such events could be the
detection of a program- or hardware-error, some interrupts from the process via peripheral
devices or an internal CPU timer (watchdog or time-of-day interrupts etc.).
Variety of blocks
All user programs and the necessary data are stored in blocks. Code-blocks contain the user
programs and corresponding data are stored in data-blocks. In STEP 7 the following kinds of
blocks as listed below are available:
Program blocks
Organization Block
Function Block
System Function Block
Function
Datablock
System datablock
Identifier Function
OB
Interface to Operation System
FB
Block with allocated memory and possibility of
parameter transfer
SFB
predefined FB, integrated in Operation System
FC
Block without allocated memory, but possibility
of parameter transfer
DB
Block for storage of users program data
SDB
Data Block, containing system relevant data,
such as configuration and parameter data of the
hardware modules. The STEP 7 software
generates and manages these blocks.
Blocks of STEP 7
Code blocks (program)
Global datablocks
DB
Instance datablocks
DI
Belong together
18
Organization blocks serve at STEP 7 as an interface between the operating system and the
user program. They correspond to the "tasks" of the IEC 61131-3 to the controlled calls of
user programs. The CPUs operating system calls the OBs when specific events occur, for
example in the event of a hardware or time-of-day interrupt. Depending on the purpose
different classes of OBs can be selected by the user. Their use is controlled by different
priorities. So each type of OB is equipped with its own priority and can interrupt OBs with
lower priority. OBs with the same priority will not interrupt each other, but will be called by the
operating system and executed according to their recognized sequence.
STEP 7 knows organization blocks for:
-cyclic program processing (only OB 1)
-time-driven program processing (clock-, delay- and watchdog-alarms)
-event-driven program processing (process alerts, errors HW/SW)
- and for the start-up (start up routine OBs)
Main Program call by OB1
The main program is always in organization block OB1, which is cyclically called by the
operating system. The repetitive cyclic program execution is the normal mode for processing
a user program in the "RUN" mode. Thus, to achieve a cyclical execution for the user
program you write it into the OB1 or other blocks, called directly or indirectly by the OB1.
Figure 2 shows the call hierarchy of a cyclic program execution by the OB1.
Operationsystem
OB 1
FB
FC
FB
FB
FC
OB-Nr.
1 (free cycle)
10 to 17
20 to 23
30 to 38
40 to 47
50 and 51
80 to 87
100 and 101
121 and 122
3.4.3 Functions
Functions, FC, are used to program frequently recurring or complex automation functions.
They can be parameterized, i. e. can be given block parameters. These parameters can be
input-values, given to the function when calling them. The FC returns a (output-) value, called
function value, given back to the calling block. The function value is optional. In addition to
the function value, function may also have other output parameters. In contrary to Function
Blocks - FB, functions do not store information (no memory), and thus have no assigned data
block. The function must be called by another program block, like an OB, another FC or a
FB.
Block structure
Essentially, code blocks (FC and FB) consist of three parts:
-
The block header, containing the block properties, such as the block name
The declaration section, in which the block-local variables are declared or defined
The program section, which contains the program and the commentary.
Block Parameters
Block parameters for FC and FB represent some kind of transfer interface between the
calling block and the called block. All functions and function blocks can be provided with
parameter sets. So it is possible within a block, to replace the instructions operands by
parameters. That means, the block can be executed several times with different data values
(replacing the declared parameters), which will cause to return different results to the calling
block.
Different kinds
The block parameters must be declared in a parameter list of the block header. There are
different kinds of parameters as shown in Table 4:
Keyword
in
out
in_out
Parameter Kind
input parameter
output parameter
in/out parameter
Description
Loads a value to the program of the called block
Returns a value (result) to the calling block
A parameter is loaded and also returned (changed)
20
temp
temporary value
Name
RESET
START
RESULT
NUMBER
Type
BOOL
BOOL
INT
BYTE
Initial value
TRUE
TRUE
0
20
Comment
Manual Reset
Manual Start
Calculated value
Intermediate_1
Intermediate_2
BOOL
BOOL
FALSE
FALSE
RLO 1
RLO 2
Condition
no
UC
Operand
FC n, FB n
SFC n, SFB n
FC n, FB n
CC
FC n, FB n
RLO = 1
no
Explanation
Unconditional block call of FCs and FBs with or
without parameters, FBs with or without Instance DB.
Unconditional block call of FCs and FBs, without
parameters only, FBs without Instance DB only.
Conditional block call of FCs and FBs, without
parameters only, FBs without Instance DB only.
Block is called only, if the actual RLO is 1.
Name
INPUT1
INPUT2
RESULT1
RESULT2
Type
BOOL
BOOL
INT
BYTE
Initial value
Comment
21
temp
MEMORY
BOOL
Local symbols
Local symbols are known only in the block (FC, FB) in which they have been defined as
parameters (names). The same local symbols can be used in different blocks for different
purposes. In the program part of a function or FB the parameters (local symbols) must be
marked by the preceding character #, in order to distinguish them from global symbols,
defined in a symbol table (enclosed with inverted commas like STOP). This is valid for all
kinds of program representation, STL, LAD or FBD language.
Segment 1
&
#INPUT1
#MEMORY
#RESULT1
#INPUT2
Segment 2
#RESULT2
&
#MEMORY
OB 1:
Segment 1
CALL FC 1
INPUT1 : =
INPUT2 : =
RESULT1: =
RESULT2: =
I0.0
I0.1
Q4.0
Q4.1
22
Example:
:A
M 3.7
:BEC
:A
I 2.4
:S
Q 2.5
:
:
:BE
BEU-operation
The BEU-operation (Block End Unconditional) will terminate an actual block similar to the
normal BE-operation. In contrary however to BE, the BEU-statement will not be used at the
end of a block, but only within a block. The BEU-operation should be used only, if the block
must be terminated before completion due to a conditional or unconditional jump-operation
within the block.
OB1
: .
: .
:CALL FC 3
:A
I 1.3
:AN M 8.2
:
:
:
:A M 3.1
:UC FC 6
:O M 7.2
:ON I 2.7
:
:BE
FC3
: .
: .
:A
I 3.6
:BEC
:O I 3.7
:CC FC 6
:
:BE
FC 6
: .
:L MW 3
:T QW 7
:
:BE
23