FB_PID (Function Block)
Ideal-form PID controller with clamped output, comparator-based anti-windup, and bumpless manual-to-auto transfer.
The control output is computed as:
where \(e(t) = SP - PV\) is the error, \(-y\) is the negated process variable (derivative on measurement, avoiding derivative kick on setpoint steps).
In Manual mode the output tracks Setpoint directly
through the output clamp. The integrator is continuously primed so that
switching to Auto produces no jump in output.
Note
Set Maximum before Minimum to ensure the clamp guard applies
correctly. The same applies to IntegratorBounds.
Use FB_init to set fKp, tTn, tTv and tTd,
fMaximum, and fMinimum at declaration time.
Extends: FB_SoComponent
Properties
AntiWindupActive
Type: BOOL
Gets whether the integrator is currently saturated and integration is halted or disabled.
AntiWindupMode
Type: E_AntiWindupMode
Gets or sets the anti-windup mode for the integrator.
See E_AntiWindupMode for available modes.
DerivativeTerm
Type: LREAL
Gets the contribution of the derivative term to the output.
Enable
Type: BOOL
Gets or sets whether the controller is active.
When FALSE all internal components are reset and the output is held at zero.
The controller resumes from a clean state when re-enabled. Defaults to TRUE.
Error
Type: LREAL
Gets the current error (Setpoint - Feedback, SP - PV).
Feedback
Type: LREAL
Gets or sets the process variable (PV).
Used to compute the error and the derivative on measurement.
IntegralTerm
Type: LREAL
Gets the contribution of the integral term to the output.
IntegratorBounds
Type: I_Bounded
Gets the integrator bounds interface.
Use this to set independent upper and lower limits on the integrator output, separate from the output clamp. This is useful when you want tighter integrator limits than the output clamp.
Kp
Type: LREAL
Gets or sets the proportional gain (Kp).
Scales the response to the current error. A higher value reacts more strongly to error but risks overshoot and oscillation. A value of 0 disables the P term.
Maximum
Type: LREAL
Gets or sets the upper output clamp.
Internally clamped to be greater than or equal to Minimum.
Set this before Minimum to ensure the guard applies correctly.
Minimum
Type: LREAL
Gets or sets the lower output clamp.
Internally clamped to be less than or equal to Maximum.
Set Maximum before this property to ensure the guard applies correctly.
Mode
Type: E_ControllerMode
Gets or sets the operating mode.
In Auto mode the output is computed from Setpoint and
Feedback. In Manual mode the output tracks
Setpoint directly through the output clamp. The integrator is continuously
primed in manual mode so switching to auto produces no jump in output.
ProportionalTerm
Type: LREAL
Gets the contribution of the proportional term to the output.
Setpoint
Type: LREAL
Gets or sets the setpoint.
In Manual mode this is used as
the manual output value, routed directly through the output clamp.
Td
Type: LTIME
Gets or sets the derivative damping time (Td).
Filters the derivative signal to reduce sensitivity to measurement noise.
A longer value gives more filtering but weakens derivative action. LTIME#0
removes the filter entirely, not recommended when the measurement is noisy.
Tn
Type: LTIME
Gets or sets the integral action time (Tn).
Controls how quickly accumulated error is corrected. A shorter value eliminates
steady-state error, faster but risks overshoot. A longer value is more stable but
slower to correct. LTIME#0 disables the I term entirely.
Tv
Type: LTIME
Gets or sets the derivative action time (Tv).
Controls how strongly the controller reacts to changes in the process variable (Feedback).
A longer value dampens sudden changes and reduces overshoot, but too much can
cause instability. LTIME#0 disables the D term entirely.
Methods
FB_init
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
if TRUE, the retain variables are initialized (warm start / cold start) |
|
|
if TRUE, the instance afterwards gets moved into the copy code (online change) |
|
|
Proportional gain. |
|
|
Integral action time. LTIME#0 disables the I term. |
|
|
Rate time. LTIME#0 disables the D term. |
|
|
Derivative damping time. |
|
|
Upper output clamp. |
|
|
Lower output clamp. |
Run
Advances the PID controller by one time step.
Note
Must be called once per cycle on a single PLC task.
SyncOutput
Sets the controller output to a given value on the next Run() call.
The integrator is back-calculated from the current P and D terms so the
three terms add up to fValue. Use it to start from a known operating
point instead of from zero.
Note
Does nothing if Tn is LTIME#0, or in
Manual mode, where the output already follows
Setpoint. If IntegratorBounds cuts the integrator short,
the output stops below the target.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Target controller output. |
SyncTn
Presets the integrator state to match a given output value on the next Run() call.
Use this when switching from manual to automatic mode with a known starting output, or when initialising the controller to a steady-state value to avoid an initial transient.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Target integrator state. |