IAE Academy

FOR CORE AND IT JOBS · CHAPTER 5 OF 7

Analog control and PID in a PLC

A PLC can hold a process variable at a set point by running a PID (proportional-integral-derivative) calculation every sample. This chapter shows how that calculation is built, how to tune it from a step test, and how a tank level loop is scaled, limited and alarmed.

Updated 30 Oct 2026

What you will be able to do

You will be able to describe a closed loop built around a PLC and choose a reverse or direct acting controller. You will compute one PID output by hand, as the PLC does each sample. You will tune a loop from step-test data and set up a tank level loop with scaling, output limits and alarms.

Before you start

  1. Chapter 4, Timers, counters and sequences

  2. The PLC scan cycle: read inputs, run the program, write outputs

  3. Ladder contacts, coils and a latch held by a parallel contact

  4. Feedback control: proportional, integral and derivative action

  5. Straight-line graphs and slope

  6. Area under a curve as a sum of thin strips

  7. Derivative as a rate of change

  8. Boolean AND, OR and NOT

The loop and the PID calculation

A closed loop has three parts. A sensor measures the process variable (PV), such as a tank level, and sends it as a 4-20 mA current: 4 mA at the bottom of its measuring range, the span, and 20 mA at the top. The controller, here the PLC, compares PV with the set point (SP) and computes an output for a final control element, usually a valve. It does this every sample time , usually in a timed task rather than each scan, so that stays constant.

Recap from control theory. Proportional action acts on the error, the gap between SP and PV, now; alone it leaves a steady offset. Integral action keeps adding while any error remains, so it removes the offset. Derivative action reacts to how fast the error changes, so it brakes an approaching overshoot.

ERROR WITH ACTING DIRECTION

Computed every sample, with SP and PV in per cent of span. : reverse acting (output rises when PV falls). : direct acting (output rises when PV rises).

Choose the direction from the plant. With a valve that opens as the output rises: on a tank's inlet, a falling level needs more inflow (reverse acting); on its outlet, a rising level needs more outflow (direct acting). The wrong choice drives the error away and the tank runs over or empty.

IDEAL PID LAW

Holds while stays inside the valve's range, with ( sets the direction). : output (%); : gain (% per %); : integral time (s); : derivative time (s); : time inside the integral (s).

PID AS THE PLC COMPUTES IT

Holds when is small against the loop's response time; at the first sample take . , : error and output at sample (%); : sample time (s). The sum is the integral as strips of width ; the one-sample difference is the derivative.

Tuning from a reaction curve

To tune without a model, use the Ziegler-Nichols reaction-curve method. Put the controller in manual (you set the output by hand; the loop is open) and step the output by . Record PV until it settles, a change of . Draw the tangent at the steepest point of the S-shaped curve. The delay runs from the step to where the tangent meets the starting level; is the time the tangent takes to climb to the final level.

PROCESS GAIN FROM THE STEP TEST

Holds for a self-regulating process, one that settles at a new steady value. : change in PV (% of span); : output step (%); has no unit.

The rule below gives starting settings, with and in seconds. It is empirical and suits S-shaped responses with well below . "Off" means the action is not used ( infinite, zero).

Controller

Kp

Ti

Td

P

τ / (K L)

off

off

PI

0.9 τ / (K L)

3.33 L

off

PID

1.2 τ / (K L)

2 L

0.5 L

WATCH OUT FOR

Measuring from the start of the rise. Test: counts from the instant you changed the output.

WORKED EXAMPLE

Tank 1 drains into tank 2, which drains through a fixed orifice. You control tank 2's level with tank 1's inlet valve. In manual, the valve output is stepped from 40 % to 50 %. The level rises along an S-shaped curve from 20 % to 36 % of span and settles. The tangent gives s and s. Find PID settings.

Solution
  1. % and %, so , because the rule needs the plant's gain, not the controller's.

  2. A PID controller is wanted, so use the PID row: .

  3. s, because the rule ties the integral time to the delay before any correction shows in PV.

  4. s, from the same row.

Answer: , s, s, as a starting point: lower or raise if the response overshoots badly.

A tank level loop in the PLC

