Inst ToolsInst ToolsInst Tools
  • Courses
  • Automation
    • PLC
    • Control System
    • Safety System
    • Communication
    • Fire & Gas System
  • Instrumentation
    • Design
    • Pressure
    • Temperature
    • Flow
    • Level
    • Vibration
    • Analyzer
    • Control Valve
    • Switch
    • Calibration
    • Erection & Commissioning
  • Interview
    • Instrumentation
    • Electrical
    • Electronics
    • Practical
  • Q&A
    • Instrumentation
    • Control System
    • Electrical
    • Electronics
    • Analog Electronics
    • Digital Electronics
    • Power Electronics
    • Microprocessor
  • Request
Search
  • Books
  • Software
  • Projects
  • Process
  • Tools
  • Basics
  • Formula
  • Power Plant
  • Root Cause Analysis
  • Electrical Basics
  • Animation
  • Standards
  • 4-20 mA Course
  • Siemens PLC Course
Reading: What are Functions in PLC Programming? (FCs)
Share
Font ResizerAa
Inst ToolsInst Tools
Font ResizerAa
  • Courses
  • Design
  • PLC
  • Interview
  • Control System
Search
  • Courses
  • Automation
    • PLC
    • Control System
    • Safety System
    • Communication
    • Fire & Gas System
  • Instrumentation
    • Design
    • Pressure
    • Temperature
    • Flow
    • Level
    • Vibration
    • Analyzer
    • Control Valve
    • Switch
    • Calibration
    • Erection & Commissioning
  • Interview
    • Instrumentation
    • Electrical
    • Electronics
    • Practical
  • Q&A
    • Instrumentation
    • Control System
    • Electrical
    • Electronics
    • Analog Electronics
    • Digital Electronics
    • Power Electronics
    • Microprocessor
  • Request
Follow US
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Inst Tools > Blog > PLC Tutorials > What are Functions in PLC Programming? (FCs)

What are Functions in PLC Programming? (FCs)

In this article we will get to know the basics of functions in PLC programming, what are they, when to use them, and how to use FC.

Last updated: March 15, 2023 1:33 pm
Mahmoud Salama
PLC Tutorials
1 Comment
Share
12 Min Read
SHARE

Programming a certain industrial process using a PLC can be very simple and easy to achieve provided that you are able to use the many tools available within the PLC, these tools are there to help you reach your programming goals easily and fast and also help you write an easy to read, follow and debug code.

Contents
Simple ProcessMore Complicated ProcessWhat is a Function Block (FC)?How to Create and Use an FC?Functions in PLC ProgrammingProgram SimulationConclusion

One of these many tools in a PLC is the Function blocks or FCs. In this article we will get to know the basics of function blocks, what are they, when to use them, and how to use them.

Contents:

  • Simple process.
  • More complicated process.
  • What is a Function (FC)?
  • How to create and use an FC?
  • Program simulation.
  • Conclusions.

Simple Process

Let’s consider a simple industrial process where you have a conveyor belt M1 that runs to transfer a product (P1) to the end of the line. The conveyor will run when a start S1 signal is available after a presence sensor B1 detects the product on the Belt.

The conveyor will start running and continue to run until the product is transferred to the end of the line and a detection sensor B2 detects the product, then the belt will stop. See picture 1.

PLC industrial Conveyor process
Picture 1 – Simple Conveyor System

Coding this process in your PLC will be fairly simple and easy, considering you have few inputs and outputs in this logic.

When coding this logic in Siemens TIA Portal, it will be as follows:

  1. Create your project.
  2. Configure your PLC (in our example we used CPU 1512C-1 PN).
  3. Define your input/output tags: see picture 2.
  • Start push button S1  %I10.0
  • Detection sensor B1   %I10.1
  • Detection sensor B2   %I10.2
  • Conveyor Motor M1   %Q4.0
defining your tags in PLC
Picture 2 – defining your tags

4. Open your main OB1 and write your code. See picture 3.

5. Compile and run your logic.

Functions in PLC Programming
Picture 3 – the logic of the conveyor belt

As you can see from picture 3, the logic of this process is very simple and it works as follows:

