Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
CLP S7 300 E S7 400
1. Creating and calling up blocks
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
2. Structure of an SCL source file
FUNCTION_BLOCK FB10
DB5
Attributes
FB10
Declaration part
FC62
Instruction part
FC61
END_FUNCTION_BLOCK
OB1
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
3. Beginning and end of blocks (e.g. function block)
FUNCTION_BLOCK FB10
Attributes
Key words for
beginning and end
of blocks
Declaration part
Begin
(* Instruction part *)
END_FUNCTION_BLOCK
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
4. Block attributes
FUNCTION_BLOCK FB10
Attributes
Declaration part
Begin
(* Instruction part *)
END_FUNCTION_BLOCK
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
TITLE='Controller'
VERSION:'2.1'
KNOW_HOW_PROTECT
AUTHOR:Training
NAME:Mot
FAMILY:ANALOG
{S7_m_c:='true';
S7_blockview:='big'}
5. Declaration part
FUNCTION_BLOCK FB10
Attributes
Declaration part
VAR
Value1,Value2,V33:INT;
END_VAR
Begin
VAR_INPUT
IN1,IN2:BOOL;
END_VAR
(* Instruction part *)
END_FUNCTION_BLOCK
SIMATIC S7
Siemens AG 2000. All rights reserved.
CONST
FIX_VALUE:=5;
P_Part:=0.8;
END_CONST
Date:
6.10.00
Filename:
VAR_OUTPUT
Q01:BOOL;
Display:INT;
END_VAR
6. Instruction part
BEGIN
FUNCTION_BLOCK FB10
// Example bit operation, arithmetic
Q0.0 := I0.0 AND I0.1;
MW20 := MW22 + MW24;
Attributes
Declaration part
// Example value allocation
Measured value:=0 ;
// Example control instruction
IF I1.1 THEN
N:=0;
SUM:=0.0;
ELSIF START = TRUE THEN
N:=N+1;
SUM:=SUM + IN;
ELSE
OK:=FALSE;
END_IF;
Begin
(* Instruction part *)
END_FUNCTION_BLOCK
// Example of calling up a sub-program
FB10.DB2(Pa1:=10,Pa2:=MW2);
Result:=DB2.MVal7;
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
7. Structure of organisation blocks(OBs)
FUNCTION FC62 : BOOL
VAR_INPUT
IN1 : BOOL;
IN2 : BOOL;
END_VAR
BEGIN
.....
Instead of OB1, a name from
the symbol table can be
used.
FC62 := IN1 AND IN2;
.....
END_FUNCTION
//*******************************************
*
FUNCTION FC61 : VOID
BEGIN
.....
There must be a declaration
of 20 bytes local data!
Further temporary local
variables can be declared
Q0.0 := I0.0 AND I0.1;
.....
END_FUNCTION
//*******************************************
*
ORGANIZATION_BLOCK OB1
VAR_TEMP
info : ARRAY[0..19] OF BYTE;
END_VAR
BEGIN
FC61();
Q4.0 := FC62(IN1:=I4.0,IN2:=I4.1);
Q4.1 := M10.4;
SCL source file
END_ORGANIZATION_BLOCK
SIMATIC S7
Siemens AG 2000. All rights reserved.
Call-up of the FC61, which
has no input / output
parameters and no return
value
Call-up of the FC62, which
has input parameters and a
return value.
Any commands.
Can be written in absolute or
symbolic form.
Date:
6.10.00
Filename:
8. Structure of functions (FCs and SFCs)
FUNCTION FC62 : BOOL
VAR_INPUT
IN1 : BOOL;
IN2 : BOOL;
END_VAR
BEGIN
.....
Blocks
in CFC
FC62 := IN1 AND IN2;
.....
END_FUNCTION
//*******************************************
*
FUNCTION FC61 : VOID
BEGIN
.....
Q0.0 := I0.0 AND I0.1;
.....
END_FUNCTION
//*******************************************
*
ORGANIZATION_BLOCK OB1
VAR_TEMP
info : ARRAY[0..19] OF BYTE;
END_VAR
BEGIN
FC61();
Q4.0 := FC62(IN1:=I4.0,IN2:=I4.1);
Q4.1 := M10.4;
SCL source file
END_ORGANIZATION_BLOCK
SIMATIC S7
Siemens AG 2000. All rights reserved.
Blocks
in FBD
Date:
6.10.00
Filename:
9. Structure of functions (FCs and SFCs)
FUNCTION FC63 : REAL
VAR_INPUT
x1,x2: REAL;
y1,y2: REAL;
END_VAR
VAR_OUTPUT
GRADIENT: REAL;
END_VAR
//FC63 describes the distance
//between 2 points and the
//gradient of the line
BEGIN
FC63 := SQRT((x2-x1)**2 + (y2-y1)**2);
GRADIENT := (y2-y1)/(x2-x1);
END_FUNCTION
//************************************************************************
ORGANIZATION_BLOCK OB1
VAR_TEMP
info : ARRAY[0..19] OF BYTE;
inclination : REAL;
distance: REAL;
END_VAR
BEGIN
distance:=FC63(x1:=1,x2:=3,y1:=1,y2:=5, GRADIENT:= inclination);
MD0
:= inclination; // MD0 and MD4 declared in
MD4
:= distance;
// symboltable as REAL !!
.......
........
END_ORGANIZATION_BLOCK
Siemens AG 2000. All rights reserved.
x
ce
tan
dis
y1
x
x1
SCL source file
SIMATIC S7
y2
Date:
6.10.00
Filename:
x2
10. Structure of functions (FCs and SFCs)
IF (x2-x1)=0 OR STEIGUNG <0 THEN
OK:=FALSE;
ELSE
OK := TRUE;
END_IF;
FDB
Execute FC62 only if FC63 runs correctly.
ENO and EN can be used
to „connect“ blocks.
OB1
FC63
SCL programcode in OB1:
distance:=FC63(x1:=MW10,......);
Error_FC63:=ENO;
// call FC63
// ENO from FC63
FC62
// call FC62 only if FC63 was ok:
FC62(EN:=Error_FC63,STEIG := inclination,WINKEL:=MD20);
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
SCL
11. Structure of function blocks (FBs and SFBs)
Supply:
VAR_INPUT
VAR_IN_OUT
OB1
Supply:
VAR_INPUT
VAR_IN_OUT
FC64
FCs:
FBs:
Call-up with
supply
and
get the results
in one
instruction
Call-up with
supply
xyz:= IN1;
:
:
OUT1:= uvw;
Get results
in a second
instruction
Results:
RET_VAL
VAR_OUTPUT
VAR_IN_OUT
Siemens AG 2000. All rights reserved.
VAR
VAR_INPUT
VAR_IN_OUT
VAR_OUTPUT
Results:
VAR_OUTPUT
VAR_IN_OUT
no RET_VAL
Within an OB and FC, there are only
temporary variables.
In the next cycle, they are no
longer available.
SIMATIC S7
FB10
Instance DB
DB2
Within an FB, there are temporary and static
variables. The static and output variables are
saved in the instance DB, which means that
they are available during the next cycle.
Date:
6.10.00
Filename:
12. Structure of function blocks (FBs and SFBs)
Call-up with
supply
Absolute call-up
FB10.DB2(x1:=5,x2:=delta,x3:=MW20);
Parameter supply:
FBs are only supplied with input
and in/out parameters.
Parameters which are not supplied
retain their last value.
Instanz- DB
No output parameter,
no return value.
Motor.Mx7(x1:=5,x2:=delta,x3:=MW20);
Symbolic call-up
Access to
output
parameters
Caller variables
Instance DB of the FB
result := DB2.speed;
MW22:= Mx7.amp;
Output parameter of the FB
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
13. Structure of function blocks (FBs and SFBs)
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
14. FB2
2
Multi-instance, local instances
FUNCTION_BLOCK FB22
OB1
VAR_OUTPUT
OUTPUT, VALUE
: DINT;
END_VAR
BEGIN
...
END_FUNCTION_BLOCK
FUNCTION_BLOCK FB11
VAR
Test, Status
: DINT;
Regulator_1, Regulator_2 : FB22;
END_VAR
BEGIN
...
Regulator_1();
Regulator_1
Test:= Regulator_1.OUTPUT;
Regulator_2();
Status :=Regulator_2.OUTPUT;
...
END_FUNCTION_BLOCK
Regulator_2
ORGANIZATION_BLOCK OB1
...
BEGIN
...
FB11.DB33();
...
END_ORGANIZATION_BLOCK
SIMATIC S7
Siemens AG 2000. All rights reserved.
Date:
6.10.00
Filename:
FB11
Regulator_1
FB2
2
Regulator_2
DB33
Test
Status
DB33
OUTPUT
VALUE
OUTPUT
VALUE