Skip to main content

CoDeSys 3.5 - POU Types and Languages

  • Author:
  • Updated date:

Liam is a programming enthusiast and likes to write about his work.

Create a new POU to add to your application.

Create a new POU to add to your application.

What Is A CoDeSys POU?

A POU is an object of a specified type and language. It houses code that is called by a task or another POU.

You can create a POU by right-clicking on the “Application” object from the Device Navigation Pane and selecting "Add Object >> POU."

The “Add POU” window will open. From here you can create a new POU to add to your application.

Name: The name of your POU

Type: The type of POU (this is covered in the next section)

Implementation Language: The language of the POU object. There are six options available that cover five different languages. The different languages have pros and cons, depending on what you are trying to achieve.

Clicking "Add" will add the new POU to your application object.

CoDeSys POU Types

There are 3 types of POU:

  1. Program
    1. The main POU type. If you’re not trying to create a reusable code module, this is the correct POU type to use. A program type can be called by another program type or a "task," and can call other programs, function blocks, or functions.
  2. Function Block
    1. A function block POU is the most versatile POU type. It enables you to write a function and use it multiple times in another POU. Function blocks are declared at design time, they are given an instance in the application. This means that if a function block is used more than once, it is named, allocated memory, and all instances of that function block remain separate from each other.
    2. A function block can be declared as a variable type.
    3. Full object-orientated programming is supported with Function Blocks using the “extends” and “implements” functions. When you're first getting started, simply ensure they are left blank. If your CoDeSys has checkboxes for “final” and “abstract”, these should also be left unchecked.
  3. Function
    1. A POU that has a single output that is declared at creation. A function is NOT created as an instance like a function block is. It can be used many times in your application, but the result is not retained in memory once executed. Your application must make use of the function and move the result to memory if it is to be retained. Functions such as timers are not suited well to functions as their elapsed time is lost every time the function completes.

CoDeSys 3.5 Languages

POUs can be written in five different languages. Each has different strengths and weaknesses, depending on the application that is being designed.

  1. Ladder Logic Diagram
    1. The most commonly used language, Ladder Logic excels at basic logic such as input / output control, timing, and basic functions.
    2. Ladder reads from left to right, top to bottom. Each row (called a network) consists of conditions to check on the left and outputs to set on the right. Function blocks can appear either to the left or right depending on what the function block is doing.
    3. Complex statements such as IF, WHILE, CASE are not available in Ladder Logic, although they can be replicated, if required.
  2. Structured Text
    1. Commonly used for complex control, algorithms, and repetitive functions.
    2. Structured Text is a written language and has no graphical properties. This can make it hard to read and follow, especially if proper notation is not followed.
    3. Structured Text is harder to learn than other languages.
    4. Complex statements are all supported.
  3. Function Block Diagram
    1. Very similar to Ladder Logic.
    2. Functions only are used to build the POU. Contacts / coils are not available.
    3. Used often to build a sequence of calls to other POUs.
  4. Instruction List
    1. Instruction list has recently been deprecated but remains for now in the CoDeSys system. The reason for its depreciation is it is difficult to write, read, and follow and offers very little in value over other languages.
  5. Sequential Function Chart
    1. Commonly used for State Machine architecture, Sequential Function Chart reads like a flow diagram. Using Transitions and Steps, the program flows downwards with sequential and parallel code steps executing until either the flow finishes or jumps to the beginning again.
    2. It is easy to induce errors with SFC by failing to ensure the flow is configured correctly.
    3. SFC allows each step be assigned actions, these actions can be based on events such as “entry,” “exit,” and “executing.” When an action is assigned, a POU is created and the option to choose a language is provided.
    4. Advanced users can create very complex architectures with relative ease.
  6. Continuous Function Chart
    1. Similar by nature to Function Block Diagram, the POU consists of mainly calls to functions.
    2. The design is 100% graphical, with wires connecting inputs and outputs between functions.
    3. Used mainly for small functions.
    4. Is not an official IEC-supported language.

© 2018 Liam