When a product is at the start of the belt and the start Push button is pressed the conveyor will run and it will keep running until the product is detected at the end of the line.

More Complicated Process

Now, imagine your production line has 50 conveyor belts all of them need to be controlled in the same manner as conveyor M1. One approach to achieve this will be by repeating steps 3 through 5 fifty times. This is not wrong, but now you have to write the same logic 50 times, and even if you just copied network 1 in picture 3 and paste it fifty times, you still have to redefine and reassign the new tags to the new networks.

Another hustle you might face is when you need to add a new parameter for your control, for example, you need to add a stop push button in your logic to stop the conveyor belt at any time the button is pressed. That means you will now define the new input signal and you will have to write it fifty times for your fifty networks, See picture 4.

More Complicated Process in Siemens Tia
Picture 4 – Re-editing your code

You see, you will have to make this change in all fifty networks of your logic. And if you forget one, your code will not work as desired and most likely it will not be something that your compiler can detect. So programming your logic this way has a lot of disadvantages.

The Best approach is to use Function Blocks or FCs.

What is a Function Block (FC)?

A function block or FC is simply a block that contains a specific logic made by a programmer, this logic or FC will be executed whenever it is called.

Functions can be used, for example, for the following purposes:

  • To return function values to the calling block, e.g. for mathematical functions.
  • To execute technological functions, e.g. individual controls using bit logic operations.

You have been using functions all along, maybe you haven’t noticed, but some of the basic instructions you usually use in your codes are actually function blocks, and each time you use this instruction you just call the FC and assign your parameters to it.

Examples of these functions are mathematical instructions like ADD & MOVE instruction. See picture 5.

What is a Function Block (FC)
Picture 5 – ADD&MOVE are examples of FCs

How to Create and Use an FC?

Now, back to our fifty conveyor belt process, how can we apply the FC concept to our logic?

The simple concept is that you will create a function block that has the logic of operation of the conveyor belt created inside, and each time to need to run a certain conveyor belt you will just call the FC and assign the parameter of this conveyor.

For example, if I want to run the conveyor belt 20 in my process, I will call this function and give it the parameters of the conveyor belt 20. Same if I want to run belt 46 or any other conveyor.

That means I will create the logic only one time. And reuse it whenever I need to. It also means, if at any point I decided to add something to my logic, I will only make that edit in the main FC block, that change will automatically be included each time you call the function.

Functions in PLC Programming

To create an FC Block, we do the following Steps.

In Siemens TIA Portal, Create a function block, by pressing the add new block icon, see picture 6.

How to Create and Use an FC Block
Picture 6 – create new function block.

Create the conveyor belt logic as you did before, but don’t assign specific IOs for that logic, instead define IOs inside the function block interface, so it can be reused again. See picture 7.

create your FC logic
Picture 7 – Create your FC logic

You now finished coding your function; you can call this function anytime you want to execute that logic. See picture 8.

call your FC Block
Picture 8 – calling your FCs

Notice, that each time you call the function, it will ask you to assign the inputs/outputs parameters of the function. That way you can use the same logic for different conveyors.

If for example, I need to operate conveyors 1 and 15 I will call the function twice and give each call the parameters of a certain conveyor. See picture 9.

assigns different PLC parameters to different function calls
Picture 9 – assigns different parameters to different function calls.

Now, imagine you need to edit your logic and add some extra functionality, for example, you want to add an output that will be ON whenever the conveyor is running, and you will use this output for an indication lamp to notify the operators that this conveyor is now running.

Using the concept of FCs, you will just have to edit your logic inside the function and it will be implied whenever you use your function. See picture 10.

editing function block
Picture 10 – Editing your function block

Now, each time you call the function it will ask for the indication lamp output tag for each call. See picture 11.

Function Block Example Code in PLC
Picture 11 – Editing the FC will be implied in each function call

Program Simulation

We will now, simulate our program to see how a function works. Follow the next steps:

Compile your PLC code and start a new simulation.

At first, you see the Function is called twice, for conveyors 1 and 15 see picture 12.

Function Block Program Simulation
Picture 12 – Simulation of program.

