Inst ToolsInst ToolsInst Tools
  • Ask
  • Courses
  • Videos
  • Q & A
    • Interview
      • Instrumentation
      • Electronics
      • Electrical
      • Practical Questions
    • MCQ
      • Instrumentation MCQ
      • Electrical MCQ
      • Electronics MCQ
      • Control Systems MCQ
      • Analog Electronics MCQ
      • Digital Electronics MCQ
      • Power Electronics MCQ
      • Microprocessor MCQ
      • Multiple Choice Questions
  • EE
    • Electronics
      • Electronics Q & A
      • Electronic Basics
      • Electronic Devices & Circuits
      • Electronics Animation
      • Digital Electronics
    • Electrical
      • Electrical Basics
      • Electrical Q & A
      • Power Electronics
      • Electrical Machines
      • Electrical Animation
      • Power Systems
      • Switchgear & Protection
      • Transmission & Distribution
  • Measure
    • Control Valves
    • Calibration
    • Temperature
    • Pressure
    • Flow
    • Level
    • Analyzers
    • Switches
    • Vibration
    • Solenoid Valve
  • Control
    • PLC Tutorials
    • Control Systems
    • Safety Instrumented System (SIS)
    • Communication
    • Fire & Gas System
  • More
    • Design
    • Tools
    • Animation
    • Basics
    • Formulas
    • Standards
    • TextBooks
    • Common
    • Software
    • Excel Tools
    • Erection & Commissioning
    • Process Fundamentals
    • Videos
    • Books
Search
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Reading: Create a User-Defined Function Block in Codesys
Share
Notification Show More
Font ResizerAa
Inst ToolsInst Tools
Font ResizerAa
  • Courses
  • PLC Tutorials
  • Control Systems
Search
  • Ask
  • Courses
  • Videos
  • Q & A
    • Interview
    • MCQ
  • EE
    • Electronics
    • Electrical
  • Measure
    • Control Valves
    • Calibration
    • Temperature
    • Pressure
    • Flow
    • Level
    • Analyzers
    • Switches
    • Vibration
    • Solenoid Valve
  • Control
    • PLC Tutorials
    • Control Systems
    • Safety Instrumented System (SIS)
    • Communication
    • Fire & Gas System
  • More
    • Design
    • Tools
    • Animation
    • Basics
    • Formulas
    • Standards
    • TextBooks
    • Common
    • Software
    • Excel Tools
    • Erection & Commissioning
    • Process Fundamentals
    • Videos
    • Books
Follow US
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Inst Tools > Blog > PLC Tutorials > Create a User-Defined Function Block in Codesys

Create a User-Defined Function Block in Codesys

Learn how to create a user-defined function block in Codesys to optimize your PLC programming. Reduce coding time and memory usage.

Last updated: September 17, 2024 3:53 pm
Viral Nagda
PLC Tutorials
No Comments
Share
5 Min Read
SHARE

When a PLC programmer wants to create a logic where some part will be repeated many times in the program, then instead of writing it every time, he can create a library which will be the reference. In PLC programming, it is called a function block.

Function block allows the programmer to write the logic only once and then use multiple instances of it to reduce the coding time and memory to a great extent. There is one software tool in industrial automation that is used as a base for many software manufacturers, whose name is Codesys.

In this post, we will see how to create a user-defined function block in Codesys.

User-Defined Function Block in Codesys

First, in an application, select a new POU as shown in the first image. After that, you will be asked to choose to create a program or a function block.

Create a User-Defined Function Block in Codesys

There, you need to choose the function block as shown in the second image. Choose the corresponding implementation language you require for designing.

Codesys user-defined function block

Now, once the function block named POU has been created, you can write the logic inside it. Now, when you mapping a new variable, you will be first asked to create one as shown in the below image.

As a function block requires an input and output, these two types must be used; otherwise, there is no use in creating a function block. This popup comes automatically. Alternatively, you can write and create variables quickly by seeing the second image.

Follow the syntax as shown in a black box and write variables under var_input and var_output. You can also create local variables that can be used just inside the function box, by clicking the var option.

Accordingly, you can design your variable types. You can also make a variable as retentive, by clicking the retain option in the popup shown below.

function block named POU

The logic as of now that has been created is as shown in the second image – the value of the input is being moved to the output.

How to create a function block in Codesys

Once the logic inside the function block has been created, you can create a new program and create multiple instances of this function block. As shown in the below image, two instances of the function block have been created.

You can define the variables and blocks locally or globally as per your requirements. We have mapped the input and output variables as shown in the figure. These function blocks work in the same way as a system function block; working independently in instances.

Just remember that the function block instances must not be used more than once, otherwise, the PLC will not realize which function block to execute. And the logic will not work due to this. That is why, as you can see, we have used different names for the two instances we have used.

Function block development in Codesys

Now, if you make the following changes in the function block – adding or removing some variables, then you update these function block instances by right-clicking the block and using the option reset pin as shown in the below image.

As you can see, you can also remove unused pins (which means input and output), add an input pin, or add an output pin. If you are adding any pin, then you need to make the corresponding changes inside the function block too.

Codesys function block example

In this way, we saw how to create a user-defined function block in the Codesys platform.

Read Next:

  • Vijeo Designer software Import and Export
  • Why different PLC Programming Languages?
  • Download Free HMI software CODESYS
  • What is CODESYS? Why Do You Need to Learn it?
  • Import PlantPAx Add-On Instruction in Studio 5000
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 !
Configuration of InTouch Scada Trends
Batch Mixing with PLC Ladder Logic Program
Open Platform Communication (OPC)
What is Profinet and How to Configure in Siemens PLC?
How to use JUMP Instruction in PLC Ladder Logic?
Share This Article
Facebook Whatsapp Whatsapp LinkedIn Copy Link
Share
Leave a Comment

Leave a Reply Cancel reply

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

Stay Connected

128.3kFollowersLike
69.1kFollowersFollow
208kSubscribersSubscribe
38kFollowersFollow

Categories

Recent Comments

  • Kamli on Top Free PLC Software
  • Guifty Shimica on Top Non-PLC Certification Courses for Automation Professionals
  • Guifty Shimica on Top Non-PLC Certification Courses for Automation Professionals
  • MIHARITSOA Aina Sitraka on Top Non-PLC Certification Courses for Automation Professionals

Related Articles

0 to 10 mA Current Loop

What is Live Zero in 4-20 mA Current Loop ?

PLC Technique for IO Mapping

PLC Techniques for I/O Mapping

Profibus DP Master

DP Master System Configuration in PLC

Structured Text in PLC: Parking Information Systems

Structured Text in PLC: Parking Information Systems

Programming in Omron PLC

Automatic Vacuum Cleaner Programming in Omron PLC

SCADA Features

Features of SCADA

Two-Conveyor PLC Control System

Basic Conveyor System for Product Handling in Omron PLC

Logic for Always ON and Always OFF bit

Always ON and OFF Bit using Ladder Logic and Statement List

More Articles

Power Systems Questions & Answers

Power Systems MCQ Series 13

FBD Logic

Why different PLC Programming Languages were Developed?

Air Pressure Regulator cut-away diagram

Air Pressure Regulator Questions

Single Phase Earth Return System

Single Phase Earth Return System Advantages & Disadvantages

Selection Guidelines for Cable Glands

Selection Guidelines for Cable Glands

Plunger Pump Drive

Too Low Efficiency Torque Converter Elimination Attempt

Electrical Machines Questions and Answers

Alternators Multiple Choice Questions

Problem in Water Level Control System

Problem in Water Level Control System

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?