CODESYS: Function Block Diagram (FBD) programming – First lesson

CODESYS: Function Block Diagram (FBD) programming – First lesson


Hi everyone. In this video, I am going to
show you how to use the Function Block Diagram (FBD) in order to program a PLC. Function
block Diagram is one of the PLC rogramming languages, which is
quite simple, I would say. It is an alternative to the Ladder logic
programming or the instruction list. So to do it,
I have created a new project and I have set the
programming language as the function block diagram (FBD). Here, what I
want to do is to create a self holding circuit in which I will have a Start push button,
a normally open one, one Stop push button, which
is a normally closed one and one coil which I will cll it as motor, and I want to
do it with the function blocks.
Looking here you can see that now the configuration of the
softwre is somehow different froom the one that we had with the Ladder logic programming.
You don’t see any more the contacts and the coils but
instead we have some other elements like the assignment element, or inserting the box
with enable and enable out and so on and so forth.
Label and return and Jump and so on. So to start, since I know I will put the stop
and start push buttons, the corresponding contact
in series with each other, it means that I will have the And operation, boolean operation.
So I need to pick one And operation hear. One input
to the And will come from the Stop, so it’s a boolean variable, I call it Stop, and another
input for the And will come from the combination of the
start and motor which is the output of the And.
So, here, instead of writing the name of the variable I’m
going to use an OR function block, or let’s say OR function.
The input for the OR comes from the Start, let’s type it here, and then declare it here,
and the Motor, it will be actually my output. So now, I want to assign the output of AND
block to the Motor, you can just click at the output, right click at the output, and
then insert the assignment. Now I can type the name
of the variable which is Motor here and yes, that’s all for the code. So let’s now
go to …, I just need to add the visualization and
over there I will create the start and stop push
buttons and the pilot lamp for the motor. You already know how to do this, if not you
can refer to the other videos. I will come back after I create it, just to
save the time. Alright here I have the visualization, I have one push button for the start which
is normally open and one Stop push button which is normally
closed. And you can see it here: as far as i dont press the start, the value
for it is False, and as far as I do not press the Stop push button, the value for it is
True. If I press the Stop,
the pilot lamp will be turned off, and if I press the Start, the
pilot lamp will be turned on and it will be kept on, because here we have the self-holding
design actually, because the value from the motor is used in order to keep it turned on
through this path that you can see here. So the output
Motor, here is used as the input and the result of Start OR Motor is True, and then the Stop
is True, True & True becomes True nd the motor is kept, is still turned on.
So, the program is quite simple, you already know it, and this is how to implement it using
the function block diagram. So now, let’s see some details about
the blocks that you can use. If you right click on any block that you have inserted,
you can increase the number of of inputs, for example for the And and for
OR blocks by selecting the “append input”. So you
see that each time that I select the append input one input is
added to the AND block and so it means that I can have
multiple inputs for the block. If I right click and “remove the unused FB call parameters”
all the unused ones will be removed. One more thing is that if you right click
on the input of the block, you can make it negated. So, here I can negate the input coming
from the output of the OR block for example. So, this would depend, of course on the design
that you have whether to have a negared inut or not, but this is how to do it. And at the
same time you can have it, the edge detection here as well, you can try to make it edge
detection and then you will see how would be the behavior of their of the block, AND
block here. And you can make, if you select it multiple times can make the edge
detection either sensitive to the falling edge
or the rising. OK, let’s see what we have here: we can insert branch here for
example. So the output of the OR can be used to provide input to some
other blocks. This is the way that we can do it, or we can remove it. And there are
some more details that I will show you later in the next videos. So this is just
for the start, so you can see that you can prepare the PLC programs using Function
block diagram, this is another option. And one more thing is that you have the option
of checking the program actually in different languages. You can switch
between the function block diagram, Ladder logic and instruction
list. Let’s see what we will have for the Ladder logic. Ok so this is very familiar
for us. This is the self holding program with
Ladder logic and let’s see what do we have with the instruction list. Alright so
here you see how the program looks like in the instruction list as well. So the value
from the stop is loaded and then it’s, the result is AND
with the start OR motor and it’s set to to the motor. So going back to the function block
diagram, we will have it in this way. So it’s kind of graphical programming
language in which you don’t type the code, you just put the blocks and connect,
create the connections between different blocks. Ok, so that’s all for this video I
hope this would help you to start working with the function block diagram in programming
the PLCs. Thanks again for watching and if you think that the video would
be helpful for some other people don’t
hesitate to share the video. Thanks and see you next time!

8 thoughts on “CODESYS: Function Block Diagram (FBD) programming – First lesson”

Leave a Reply

Your email address will not be published. Required fields are marked *