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.
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.
SQRT().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.
| Task | Type | Interval | Priority | Calls POU |
|---|---|---|---|---|
| MotionTask | event | on sync IRQ | 1 | PLC_Motion (PRG) |
| FastTask | cyclic | 4 ms | 5 | PLC_Fast (PRG) |
| MainTask | cyclic | 20 ms | 10 | PLC_PRG (PRG) |
| BackgroundTask | freewheeling | as fast as free | 15 | PLC_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.
You need a reusable conveyor controller, dropped onto 10 conveyors, each holding its own state & timer. Which POU type?