CODESYS Β· Track 02 Β· the program building blocks

POUs & the Task Config

A CODESYS program is built from POUs β€” Program Organization Units β€” in three flavours: PRG, FB and FUN. What separates them is memory and instancing. Then the Task Configuration decides which POUs run, how often, and at what priority. Get these two ideas and you understand how any CODESYS app executes.

πŸ“‹ PRG🧠 FBβž— FUN
01 Β· The three POU types

Memory is the difference

Tap each. A FUNCTION is pure maths β€” inputs in, value out, no memory. A FUNCTION_BLOCK has its own data and can be instanced many times, each remembering its own state. A PROGRAM is like a single global FB instance β€” one copy, called by a task.

PRG
PROGRAM
A single global instance, called directly by a task. Holds state, but there's only one of it.
one instance
FB
FUNCTION_BLOCK
Behaviour + private data. Declare many instances; each keeps its own timers, counters, state.
many instances
FUN
FUNCTION
Stateless. Same inputs β†’ same output, every time. No memory between calls. Like SQRT().
no memory
02 Β· The Task Configuration

What runs, how often, what wins

A POU does nothing until a task calls it. The Task Configuration lists the tasks, each with a type, an interval and a priority (0 = highest). Higher-priority tasks preempt lower ones β€” so keep the fast ones short.

TaskTypeIntervalPriorityCalls POU
MotionTaskeventon sync IRQ1PLC_Motion (PRG)
FastTaskcyclic4 ms5PLC_Fast (PRG)
MainTaskcyclic20 ms10PLC_PRG (PRG)
BackgroundTaskfreewheelingas fast as free15PLC_Bg (PRG)

Four task types you'll meet: cyclic (fixed interval β€” the workhorse), freewheeling (restarts as soon as it finishes β€” no guaranteed rate), event (fires on a signal/IRQ), and status (runs while a flag is true). Each task has a watchdog β€” overrun your interval and it trips, exactly like every other brand's scan-time guard.

03 Β· Check yourself

Which POU type?

You need a reusable conveyor controller, dropped onto 10 conveyors, each holding its own state & timer. Which POU type?