A CODESYS program is built from POUs (Program Organization Units) of three types: PRG, FB and FUN. They differ in whether they retain data and how you create instances. The Task Configuration decides which POUs run, how often, and at what priority. Together, these settings determine how the application executes.
Select each POU type to compare it. A FUNCTION takes inputs and returns a value without retaining memory between calls. 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-priority ones, so keep the fast tasks short.
| Task | Type | Interval | Priority | Calls POU |
|---|---|---|---|---|
| MotionTask | external 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) |
Five task types you'll meet: cyclic (runs at a fixed interval), freewheeling (restarts as soon as it finishes, with no guaranteed rate), event (starts on a rising edge of a BOOL variable), external event (starts on a system event such as a fieldbus sync or hardware interrupt, if the device offers one), and status (runs while a flag is true). Each task can have a watchdog with its own time and sensitivity. When the task runs past the watchdog time for as many cycles as the sensitivity allows, the runtime raises an exception and halts the application, like the scan-time guard on other brands.
You need a reusable conveyor controller, dropped onto 10 conveyors, each holding its own state & timer. Which POU type?