7
Oct

CODESYS: Sequential Function Chart (SFC) programming – First lesson


Hi everyone. In this short video,
I am going to introduce you the …, another PLC programming language which is called
SFC or sequential function chart. Sequential sequential function chart is basically
a graphical chart which contains steps as
the main elements, the transition between the steps and also the actions which can be
taken steps along with the steps: during the step,
whenever you enter the step, or whenever you exit the step.
There are a lot to discuss and to explain about the actions: how you
can declare the action (determine the action, actually).
There are different kinds of actions, when to take different actions,
whenever you enter the step for example or whenever you
exist the step, and so on and so forth. And there are a lot to talk about the
configuration of the SFC as well, so you can create paralell branches or different
branches for a chart and so on and so forth. But the aim of this video is not to go
into the details of the SFC, however I’m going to introduce you how you can
build the simplest, let’s say, the SFC program for the PLC.
For doing that, I’m going to create a new project, so here I determine the name
for the project, the location and then, it’s,
it’s a standard project, click on OK, I am going
to save whatever I had already for the old
project Ok, I am going to overwrite it. So here in the programming language section,
I’m going to select the SFC (Sequential Function
Chart) and for the device,
you don’t care if you are in the simulation mode, if you’re not in the
simulation mode, you need to select a device that you are working with.
Ok, clicking on the OK, I will see the project tree here,
and now if I double click on the PLC_PRG, the main program that I have, here you will
see the main window, let’s say. So, again, here is the location for declaring
the variables and here is the environment in which you are going to develope the code.
So, you can see that, you initially have one “Init”, which is the step,
this one, and here we have one transition which is by
True, and here we have a jump. So this is the jmup and this is a label to be
step, which is Init. So if you run this, it will be
continuesly jumping from the end of the program to the step, and there’s nothing
to do actually, here. but we are going to modify it
and create the program the we would like. Before going forward,let’s set the Online
mode to the Similation and let’s add a
visualization to our project. So what I want to do here is that I’m going to
place one switch which can be turned on or off and one pilot lamp and I’m going to
determine the state of the pilot lamp based on the Start button, let’s say, if the
Start push button has True value, then the Pilot lamp
should be turned on and off sequentially let’s say for 1 second each time. If the Start
push button is False, then the Pilot lamp wil be turned Off,
it will not turned On. One more thing that we
need to do here, for this version of CODESYS, is to go to the properties of the application,
and in the build tab, we need to write down: “VISU_NO_EXCEPTION_HANDLING”.
this is due to the bug that there is with the latest version of CODESYS
(3.5.7.1). I hope they will
fix this in the next versions. So let’s go back here, I am going to declare
a variable, StartPB as the Boolean, Ok, I think my Caps
Lock is turned on, let’s do it again, StartPB, then PL as another Boolean variable, and now
it’s the point in which we are going to start the
process. So, here, after the Init, I click on the Init
state, and then you can look here, in the Toolbar,
that I can insert a “step transition” or I can
insert the “state transition after”. So if I select this one, you can see here
that there is a transition, which is called Trans0 right now,
I am going to modify it, and there is a step, which is called Step0 by default. So I am
going to change the name for this step to “OnState” and I am going to add
another step and call it “OffState”. As I told you, I want to start the process
whenever to stop push button is pressed or the value for the StartPB is True.
So here for the transition after the initialization, after the Init state, I will use the StartPB.
So the value of StartPB will be checked, if it is
true then the transition from Init to OnState will happen. If not the
execution of the program will be remained in the Init state.
Then from OnState to OffState I need to determine another transition
condition, I will do it later, but for now let me introduce you have to create
the actions for a given state. So, here in the
OnState, I want to turn on the Pilot lamp. Whenever I entere the state I
want to turn on the pilot lamp, and so I can just
rigth click on it, and select the “add entry action”,
you can find it in the toolbar as well, but for now I
just select it from here. So, by default it is called “OnState entry”, you can change
it if you wish. I am going to keep it like that. And here
we can select the language for the implementation, any of
the standard languages. To make it simple, I am going to use the Ladder
logic, for now. Alright, so here I want to turn on the pilot
lamp. I can insert the coil, connect it to the line
and then determine the variable as PL, so it would be turned on automatically,
and then I can close this. Then in the transition since I want to
have the pilot lamp turned on for 1 second, I can do it in this way: so I
want to have the transition whenever we have OnState dot “t” (OnState.t)
“t” is the time which we have been inside the OnState, is bigger than one second. So
if the time which we have spent inside the OnState is bigger than one second, the
transition will happen, and we will go to the next.
For the next state, I’m going to determine another
entry action for this, with the Ladder logic, and in this
case I’m going to turn off the pilot lamp. So, here we will have PL and for this I will
have the negated coil. Alright, so, …, and then
I want to have the pilot lamp turned Off for another
one second so here instead of True, I will write OffState.t
bigger than one second. If this is the case, then the transition will
happen and then the execution will jump to the Init and
the process will start again. So, here pay attention that the action that
I have determined here, I have developed, all of them have appeared here.
So in the PLC_PRG, you can see that they are, kind of
the actions which are developed and used inside this program. OK, so that’s it for
the program. Just in the visualization we need to
insert a switch and assign the variable for the switch as the StartPB, then I’m
going to insert a pilot lamp and the variable for that will be the PL.
Ok, so the program looks fine. The only thing that we need to do is to login,
compile the code, login and then run the project. Alright, so here we have the visualization,
I just put it over there. So, here, in the runtime you can see that
the value for the Start push button is False, the pilot lamp is turned off, that’s true.
And here you can see different states. So we are initially in the Init state, that’s
why it is highlighted with the Blue, and then the others are in gray, because we have not
entered them. Here, beside the states you can see the time inwhich we have been inside
the state. So it is zero milliseconds for the OnState and for the OffState as well.If
I turn, if I change the sttae of the Start push button from False to True, you see that
we entered this stateand then the transition between different states is happening. And
each time that we enter the state, the time in whih we have been inside the state, starts
from zero and it goes up to one thousand milliseconds or one second. So that is why we have the
pilot lamp here, flahsing. But if I just change the state of the Start
push button from True to False, then we will stay indside the Init state and here you can
see the amount of time that we have been inside the state.
Alright, so for this very simple, let’s say example, that’s all that you need to do. to
have a flashing pilot lamp controlled by a switch.
However, as I already told you, there are a lot to discuss and explain about the SFC
PLC programming. I will do it later, in the next videos, but
for now, that’s all. Thank you for watching, let me know if you
have any suggestions or comments and if you feel that the video
could be useful for someone else, then don’t hesitate to share it. Thanks again and
see you next time.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

