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 T, usually in a timed task rather than each scan, so that T 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.
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.
PID AS THE PLC COMPUTES IT
uk=Kp[ek+TiTj=0∑kej+TTd(ek−ek−1)]
Holds when T is small against the loop's response time; at the first sample take e−1=e0. ek, uk: error and output at sample k (%); T: sample time (s). The sum is the integral as strips of width T; the one-sample difference is the derivative.