IMDHMIControls LibraryShop main store

How-to

Run Logix 5000 PID loops in a periodic task

PLC programming Published 6 min read

Short answer

No. Thirty PID instructions in a FOR loop in a continuous task, with no timer, execute once per scan at a varying interval, so their loop update time setting never matches reality. Move the routine into a periodic task whose period equals the shared update time, and write that same period into every loop's .UPD.

On this page
  1. Why a continuous task cannot time a PID
  2. What the loop update time actually does
  3. Choose the rate from the process, not the scan
  4. Move the calls into a periodic task
  5. When the loops need different update times
  6. Keep the schedule honest
  7. Worked example: a 25 ms task for 30 same-rate loops
  8. Questions asked

No. Thirty PID instructions called from a FOR loop in a continuous task, with no timer and no periodic trigger, do not execute at their loop update time. Each one computes once per scan of the continuous task, at whatever interval that pass happens to take, so the value in the update-time setting is not the interval the math sees. Move the routine into a periodic task whose period equals the shared update time, and write that same period into every loop's .UPD. That change is required; the rest of this article is how to size the rate, make the move, and prove the timing.

Why a continuous task cannot time a PID #

The Logix 5000 PID instruction is event-driven: it performs one calculation each time the statement that calls it executes, and nothing inside the instruction decides when that happens. Current Logix instruction documentation is direct about the arrangement: the simplest way to execute the instruction is from a periodic task, with the loop update time member (.UPD) set equal to the task period.

The habit that catches programmers here comes from the SLC family, whose PID ran on an unconditional rung with its own internal timing. The ControlLogix PID follows the PLC-5 convention instead: outside a periodic task it must sit on a conditioned rung or inside a structured-text condition that fires at a defined interval.

Your FOR loop visits every enabled loop once per pass of the continuous task, and the continuous task has no fixed period — its scan time moves with logic size, online edits, and message load. The condition on .ENB decides whether a loop computes, never when. An enable bit is not a timing trigger.

What the loop update time actually does #

Setting .UPD schedules nothing. The member tells the instruction what interval to assume when it applies your integral and derivative tuning, so the loop's dynamic action is correct only when the real interval between calls matches the configured one. Call a loop every 40 ms of drifting scan with a fixed update-time setting, and the integral and derivative the process actually receives are not the ones you entered.

The loops can still hold setpoint, because they were tuned against the behavior the accidental rate produced. That tuning is chained to the scan time: any change that shifts the continuous scan retunes all 30 loops without anyone touching a gain. Any routine that assumes a fixed execution interval has the same dependence; porting a PLC-5 filter routine to ControlLogix structured text is the same trap with different coefficients.

Choose the rate from the process, not the scan #

The useful execution rate comes from the process. The working rule is to sample at least ten times within the process time constant: T ≤ 0.1 × Tp, where T is the interval between PID executions and Tp is the process time constant. As the rate falls toward five samples per time constant, T approaching 0.2 × Tp, performance degrades measurably; below that the loop cannot track what the process is doing.

Going faster than a loop needs is usually recoverable: retune and the loop settles. Going slower than the process is not fixed by tuning. The floor under your chosen rate is controller capacity, because every call in the task adds execution time. Since all 30 loops share one update time and hold setpoint today, keep one rate: set the task period to that update time.

Move the calls into a periodic task #

The call itself does not change. The structured-text form of the instruction is PID(PID,ProcessVariable,Tieback,ControlVariable,PIDMasterLoop,InHoldBit,InHoldValue); — the first operand is the PID tag, PID[Index] in your array, and the FOR loop around it reaches all 30 in one pass. What changes is which task the routine lives in.

  1. Record the configured update time of all 30 loops and confirm they are the same value.
  2. Create a periodic task and set its period to that value. If the loops ever need different rates, use the arrangements in the next section instead.
  3. Move the program or routine holding the FOR loop out of the continuous task and under the periodic task. Keep the enable and disable conditions exactly as they are.
  4. Set .UPD on every PID tag equal to the task period.
  5. Download with the loops in manual and the process in a state that tolerates a wrong output for a few seconds: a loop that suddenly executes at its configured rate will not behave as it did on scan time.
  6. Return the loops to automatic one group at a time and trend process variable and control variable through normal load changes, retuning only where the response asks for it.

No timer belongs inside the new task. The schedule replaces the pulse, and it is the more consistent trigger: a timer-done bit is only noticed at a scan boundary, and at intervals in single-figure milliseconds that jitter is the same problem you just removed.

When the loops need different update times #

One periodic task period can equal only one update time. If the loops split into different rates, give each rate its own periodic task and set every loop's .UPD to that task's period. The alternative is one base task running at the fastest interval any loop needs, with each loop gated to execute on every Nth scan; a loop gated that way executes at N times the base period, and that product is the value that belongs in its .UPD.

