The short answer
Tasks and Execution Priority
A modern controller does not run one scan; it runs tasks. The continuous task runs the main program over and over as fast as it can. Periodic tasks run at a fixed interval, preempting the continuous task at a set priority, which is where PID loops, fast counting, and anything that must run at a known rate belong. Event tasks run when something happens, an input changes or data arrives. Getting the assignment right is what makes a loop tune the same on a busy day as on a quiet one.
Key points
- The continuous task runs whenever nothing of higher priority needs the processor, so its scan time varies with everything else.
- A periodic task runs on a fixed interval and its logic sees a constant time step, which is what closed-loop control needs.
- A higher priority task interrupts a lower one; a task that overruns its period is a fault waiting to happen.
- Put fast, timing-sensitive logic in short periodic tasks and everything else in the continuous task.
- Each task has its own watchdog, and the tasks together must fit within the processor time available.
One scan is not enough
The simple picture of a controller is one program executed top to bottom in a loop. Small controllers still work that way, and it is fine for a lift station. But a program that handles a plant has logic that must run every 10 milliseconds beside logic that would be happy running every second, and running all of it at the rate the fastest piece needs wastes the processor. Tasks are how the controller runs different parts of the program at different rates with different urgency.
The three kinds
- Continuous
- Runs the programs assigned to it repeatedly, restarting as soon as it finishes, in whatever processor time the other tasks leave. Its scan time is whatever it happens to be, and it changes with communication load and with what the periodic tasks are doing. Most sequencing, interlocking, alarming, and general logic lives here.
- Periodic
- Runs at a fixed interval, 10 ms, 100 ms, 1 s, at a set priority. When the interval elapses, the controller suspends whatever lower-priority task is running, executes the periodic task, and resumes. Its logic sees a constant time between executions, which is what a PID instruction, a rate calculation, or a totalizer needs.
- Event
- Runs when a trigger occurs: a change of state on a designated input module, a consumed tag arriving from another controller, a motion event, or an instruction in another task. It is how the controller reacts to something within microseconds of it happening rather than at the next scan.
The names and the details vary by platform. One vendor calls them tasks with programs inside them; another has a cyclic main block and cyclic interrupt blocks at fixed intervals; a third has a single scan with a high-speed interrupt routine. The behavior is the same everywhere: some logic runs on a fixed clock with priority, and the rest runs in the gaps.
Priority and preemption
Each periodic and event task has a priority. A higher priority task interrupts a lower one wherever it is, even in the middle of a rung, runs to completion, and hands the processor back. Two tasks at the same priority take turns. The continuous task has the lowest priority of all. The practical rule is that the fastest task gets the highest priority, so that a 10 ms task is never held up by a 500 ms task that happened to be running.
What goes where
| Logic | Task | Why |
|---|---|---|
| PID loops | Periodic, at the loop update rate | The integral and derivative terms assume a constant time step |
| Flow totalizing and rate calculations | Periodic | A total accumulated on a variable scan is wrong by the scan variation |
| High-speed counting or pulse handling | Event or fast periodic | A pulse shorter than the continuous scan is missed |
| Sequencing, interlocks, alarms | Continuous | Tens of milliseconds of variation do not matter |
| Communication and SCADA handling | Continuous or slow periodic | Neither fast nor time critical |
| Safety-related logic | Not in the standard controller | A safety function belongs in a safety-rated controller or a hardwired circuit |
Overlap and overrun
A periodic task that takes longer to execute than its interval has overrun: the next execution is due before this one has finished. The controller flags it, on most platforms as a task overlap counter, and depending on configuration either skips an execution or faults. An overrun is a design error: the task has too much logic for its interval, or a higher priority task is starving it. The fix is to move logic out of the task, lengthen its interval, or reconsider the priorities, and the task overlap counter is the diagnostic to watch after any change.
All the tasks together have to fit in the processor. If periodic tasks consume most of the available time, the continuous task starves, its scan time stretches to seconds, and the plant slows down without anything faulting. The controller reports the time consumed by each task, and keeping the total well under the capacity is part of the design.
Watchdogs per task
Each task has its own watchdog, a maximum execution time after which the controller faults. The default is generous for the continuous task and tighter for periodic ones. A watchdog fault names the task, which is the first clue to where a loop or a blocking instruction lives. The watchdog page covers it.
Frequently asked questions
- Should I put my PID loop in a periodic task?
- Yes. The integral and derivative calculations assume a constant time between executions. In the continuous task that time varies with load, and the loop behaves differently on a busy scan than a quiet one. A periodic task at the loop update rate gives it the constant step it assumes.
- What rate should a periodic task run at?
- As slow as the logic in it allows. A pressure loop might need 50 to 100 ms; a level loop is fine at one second. Faster rates consume processor time and leave less for everything else.
- What happens if a periodic task overruns?
- The controller records an overlap, and skips or delays the next execution. It is a design error: too much logic for the interval, or starvation by a higher priority task. Move logic out or lengthen the interval.
- Can safety logic go in a fast periodic task?
- Speed is not the issue; integrity is. Logic that protects people belongs in a safety-rated controller or a hardwired circuit, where a single fault cannot defeat it, not in a task of the standard controller, however fast.
Related topics
- The PLC Scan CycleRead inputs, solve logic, write outputs, housekeeping. Understanding scan order explains most PLC behavior that looks wrong at first glance.
- The Watchdog TimerWhat the scan watchdog protects against, why it faults the controller instead of pausing it, what makes a scan run long, and why raising the limit is the wrong first response.
- PID Control for Pumps and ValvesWhat each term actually does, how to tune a loop on a real pump station, and the handful of mistakes that cause most of the oscillation people blame on tuning.
- Program OrganizationStructuring a controller program so that someone else can maintain it: a layout that follows the plant, one routine per job, standard device blocks, I/O mapped in one place, a fixed execution order, naming that means something, and comments that say why.
- What Is a PLC?A programmable logic controller is a ruggedized industrial computer that reads field inputs, solves a control program, and drives outputs on a repeating, deterministic cycle.
- PLC ArchitectureHow a programmable logic controller is physically organized: the chassis, backplane, processor, I/O modules, remote racks, and what those choices mean for wiring, expansion, and failure.
Direct contact
Have a controls question?
Reach Eric Sullivan directly about anything on this site, a controls or automation topic, or one of his personal projects.