Yaskawa
eLearning
You're watching the IEC 61131 Basics
Video Tutorial Series
covering Functions and Function Blocks
Hi, I'm Matt Pelletier
Now first I'd like to show you the differences between
Functions and Function Blocks
and then I'd like to explain how
Bitwise Functions work
how to Duplicate and Negate Function Inputs
and how to use the EN/ENO feature.
Let's start with a comparison of Functions
versus Function Blocks
and I'm using an example here of AND
and a TON, two blocks that we've used
and the first distinction of an IEC 61131 Function
versus Function Block
is that every single function will execute in one scan
one scan through the code
and the inputs produce the output
this is no necessarily the case with a Function Block
think of the Block T ON
several scans are necessary
just to tell how much time has gone by
and so because of this difference
you'll notice that a Function
does not have what we call an Instance
which is this title above a Function Block
see a Function operates and
if there's another Function next to it
it operates in the same way immediately
whereas a Function Block
has to store for the next scan through
as to store all of its operational results into
memory somewhere and that's called an Instance
and so one telltale sign of
is it a Function or Function Block
is you look for this title
there has to be an Instance
of the Function Block
there will never be an instance of a Function.
Another property of the Function is the
Single Output
Every Function will have just one output
and a Function Block may have only one
or may have more than one.
Moving down to the fourth
you must connect all output and all inputs
for the Function to compile.
A Function you can't just leave any of
the outputs or inputs disconnected
this is not the case in a Function Block
the code will compile
if you don't connect outputs at all
if you don't connect inputs well there may be
some inputs that are required for the
Function Block to compile and there may
be inputs that are required for the
Function Block to work
you won't even get a Make to be successful
with a Function if you don't connect all inputs
and the output.
The next property of Functions
is that the Output Value
depends only on the Function Inputs
this is the output right here and its value
depends only on the Inputs.
Think of a mathematical function
if you have several variables that determine
the Output there's one right answer and it
depends only on those Inputs
it doesn't depend on how much time has gone by
think of T ON, for example we don't have
an Input for how much time has passed
that's a hidden if you would a given Input
that this Function Block will use
in order to adjust its outputs
and other types of Function Blocks for example in
PLC Open may control Motion
the Motion may not be possible, you may get errors
on the Blocks depending on certain conditions
other than the conditions given
by the Inputs to the Block
so again this is an important distinction
if you have certain values as
an Input to a Function, you will always have
the same Output Value
that is not necessarily true for a Function Block
because there are other factors that
affect the outputs of a Function Block
other than the Inputs alone.
Now these last three properties apply more
specifically to user created Functions
or Function Blocks.
Things to keep in mind if you're going to
make your own Function or Function Block
One, is that if you make your own Function
you can't put Function Blocks inside of it
if Function Blocks break all these above rules
how are you going to make a Function
out of Function Blocks
can't be done
To make your own custom Function Block
you can use Functions or Function Blocks
in order to create your own Function Block.
So you may ask yourself why bother ever
creating a customized Function if there
are all these limitations when you create a
customized Function
and one of the answers is that it's
a very efficient way to calculate
simple mathematical formulas
it's a very efficient use of
the processor in RAM.
If you were to make a Function Block
to do what a Function could have done
it will use slightly more processor power,
slightly more RAM to do the same task
so if you can put it in a Function
that's more efficient
if you have to do it in a Function Block
it's not so inefficient, but as the best practice
use a Function if you can
otherwise use a Function Block.
Finally, related to Variables
when you create your own Function
and Function Block
you will not be allowed to use Global Variables
to create a Function.
You can use Global Variables in your
Function Blocks internally to make them run
however it's not really a great idea to
use Global Variables because then those
Global Variables must exist in any future project
in which you'd like to use your custom Function Block
so we'd recommend that if you have data you'd
like to add to the Function Block that
you don't include a hidden Input, so to speak,
as a Global Variable that has to
be created instead make it as an Input
and in another video we'll be showing
how to make a custom Function
and a custom Function Block
so you'll see how to do that.
Now when working with Functions
some Functions have what we call
a Bitwise operation
which means that given two inputs of the same
data type and a Block such as AND or OR
the Bits of that data are ANDed
so it's more than the equivalent of a two ladder
contacts in series because you're not
limited with the AND or the OR function
to using only Booleans
you can use any data type and the data
is ANDed with a Bitwise result as we see here
Input 1 had these values for each Bit
and Input 2, these other values ANDing means
ANDing together Bit by Bit
and that's how you get the result
and if you recall when we created our Array,
I put in two Array elements into an AND Block
and got the result
and the result was therefore
calculated Bit by Bit of each of those
Word Data Types in the Array.
The IEC 61131 Functions
also have properties
Functions and Function Blocks have properties
and I'd like to focus on two of them
Negate and Duplicate
and we'll stick with our example here of AND
Negate puts this little circle
which is the same as a NOT
in front of it
it's taking the opposite of that Input
in the case of a non-Boolean Data Type
such as Word, it would negate every Bit
so how do you get to the Properties
of a Function or Function Block?
You can either double-click or
right-click and choose Object Properties
this is giving the Object Properties
for this Block it lists here the Inputs and Outputs
and you can see in this table that we can Negate
an Input and then the other thing we can do
in some Functions is to Duplicate
you do have to click on the correct one
usually that's the bottom one
and Duplicate
so I could AND several of the same
Data Type together by using Duplicate
and I can Negate Inputs
so sometimes this helps to
compact your code, make it a little more easy
to understand and instead of cascading
ANDs together you can put in as
many Inputs as you need
this technique also works with multiplication
and can put in an ADD
double-click for the Properties
and you could add several numbers
by duplicating the Input
and add them all up together.
And now you probably noticed that
when I ADD any Function
it gives me this EN/ENO Input and Output.
So what is that about?
How can we use it?
EN/ENO means Enable and Enable Output
it allows you to enable or disable
the execution of the Function
now if you have the EN Input
the Enable Input disconnected
then you are automatically
going to always Enable execution
and that's why back here when we did this AND
I had said just don't connect it and it will work.
So this is one option of not using EN/ENO
if you don't want to
that is don't connect it and the Function
will work fine
but the idea of using EN/ENO is that you can put
then your Block into a Ladder Rung
and have different conditions either Stop or
Start the execution of that Function
and we can see here the Output of ENO
under most circumstances that's equal
to the Input so you don't really have to
connect anything to ENO
but sometimes it's required
and one check is that if
there's ever a Function error
then your EN Input may be ON
but the ENO, an output would be OFF.
For example dividing by zero or
having some type of invalid data.
Some have misunderstood that the Enable Input
when disabled would somehow clear the Output
or force the Output of a function to zero
this is not the case
when the Enable Input is TRUE
then the operation to calculate the
Output based on the Inputs will occur
and every scan, the Output will update
when the Function is disabled
meaning EN goes to FALSE
then regardless of the value of the Inputs
the Output will remain as it was.
So here I am using the LT less than Function
and at a first the answer was YES
Value 1 is less than Value 2
if in the next scan I were to disable
enabling the Function
and then at some point in the future
Value 2 here were to change
since it's not executing the Function,
the Output remains as it was.
So the important conclusion is just understand
that Enable means enabling the operation
and enabling the Output to Updates
and disabling the Output to update
based on the Inputs
that is EN/ENO.
When you're creating your code
we understand that you may not
want to use the EN/ENO feature
and so to avoid mistakenly connecting variables
to those terminals
you may want to simply remove
the EN/ENO feature
and there's a couple ways to do that.
One is a software option called Graphical Editor
you can throughout your whole software
and your whole project
just to remove the capability of
Functions with EN/ENO
and the other option is a worksheet
per worksheet you can remove the option
of inserting Blocks with EN/ENO
you also do save a few Bytes of data
and memory in your code
so if you're not going to going to use EN/ENO
we would recommend that you do
insert them without it
and so let me show how to do that here
let's look at it live and go to your project
and do this along with me
we can go first to the Objects menu
I'll do it this way
and I've got this Block here
Insert Blocks with EN/ENO
now if I take a new AND Block
it inserts it and it's considerably smaller
then it would be with EN/ENO
so that's one advantage and it also has
as I mentioned, a fewer Bytes of memory
when it compiles
however, I can go to another worksheet
here I've got timers up
and I could put an AND in this one
and you'll see that it does put in EN/ENO
because the Objects menu
has this option checked for this worksheet
back in the Main POU
I had unchecked it
and it remembers that
I could put it back and forth
and so this is an option for the Worksheet.
If you'd like a global setting
you can go to Extras > Options
this has to do with the Graphical Editor
and you can uncheck this Functions with EN/ENO
and that will remove that for your entire project.
Now whichever way you do it
you do notice that the existing
functions were not affected
by that option if you would like them to be updated
then you can right-click > Update FB/FU
and it will remove the EN/ENO Input
and thus reduce by a small amount
your compiled code size
and this is what we're showing in this
this illustration of the presentation
is that whether you'd like to remove EN/ENO
or put an EN/ENO back in
you just right-click on the Function
and your current setting will be applied to
that Function.
So thank you, hope that that helps
with Functions and Function Blocks.