Now, try to run conveyor 1 by activating S1 and B1, see picture 13.

Learn How to Use FC for Programing Siemens PLC
Picture 13 – only conveyor 1 is running

Notice, how only belt 1 is running, even though we have two calls for the same function, but conveyor 15 is not running as its conditions are not met yet.

Now, try to run conveyor 15, and notice that its operation is completely separate from the conveyor 1 process, even though it is the same function. See picture 14.

What are PLC function blocks
Picture 14 – Different function calls are independent of each other.

Did you notice, how after a while conveyor 1 stopped as the B2 signal is now true? While conveyor 15 still running. That is how a function block in a plc can be created and used.

Downloads:

  • Siemens Tia Portal Sample Code
  • Function Block Code in PDF

Conclusion

Using function blocks or FCs in your logic will optimize your code and make it clean and easy to understand. It will also give you the advantage of reusing your code as many times as you want in one program which will reduce a lot of coding and editing time and also will reduce errors in your program.

If you liked this article, then please subscribe to our YouTube Channel for PLC and SCADA video tutorials.

You can also follow us on Facebook and Twitter to receive daily updates.

Read Next:

  • How to use JUMP Instruction
  • Program to Count Running Hours
  • Water Level Control Logic
  • Tank Level Detection Switches
  • Industrial Automation Systems
Don't Miss Our Updates
Be the first to get exclusive content straight to your email.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address
You've successfully subscribed !

Continue Reading

How to Automatically Close Pop-up in FactoryTalk View Studio?
Smart Automation Solutions: PLC Logic for Stairway Lighting
PLC Programming in Hindi – Siemens Tia Portal Full Course Free
Basics of Industrial Communication Networks
Motion Detection based Street Light: PLC Logic Solution
PLC Question Bank
Share This Article
Facebook Whatsapp Whatsapp LinkedIn Copy Link
Share
1 Comment
  • Stephen Nabasa says:
    April 30, 2023 at 1:18 pm

    Thanks for the precious knoledge your giving us

    Reply

Leave a Reply Cancel reply

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

Stay Connected

128.3kFollowersLike
69.1kFollowersFollow
210kSubscribersSubscribe
38kFollowersFollow

Categories

Explore More

SCADA Systems
Quiz: Identifying I/O Examples in PLC Systems
PLC Programming Example with Pushbutton and Motor
Conveyor Speed Logic using Structured Text in PLC
PLC Program for Daily Production Record
SCADA Communication and Protocols
PLC Mixing Logic in Liquids on EcoStruxure Machine Expert-Basic
How Engineers Effectively do Problem-solve and Troubleshoot?

Keep Learning

Marshalling Panel

What is Marshalling Cabinet?

Boolean Logic to PLC Programming

Boolean Logic to PLC Programming

PLC Ladder Logic Example

PLC Ladder Logic Example

memory types in siemens plc

Memory Structure of Siemens PLC

Allen Bradley PLC Example with Sub routines

How to use Sub Routines with Allen Bradley PLC

Coil Type Timers in Siemens PLC Programming

Coil Type Timers in Siemens PLC Programming

4 TO 20 MA ANALOG CURRENT SIGNALS

Basics of 4 to 20 mA analog Signals

Siemens PLC Course for Beginners

Siemens PLC Course for Beginners: Problems and Solutions

Learn More

compressor emergency shutdown system

Solenoid Valves Questions & Answers – 2

Measurement and Instrumentation Objective Questions

Measurements & Instrumentation Quiz – Set 2

Single Position Calibration of Temperature Bath

Single Position Calibration of Temperature Bath

PLC Program for Selective Execution of the Application

PLC Selective Execution of the Application – Example Program

RTD Accuracy

What is RTD Accuracy ?

Seven Segment LED Display

Difference Between Common Cathode and Common Anode 7 Segment LED Display?

Gas flow rate Formulas

Gas Flow Formulas

Instrumentation Cables Testing Standards

Instrumentation Cables Testing Standards

Menu

  • About
  • Privacy Policy
  • Copyright

Quick Links

  • Learn PLC
  • Helping Hand
  • Part Time Job

YouTube Subscribe

Follow US
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?