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 !
Complex Car Parking Logic in XG5000 LS Electric PLC
Overview of Industrial Control Systems
Open Platform Communication (OPC)
#8 PLC Best Practices – Validate HMI Input Variables at PLC Level
ICS System Design Considerations
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

Interposing Relay Panel (IRP)

Interposing Relay Panel (IRP) – Wiring and Testing Requirements

Batch mixing process automation with Omron PLC

Automate Batch Mixing with Repeated Cycles in Omron PLC

LogixPro Simulator Software

Introducing PLC Programming using LogixPro Simulator Software

Coil Type Timers in Siemens PLC Programming

Coil Type Timers in Siemens PLC Programming

Omron CX programmer shift register

The Concept of Shift Register in Omron PLC with Example

Human Machine Interface

What is Human Machine Interface (HMI) ?

Control of Double-acting Pneumatic Cylinder

Ladder Logic for Control of Double-acting Pneumatic Cylinder

PLC Sequence Programming Ladder Logic

PLC Sequence Programming Ladder Logic

More Articles

Pneumatic Circuit Design Using PLC - 2

PLC Pneumatic Circuit Control

Solenoid Valve Terminology

Solenoid Valve Terminology Questions and Answers

Siemens PLC programming: BCD, Integer, Double Integer, Real

Troubleshooting a Biased Transistor

Troubleshooting a Biased Transistor

Ammeter with Shunt

Ammeter

Nuclear Magnetic Resonance Spectrometer Questions and Answers

Continuous Wave NMR Spectroscopy Questions & Answers

Closed Tank Application

Zero Elevation and Zero Suppression in Level Measurement

In this article, we will learn the difference between Machine Expert Basic and Machine Expert software in Schneider PLC.

Difference between Machine Expert Basic and Machine Expert – Schneider PLC

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?