Boolean Logic to PLC Function Blocks | Fundamentals
Have you ever wondered how skilled PLC Programmers create, install and test programs when presented with complex system requirements? Today’s successful PLC programmers possess knowledge and skills in electrical, mechanical, and software engineering. In addition to having expert-level skills in vendor-specific PLC programming software, PLC programmers rely on Boolean Logic and mathematical concepts to optimize their designs.
In this article, we’re going to have a look at some basic mathematical concepts that are used to create Function Block programs.
Boolean logic
Earlier we said that PLC programmers rely on mathematical concepts to optimize their designs. PLC programmers use Boolean Algebra, also called Boolean Logic every time they create a program.
Don’t let the term Algebra scare you because the concepts of Boolean Logic aren’t terribly difficult.
Boolean Logic centers around the fundamental concept that all values are either True or False. Going one step further, True and False can be represented by either a 1 bit or a 0 bit.
You’ve likely noticed that most PLC programming languages use the term BOOL to represent a digital input or output. BOOL is short for Boolean. Every digital I/O can be represented by a 1 or a 0.
Basic function blocks
Function Block Diagram (FBD) as described in IEC 61131-3 is rapidly replacing Ladder Logic as the programming language of choice amongst PLC programmers.
Let’s look at the two basic Function Blocks in FBD and investigate the Boolean Algebra associated with each.
OR function block
The OR Function Block has at least two inputs. Earlier we said in Boolean Logic, all values are either True or False and can be represented by either a 1 or a 0 bit.
The OR Function Block has a Truth Table that does two things.
First of all, it lays out all of the possible input conditions.
Secondly, it indicates how the output reacts to the input conditions.
From the Truth Table, we can see that the C is True when A OR B is True.
OK… Here’s where we get into the Boolean Algebra part. The mathematical expression for the OR function block is A OR B equals C. A plus sign is used to indicate the OR function.
In primary school, we were taught that the plus sign is used for addition. So… it would appear that the OR function block performs Boolean addition.
AND function block
Ok… Let’s move on to the AND Function Block. The AND Function Block has at least two inputs.
From the AND Truth Table, we can see that C is True when A AND B are True.
The mathematical expression for the AND function block is A AND B equals C.
Notice the multiplication symbol used to indicate the AND function. So, it would appear that the AND function block performs Boolean multiplication.
We can drop the multiplication symbol and the expression looks like this: AB = C
FBD optimization example
As we said earlier, PLC programmers rely on Boolean Logic to optimize their designs. Let’s look at a simple example of Boolean Logic optimization.
On the first pass of converting a system requirement into a FUNCTION BLOCK DIAGRAM, a programmer ended with three function blocks.
The programmer would ask herself… Can I optimize this FUNCTION BLOCK DIAGRAM and eliminate any of the function blocks using Boolean Algebra? The answer is Yes. So, let’s see how.
The Boolean Logic expression for this program is: D = AB + AC
Using a little high school math, we use the Distributive Law, and a transformation occurs.
Alright… now let’s rebuild our FUNCTION BLOCK DIAGRAM and see if we’ve made some progress towards optimization.
After using some basic algebra, we’ve gone from three function blocks to two function blocks.
I’ve given you just a glimpse of how Boolean Logic can be used in the optimization of PLC programs. Like it or not, seasoned PLC programmers have become mathematicians.
I recommend checking the following related articles, if you haven’t already, to have a better understanding of PLC Function Blocks:
What is a Control or Function Block?
What is the Difference between Ladder Logic and Function Block Diagrams?
Summary
OK… let’s review:
– PLC programmers possess a variety of knowledge and skills in electrical, mechanical, and software engineering.
– PLC Programmers have expert-level skills in vendor-specific PLC programming software and rely on mathematical concepts to optimize their designs.
– Boolean Logic centers around the fundamental concept that all values are either True or False and can be represented by either a 1 bit or a 0 bit.
– Function Block Diagram (FBD) is rapidly replacing Ladder Logic as the programming language of choice amongst PLC programmers.
– The two basic Function Blocks in FUNCTION BLOCK DIAGRAM are OR and AND.
– Boolean Logic can be used by PLC programmers in the optimization of PLC programs.
If you have any questions about the Boolean Logic or about PLC Function Blocks in general, add them in the comments below and we will get back to you in less than 24 hours.
Got a friend, client, or colleague who could use some of this information? Please share this article.
The RealPars Team
Join the Top 1% of Automation Engineers
Start Your 7-day Free TrialLearn from Industry Experts
With a 7-day trial, then €25/month