10 Comments

  • Victor Sj says:

    Hi, could you upload the pdf's lecture 24, 25?

    thanks

  • Arsayin Sayin says:

    how are the INIT, OnState and OffState boxes declared as time blocks. do the current time counting next to the boxes come from >t#1s declarations of the transitions.

  • ano nimo says:

    Hi Tohid,

    What is the reason for the music in background?

    Thanks

  • Oskar petersson says:

    Hi Tohid,
    can you create a programe for those video by SFC and send me the code?
    https://www.youtube.com/watch?v=eBq5hlEcyH8&feature=youtu.be&list=PLlaeyxqFKfKOusGn_dh_L19g0w6hChgDf

    https://www.youtube.com/watch?v=DWyrEvKd5_M&feature=youtu.be

    https://www.youtube.com/watch?v=cFdsSW457To&feature=youtu.be

    Thanks you

  • YICE JIANG says:

    Hi Tohid,
    I have a question about writing transition: Can I write something like that? it is like when either pushbutton is pushed and emergency stop button is not pushed, T3 is true. The default value of EmergencyStop is false when it is not pushed

    T3:=positive_direction OR negative_direction OR Enable AND NOT(EmergencySTOP)

  • Tohid Alizadeh says:

    Here is the same video without the background music! Sorry for that, and thanks a lot for the feedback!
    https://youtu.be/eP42t9O5drk

  • Düz adam Sami says:

    Thanks for your labor

  • David Pote says:

    To Many adverts

  • Charles Sabate says:

    Could do without the music. But thanks for posting. It does help

  • Farhad Farkish says:

    The music 🤒🤒🤒🤒🤕🤕

Leave a Reply

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