Hello my name is caner and siemens simotion system 2
And programming course if this chapter 3
chapter is 25 4
we will learn about functions and function blocks 5
Let's open our sitrain motion program notes 6
What you will learn 7
this course 8
Contents are 9
Blocks for structured programming 10
Properties of functions define a function in St source 11
Declaration and statement part of a function 12
Calling user function 13
Short form of user functions 14
calls 15
arrays with Dynamic lengths 16
It's possible from 4.2 17
Properties of function block defining a function block 18
Parameters in function block standard functions in simotion 19
standart function block in simotion 20
Axis 21
Technology objects and so on... 22
Let's start 23
That's the first page you see here block for structured programming 24
There's a cyclic task 25
there is one motor and controller for the motor that are some valves 26
limit values and coping procedure at the background task 27
you will see here 28
Motor 1 in example for consist of 29
Starting. Inputs and output of this 30
Function or function block 31
So 32
Subtask are solved in separate which model of programming 33
Parameterisation makes for flexible application 34
Reusable of blocks libraries Blocks can be called and unlimited number 35
So basically you define or design 36
A motor block 37
Function or function block then you have 38
100 Motors in your system for instance 39
This 40
function Block instance 400 times 41
And assign the input and output related to each motor 42
There are some restriction 43
No axis to global operand from inside the function communication 44
List 45
Best idea 46
Properties of functions 47
Or 48
Parameterizeable blocks any number of input parameters and number 49
No parameters 50
no memory 51
there are temporary available only in functions 52
This is the difference between function and function block 53
Only one of the parameter is ret val 54
You define the datatype real or whatever 55
you don't use global variables and you don't use 56
absolute operands and global address 57
no meaning 58
return an identical result with the same input parameters is possible via function 59
If your programmer and you have already commissioned some projects in simatic manager 60
This is the same 61
As function and function block idea 62
How do we Define a function in ST source 63
You see here the unit 64
Interface and implementation area 65
Let's say function my function that are described in implementation area 66
The return value some type 67
I have defined by myself as user-defined data type here in interface section 68
And there are some 69
Other inout 70
parameters and this is my program code for function 71
Decleration part of a function 72
You'll see here type definition inside the function 73
inputs 74
inout 75
And some variables temporary 76
Input parameters and variables can initialize inout parameters can not be initialized 77
assigment is important assignment of the return value you'll see here 78
Assignment equals blah blah blah 79
Statement of a function is here right access to a variable 80
temporary is variable assignment 81
At the end of the function statement that are some real axis 82
how call user The functions 83
You will see in Main program 84
I just call value the functioning 85
actual parameters ST call 86
I assign here 87
A variable 88
These are the formal input parameters of the FC 89
Especially as the type of assignment is neither possible or necessary 90
with the other data types return will you must always be assigned to a variable 91
And the short form of function calls 92
In this example the function name is start Task and enable axes 93
So return with you is MCC Red Double integer as 94
Described here 95
you see action parameters of the FC call 96
leading axis all active inactive 97
You don't see here 98
symbolic name of input and output 99
Items just a assigment Just actual parameters off 100
Function so this is the short form called 101
This is the long form 102
Next page 103
arrays with Dynamic length 104
for inout parameters FC FB it's possible to use 105
Dynamic length in arrays address of decleration 106
Specification of limits for index 107
So 108
This is an example of usage access the lengths and limits of every possible via system functions 109
Last index of array 110
It's value type double integer for these 111
Axis occupied memory via sizeof 112
this functions is usable 113
To create and manage array data type variable 114
Properties of function blocks 115
Call forms to IEC standart. Any number of input output parameters possible 116
with memory 117
not just temporarily also use static variables that's why we have to ask 118
Assign an instance for function blocks 119
Call with seperate data area. 120
But the encapsulation is possible 121
Application in cyclic task 122
Timer and counter basically actuated process units with internal States 123
drives valves ... I'm so on 124
you see here 125
Defining a function Block in St source 126
Difference between FC and FB 127
It's almost the same 128
Well of course there are some different 129
Declaration part of a function block 130
Input output. 131
You see here the static variable is different than the function and temporary variable declaration 132
Also the constant 133
So in out parameters cannot be initialized there's a deep note for you 134
at this case 135
We initialized axis pos long real data type 136
An assignment initial visit initialization value is 15 137
You'll see here in this table parameters in function blocks input output in 138
in out 139
statement part Of a function block is here 140
Restrictions with access to parameter and variables are 141
Read-only axis to input parameters only 142
Read and write access to output and input parameters is possible 143
Read and write access for all local variables is possible 144
constants 145
value are constant 146
variable or read-only access to contants is possible 147
Instant idea of function blocks 148
here motor1 instance 149
Motor 2 Motor 3 150
Call in our program code to the function block 151
And the instance are there for motor 1 see here 152
for 2 for 3 with different colors 153
You may cross the instance as a data block or a member area it's your RAM disk 154
Or your memory 155
to understand 156
So IEC type call of function without instance in St 157
Normally w will use this case 158
But if you don't assign the output of a function look to a 159
Global available 160
This way of usage instance name. the parameter 161
Assignment is also possible 162
call Options action permit language extension 163
you see here 164
Imports 165
Imports Imports 166
This is the output 167
And read and write access to input parameters outside of the parameter list 168
There's an assignment motor to start with 169
Equalize the digital inputs 170
Motor 2 speed equals constant value 171
then you call Motor 2 only estop parameter 172
estop 173
So this is also another way to use 174
Forward declaration in St 175
Use of fc fb or program program organization pre-order 176
implementation 177
So you'll see you're an interface section and implementation section 178
If you want to use forward decleration 179
type section of interphase of implementation Part is possible 180
So we 181
Define functional operate mode aS Type 182
and we create 183
A global variable operating mode 184
and here function block operate mode later on described 185
This is the forward declaration 186
you need to enable compile option first 187
Program oorganization units can be used for following purposes 188
instance decleration of function block call for function 189
So 190
Your used within type and type section in the interface to do that 191
Keep in mind maybe you need it in the future 192
Command library in simotion Scout you see on the left side that are some 193
Ready-to-use functions 194
for different 195
Section alarm messages Drive function 196
Communications and so on 197
That are here several standard functions in simotion 198
And example 199
bistable flip flop set reset and triggered counter PLC open commands 200
and next 201
How do we access to technology object data types? 202
In FBs and FCs via input parameters it's possible 203
So see the keywords 204
okay If I want to create my own program 205
FB for position access at the input side I define my access variable 206
Declaration of input 207
here Is example usage motion control commands enable access 208
pos axes 209
and I can reach 210
System variable or the variables of the 211
technology objects 212
So... 213
Transformation and checking data type 214
Typecast explicates or explicit 215
typecast 216
With converison or without conversion you see here at this example 217
drive axes 218
Assignment to a pos axis 219
It's just you lost some information 220
Yep 221
And you can assign a drive axes to any object type 222
Variable is possible 223
teseting TO reference we can use this phrase pos access 224
Is not equals 225
Technology objects 226
null instance 227
casting succesfull 228
After that we can use our casting phrase 229
Example this 230
For explicit type casting you use anyobject to object 231
At this case you don't lose information 232
Because you're converting 233
Access to pos access object so 234
I think this second way is more common used 235
Programming 236
and before to do that you have to check the TO reference 237
Okay 238
That's all so far 239
you may 240
Check the exercises in your lecture notes and do related examples 241
In your PC 242
On your own 243
See you then.