What you cannot do is call every loop on every scan of one task while the .UPD values disagree with the period. That rebuilds the continuous-task problem at a new rate.

Keep the schedule honest #

A periodic task times the loops only if it finishes inside its period every time. After the download, read the task's execution time in the programming software's task monitor and compare it with the period; the pass condition is execution time comfortably below the period on the worst execution, not the average one. The failure mode to catch early is what happens when a periodic task period is less than its execution time, because overlap and watchdog faults follow from it.

If the 30-call routine runs close to its period, split the loops across two tasks at the same period rather than stretching the rate past the sampling rule.

Worked example: a 25 ms task for 30 same-rate loops #

Inputs: 30 PID instructions called from one FOR loop, all sharing a single configured loop update time, from this project. A candidate task period of 25 ms, the rate proposed for this job. The sampling rule from above: T ≤ 0.1 × Tp.

Rule in words: the task period equals the update time written to every loop, and an execution interval is fast enough only for processes whose time constant is at least ten times that interval.

Arithmetic: the fastest process the 25 ms interval covers is Tp = 25 ms ÷ 0.1 = 250 ms.

Result: a 25 ms periodic task meets the ten-samples-per-time-constant rule for every loop whose process time constant is 250 ms or slower.

Decision: set the task period to 25 ms and .UPD to 25 ms on all 30 tags. Any loop whose process responds faster than a 250 ms time constant moves to a faster task, with its .UPD set to that faster period. After download, the routine's execution time must read well under 25 ms; if it does not, split the loops between two tasks at 25 ms before changing the rate.

Questions asked

My loops already hold setpoint in the continuous task. Do I really have to move them?

Yes. Holding setpoint proves only that today's scan rate and today's tuning happen to agree; the integral and derivative action is still being scaled by an interval the instruction is not running at. Any change that shifts the continuous scan, such as more logic, heavier messaging, or an online edit, changes the effective tuning of all 30 loops without anyone touching a gain. The move costs one task and one download; leaving the code as it is spends stability every time the scan drifts.

Is a timer-done bit an acceptable trigger instead of a periodic task?

It is the documented alternative: put the call behind a condition that is true only when a timer completes at the intended interval, and set the update time to that same interval. It is simply less consistent, because the done bit is only seen on a scan boundary and timer resolution adds jitter; at intervals in the single-figure milliseconds the periodic task is clearly the better trigger. On slow loops the difference may never show.

What if the loops end up needing different update times?

Give each rate its own periodic task, with every loop in that task carrying the task's period as its .UPD. Or run one base task at the fastest interval any loop needs and fire each loop on every Nth scan; that loop then executes at N times the base period, and that product is the value that belongs in its .UPD.

Does the PIDE instruction have the same requirement?

PIDE also belongs in a periodic task; it assumes the configured execution rate for its control modes and calculations. It is not interchangeable with the PID instruction, since the two use different tag types, operands, and tuning methods, so confirm which instruction the project actually calls before moving anything. Thirty arrayed calls driven by a FOR loop in structured text, as described here, are the PID instruction.

How do I know the task period I picked is too fast for the controller?

The limit is the controller, not the rule. After the download, read the task's execution time in the programming software's task monitor and compare it with the period: the task must finish comfortably inside its period on its worst execution, not its average. If it runs close, split the loops across two tasks at the same period or lengthen the period within the sampling rule.

Keep reading

  • Troubleshooting

    When a CODESYS TON works in structured text but not ladder

    The structured text routine counts because its four statements run in sequence inside one scan; the ladder version fails when the reset network clears Timer.Q before the addition samples it, or an unconditional reset restarts the timer every cycle. Put the call, the Q test, the addition and the reset of the same TON instance in one ladder network, left to right in that order, and it counts exactly one B per interval.

    PLC programming

  • Troubleshooting

    Why only Studio 5000 programs a ControlLogix 5571

    A ControlLogix 5571 is programmed only with Studio 5000 Logix Designer (RSLogix 5000 in older releases) over an RSLinx or FactoryTalk Linx driver path. The USB port feeds that driver, not a terminal: PuTTY, minicom or picocom never reach a prompt on this VxWorks-based runtime. A controller missing from a device list means you check installed Studio 5000 revisions and the communications path first, and you flash firmware only to match an installed release's major revision — never to cure a browse fault.

    PLC programming

  • How-to

    How to run two TwinCAT PLC programs on one laptop

    Merge both PLC projects into one TwinCAT XAE system configuration and activate it once. The XAE assigns each PLC project its own ADS port (851 to the first, 852 to the next by default numbering), and both programs reach RUN on the local runtime. Changing the port in one of two separate XAE projects does not work, because one activation replaces the other.

    PLC programming