Right use of Flow Chart blocks
The Flow Chart library provides the possibility to realize flow chart programming, e.g. it provides function blocks to manipulate the control flow of the program.
With this kind of programming, new programming concepts can be implemented. Multiple quasi-parallel flows can run in one task now. Furthermore, further flows can be controlled with special parameters, so a flow can be stopped or it can be restarted.
The function blocks in this library allow the user to create any kind of flow. This flow is guided by signal lines of the FLOWCTRL data type. Every flow starts with a START function block. If no endless loop is intended, the flow needs an END block. Between these two blocks any kind of forks and jumps can be created by the IF function block and a suitable interconnection with the signal lines. The YIELD function block is used to voluntary yield the program execution to other flows and tasks, so these processes have the chance to be carried on.
From a control flow point of view the following figure shows a little example of a valid flow with all available flow control function blocks.
A Flow Chart Program is rarely used for a self-purpose, but to control other operations. They are implemented through the normal function blocks. Be aware that the combination of control and dataflow on one program or macro level is not permitted. The data flow functionalities (operations with normal function blocks) have to be capsulated into macro blocks without control flow in one sequence. If that has not been considered, an error message will be displayed during the download of the program into the target system. Such a macro is being generated by including an input and output with the data type FLOWCTRL. Furthermore the option “Call of data flow sections“ has to be selected. These signals are not used in one macro block. Such macro blocks can be implemented in the control flow.
Of course it is also possible to use control flow blocks inside of macro blocks. However, no normal function block can be used then, they would have to be capsulated in further sub-macro blocks.
It also has to be noted that any operation between two YIELD blocks (and also between START and YIELD or YIELD and END) will be executed in one step without any interruption within one program cycle. By using this kind of programming it is easily possible to create unwanted side effects up to the point to complete lock down of the system. The flow chart function blocks have to be used with care.
The following example will show the use and the interactions of the flow chart function blocks. The example program uses a simple counter, which is increased by one until it reaches a specific value (in this case 10000). After that the program ends. The functional operation is encapsulated in the macro COUNT, because data flow and control flow must not be mixed up in the same program level. The visualization block can be used, because it does not have a target functionality.
After the program starts, the macro count will be executed. As long as the binary output of that macro is HIGH, the loop will be continued. As soon as a LOW signal is given to the IF block, the program ends.
The COUNT Macro is a typical macro, which is used within flow programming, even though it does not have a control flow function itself. It contains an input and an output from the data type "FLOWCTRL", where the option "Call of data flow sections" was selected.
For the functional operation, an Addition function block is used to count a value by one. This counter value is given to an output for visualization. As long as this value is less than 10000, the Comparator function block returns a HIGH signal.
In case a backward jump is programmed without a YIELD block, it is possible to create an endless loop, which can lock the complete system. When applied to the given example, there is a condition, which leads to a defined end of the program. This will prevent an endless loop. Nonetheless there will be the problem that now the complete program will be executed within one program cycle without any interruption until it reaches the END function block. If there are too many loops, the system will be locked, too.
For that reason there is a safety mechanism, which only allows a certain number of non-interrupted loops, but shows a lock down afterwards and thereby stops the flow. This will be displayed by a red-colored START function block.