Here the PLC holds a tank's level. Addresses are in IEC style (%I0.0 an input bit, %Q0.0 an output bit, %M0.0 a memory bit); some PLC families write them differently. %IW0 and %QW0 are analog input and output words, %MD10 a memory double word.

  1. Level transmitter: spans 0 to 2 m and sends 4-20 mA to %IW0, which a common input module reads as a count from 0 (4 mA) to 27648 (20 mA); check yours.

  2. PLC: scales to the level (m) in %MD10. The PID uses PV (% of span). Its output , limited to 0-100 %, goes to %QW0 as the count , which the output module turns into mA.

  3. Inlet valve: opens further as the current from %QW0 rises, so the controller is reverse acting ().

  4. Outlet: a fixed orifice, so outflow rises with level.

  5. Alarm lamps: high on %Q0.0, low on %Q0.1.

SCALING A COUNT TO A LEVEL

Holds for a linear transmitter: a straight line through and . : raw count; : level (m). Here m at and m at .

OUTPUT LIMIT AND INTEGRAL HOLD

Holds with , so a positive raises . , % (valve travel). While and , or and , skip adding to the sum; otherwise the sum grows (integral windup) and holds the output at its limit after the error changes sign.

Alarms use hysteresis so they do not chatter when the level hovers at a limit: the high alarm comes on at 1.6 m and clears below 1.55 m; the low alarm comes on at 0.4 m and clears above 0.45 m. In each rung the coil's own contact, parallel to the first compare contact, holds the alarm on until the second one opens.

Rung

Element

Type

Address

Meaning

1

h ≥ 1.6 m

compare contact

%MD10

closes at the high limit

1

high alarm (parallel)

contact

%Q0.0

holds the alarm on

1

h ≥ 1.55 m

compare contact

%MD10

opens below the clear value

1

high alarm

coil

%Q0.0

high alarm lamp

2

h ≤ 0.4 m

compare contact

%MD10

closes at the low limit

2

low alarm (parallel)

contact

%Q0.1

holds the alarm on

2

h ≤ 0.45 m

compare contact

%MD10

opens above the clear value

2

low alarm

coil

%Q0.1

low alarm lamp

HIGH AND LOW ALARMS WITH HYSTERESIS

Holds each scan, with in metres (%MD10). A bracket is 1 while its comparison is true; + is OR, · is AND. is %Q0.0 (rung 1), is %Q0.1 (rung 2); on the right they are the previous scan's values.

WORKED EXAMPLE

In the loop above, the input word reads 20736. Find the level, the PV the PID sees, and the current.

Solution
  1. Fraction of span , since the line starts at 0 counts for 0 m.

  2. So m and PV %, because the PID works in per cent of span.

  3. Current mA, because the same fraction applies to the 16 mA above 4 mA.

Answer: m, PV %, 16 mA. 1.5 m is below 1.55 m and above 0.45 m, so both alarms are off whatever their last state.

Check yourself

CHECK YOURSELF 1

A PLC controls the level of a tank by moving a valve on the inlet pipe. The valve opens further as the controller output rises. Which acting direction does the controller need?

  1. (A)

    Reverse acting: the output rises when the level falls

  2. (B)

    Direct acting: the output rises when the level rises

  3. (C)

    Either, because the integral action corrects the sign

  4. (D)

    Neither, because a level loop needs no feedback

Answer and solution

Answer: (A)

  1. A falling level needs more inflow.

  2. So the inlet valve must open more when PV falls.

  3. That is reverse acting.

CHECK YOURSELF 2

A level transmitter spans 0 to 2 m and gives 4 to 20 mA. The PLC input module returns 0 to 27648 counts over that current range. A reading of 6912 counts corresponds to what level, in metres?

Answer and solution

Answer: (accepted range )

  1. Fraction of span .

  2. Level m.

CHECK YOURSELF 3

A PLC runs with , s, s and s. The errors at samples 0, 1 and 2 are 6 %, 5 % and 4 %, and no output limit is reached. Find in per cent.

Answer and solution

Answer: (accepted range )

  1. Sum %, so the integral term is %.

  2. Derivative term %.

  3. %.

CHECK YOURSELF 4One or more options are correct

For the PLC's discrete PID with positive , , and , and no output limit reached, which statements are correct?

  1. (A)

    With a constant nonzero error, the integral term grows in size at every sample

  2. (B)

    The derivative term is zero when the error is the same at two successive samples

  3. (C)

    Halving halves the integral term

  4. (D)

    The proportional term alone always brings a constant error to zero

Answer and solution

Answer: (A), (B)

  1. A is true: the sum gains the same each sample, so the term's size grows.

  2. B is true: .

  3. C is false: divides the sum, so halving it doubles the term.

  4. D is false: proportional action alone leaves an offset.

Used in these GATE topics