In today’s article, you will learn about the different types of POUs, or Program Organizational Units, that are available to use in CODESYS projects.
By the end of the article, you will know the benefits of using POUs in your projects and understand the key features of the different types of POUs that are available in CODESYS.
If you’d prefer watching instead of reading, check out the video below. Otherwise, feel free to skip it and continue with the blog.
Let’s get started by talking about what POUs are and why they are useful.
Overview
POUs are blocks of code that can be reused in a project or across multiple projects. To use a POU, you call it in your application. When you call a POU, the code inside the POU is executed.
The two main advantages of using POUs in your PLC projects are code reuse and project organization.
Let’s look at each of these advantages in more detail.
Code reuse
POUs let you encapsulate and reuse code in a project. To understand the benefits of this, let’s look at a practical example.
Let’s say you have to write the logic to convert the temperature of a tank from degrees Celsius to degrees Fahrenheit. Since there is only one temperature to convert, it is OK to write the logic directly in a program and maintain it there.
But what if you had to convert the temperature of a large number of tanks?
If you copy and paste the conversion logic many times in your project, it becomes very hard to maintain and interpret.
Instead of copying and pasting, you can create a POU to encapsulate this logic and call the POU each time you want to convert a temperature.
By creating a POU, you can avoid duplicating logic in your program, encapsulate the technical detail of how the conversion is done, and create a single, central location where the logic to convert a temperature is maintained.
Structuring projects
POUs also allow you to structure your projects in a logical way.
Instead of writing all of the code for a project in a single project, you can use POUs to break a project down into logical components and call them in an order that creates a system hierarchy.
For example, you may use the S88 physical model to decompose a machine into units, equipment modules, and control modules.

After logically decomposing the machine, you can create a POU for each component and call those components in your project to create a hierarchy. In this case, a task calls the Unit POU, the Unit POU calls the Equipment Module POUs, and the Equipment Module POUs call the Control Module POUs.
This call stack provides a logical structure to the project.
Since each component is a standalone POU, you can also assign the development of each POU to different controls engineers. Since the development of each POU is happening in parallel, project run times can be reduced.
Now that we know the benefits of using POUs in our projects, let’s look at the different types of POUs that are available in CODESYS.
Types of POUs
Program POUs
Program POUs are top-level POUs that are usually called by a task.

Program POUs in CODESYS are what are known as singletons. This means that there can only be one instance of a program in your project.
In general, you will only call a program POU once in a project, and the program POU will be used to call function and function block POUs.
Functions
A Function POU is a simple type of POU that does not have its own internal memory. Since it does not have its own internal memory, it cannot store data across scans.
Function POUs are great for encapsulating simple calculations and logic that is repeated in a project.
In the previous example, we talked about a POU that converts a temperature from degrees Celsius to degrees Fahrenheit.
This would be a good application for a Function POU since there are no values that have to be stored - the calling POU simply passes a temperature value in degrees Celsius to the Function POU, and the Function POU returns a temperature value in degrees Fahrenheit by executing a pre-defined calculation on the input value.

Function Blocks
Function Blocks are more complex POUs that have their own internal memory. When you create a Function Block POU in CODESYS, you are creating a blueprint. This blueprint defines what logic should be executed and what data should be stored in an instance.
When you call a function block in your project, you are creating an instance of that function block. Each instance of a function block uses a dedicated variable to store the data for that instance. Since each instance has its own memory, instances act independently of each other.
This can be a bit confusing to think about, so let’s look at a concrete example.
A timer is a Function Block POU that you have probably worked with before.
Each time you create an instance of a timer in a CODESYS project by calling the function block, you have to define a variable that stores the data for that instance.
A project can have multiple instances that all behave independently of each other because each instance has its own data.

Wrap-Up
In this article, I explained what POUs are in CODESYS and the advantages of using POUs in your projects.
I also introduced the three types of POUs that are available to use in your projects.
Your team can get access to this course and all of our other great courses with a RealPars Business membership. To learn more about RealPars Business, head over to realpars.com/business.