0

I am coming from computer science background and used to traditional IT programming. I have relatively little experience with structured text. In my current project I am extensively using many function block. I am aware that this involves some memory issues and so on. Could anyone come up and give me some advantages and disadvantages of each of them. Should I avoid them and write everything in a single program ? Please practical hints should be welcome as I am about to release my application.

System : Codesys

soulemane moumie
  • 1,005
  • 1
  • 14
  • 26

2 Answers2

1

I also come from the PC programming world, and there are certain object tricks I miss when programming in Codesys. The function blocks go a long way towards object thinking, though. They're too easy to peek into from the outside, so some discipline from the user is necessary, to encapsulate the functionality or objects.

You shouldn't write a single piece of program to handle all functionality, but instead use the Codesys facilities to divide the program into objects where possible. This also means to identify which objects are alike and can be programmed as function blocks. The instance of a function block is created in memory when the program is downloaded, e.g. it is always visible for monitoring.

I normally use POU's to divide the project into larger parts, e.g. Machine1(prg), Machine2(prg) and Machine3(prg). If each machine has one or more motors of similar type, this is where the function blocks come in, so that I can program one motor object called FB_Motor, and reuse it for the necessary motor instances inside the 3 machine programs. Each instance can then hold its own internal states, timers, input output, or whatever a motor needs.

The structure for the above example is now:

MAIN, calls
  Machine1(prg), calls
    fbMotor1 (implements FB_Motor, local for Machine1)
    fbMotor2 (implements FB_Motor, local for Machine1)
  Machine2(prg), calls
    fbMotor1 (implements FB_Motor, local for Machine2)
  Machine3(prg), calls
    fbMotor1 (implements FB_Motor, local for Machine3)
    fbMotor2 (implements FB_Motor, local for Machine3)
    fbMotor3 (implements FB_Motor, local for Machine3)

The functions are another matter. Their data exist on the stack when the function is called, and when the function has returned its value, the data is released. There are lots of built in functions, e.g. BOOL_TO_INT(), SQR(n) and so on.

I normally use functions for lookup and conversion functions. And they can be called from all around the program.

pboedker
  • 523
  • 1
  • 3
  • 17
  • Having almost similar hardware with more or less similar functionalities I was in that logic of reducing the number of share functionalites by writing more function blocs. But was bit reluctant, now with your answer I feel safer of moving in the right direction. Thanks for your remarks. – soulemane moumie Sep 21 '15 at 07:11
  • I think functions, at least in OpenPCS are limited to returning elementary data types such as bool, byte, dint etc. Function blocks can declare a user-defined data type and have it as an output variable. – Adam.at.Epsilon Apr 06 '16 at 07:31
0

The clarity, robustness and maintainability are everything in PLC world. Function blocks help you to archieve that if the stucture is kept relatively flat (so one should avoid functionblock inside functionblock insede function block, compared of true object and their heritage).

Also the graphical languages are there for reason they visualise the complex systems in easy to digest form in a way that the maintaining personnel in the future have easier life to follow what is wrong with the PLC program and the part of the factory.

What comes to ST it is advance to remember that it is based on strongly typed Wirthian languages (ADA, Pascal etc.). Also what is often more important than memory usage is the constant cycle time of the program (since real time system). The another cup of the tea is the electrical layer of the control system, plus the physical layer and all the relations on that layer that can backflash somewhere else in your program if not taken account.

V.Tile
  • 1
  • 1