FB_HVACPIDCtrl_Ex

Universal PID controller.
The PID controller is a standard controller for heating and air conditioning applications. It can be used to control temperatures, pressures, volumetric flows or humidity. The values of Ti and Tv can be set to zero. This allows a P, PI, or PD controller characteristic to be set. The controller has an anti-reset-windup function. This prevents continuous integration in the event of a perpetual pending control deviation. In addition to FB_HVACPIDCtrl, the controller provides a slope compensation at the output.
Passive-behaviour (bEnable = FALSE or bError = TRUE)
The outputs are set in the followiog scheme:
rY | 0,0 |
rXW | 0,0 |
bMaxLimit | FALSE |
bMinLimit | FALSE |
bDecLimit | FALSE |
bIncLimit | FALSE |
bActive | FALSE |
bARWactive | FALSE |
b2Ptactive | FALSE |
In case of an error the output bError is set to TRUE - eErrorCode displays the actual errorcode. The internal values for the P-, I-, and D-part are set to "0", as well as the repective values for the previous cycle. Thus the controller can restart "clean" without any past values.
Active behavior (bEnable = TRUE and bError = FALSE)
In the first cycle, the I and D components are calculated "clean", i.e. without historical values, as already mentioned. A positive signal on bSetSyncValue sets the I-component such that the control value assumes the value rSyncValue. If bEnable and bSetSyncValue are set at the same time, this method can be used to set an initial value from which the controller "sets off". If the I-component is not active, the D-component is set accordingly. Note that only the rising edge of bSetSyncValue is evaluated internally as this is a setting action. A TRUE signal must be applied again to the input bSetSyncValue for renewed synchronization, for instance with a transfer value. If the I-component is active, then the controller ensures that this is held constant if the controller output rY should be at the limits rYMin or rYMax and attempts to fall or rise further. This procedure is referred to as Anti-Reset-Windup. It ensures that the I-component is always only just sufficiently large to enable the control value to assume values within the limit immediately after a control deviation, without having to deal with an integral component that has become too large.
Control direction
If bDirection = FALSE, the control direction of the controller is reversed so that a control deviation of less than 0 causes a change in the control value in the positive direction. This is achieved by a negative calculation of the control deviation:
bDirection | rXW (control deviation) | Control direction |
TRUE | lrX-lrW (actual value setpoint) | direct (cooling) |
FALSE | lrW-lrX (setpoint actual value) | indirect (heating) |
Anti-Reset-Windup when the maximum or minimum value is reached
If the controller reaches its upper limit at the output and the control deviation is still positive, the integral component will continue to increase, until the control deviation is less than or equal to zero again. This may lead to an unnecessarily large integral component, which would have to be reduced again, if the sign of the control deviation changes and would make the control behavior sluggish. The same applies if the minimum values is reached at the output, while the control deviation is still negative.
To prevent this in the event of leaving the control range, the I-component is set in such a way that, in addition to the P and D-components, it reaches the respective limit value lrYmin or lrYMax at the control output.
The further calculation of the P, I and D values is suspended until the sign of the control deviation allows the control range to be entered again; i.e. a control deviation of less than 0.0 when persisting at the maximum limit and or a control deviation of greater than 0.0 when persisting at the minimum limit.
In the PLC cycle of the re-entry also, the output lrY is set by manipulating the I-component so that it doesn't move erratically in the control range, but starts to change from the limit of the preceding persistence.
Slope limitation
If the controller is set faster than the actuator, it is unable to follow the controller, which can lead to jitter. It is therefore possible to limit the slope of the control value.
It is based on the following parameters:
tMinToMax: Slope limitation of controller output for increase: tMinToMax in seconds in reference to a change from rYMin to rYMax.
tMaxToMin: Slope limitation of controller output for decrease: tMaxToMin in seconds in reference to a change from rYMax to rYMin.
This can be used to calculate the maximum change per PLC cycle (maximum increment or decrement).
If the calculated change of the control signal over a PLC cycle is now higher than that set under tMinToMax or tMaxToMin, then the control signal is merely increased or decreased respectively by the maximum increment or decrement.
Internally, the I-component is automatically adjusted in the same way (I-component of last PLC cycle + maximum increment or I-component of the last PLC cycle - maximum decrement).
Deadrange
If the setpoint is finally reached, the actual value may still swing around it, which causes swinging at the control-output and constant movement at the actuator. This can be surpressed by defining a deadrange around the setpoint. If the absolute value of the control-deviation is smaller than half of the defined rDeadRange, the P- I- and D-Part will be frozen and not calculated any more until the deviation gets above 0,5*rDeadRange again.
A zero-entry at this input deactivates the deadrange.
2-point control behavior
If the control parameters Ir, rKp, tTn, tTv and tTd are set to 0.0 or t#0s, then the controller has by definition a 2-point behavior.
The dead range rDeadRange defines the hysteresis. Switching to the maximum value at the output rY fundamentally takes place when the control deviation rXW is larger than half of the hysteresis value rDeadRange, while switching to the minimum value always takes place when the control deviation rXW is smaller than the negative half of the hysteresis value rDeadRange:
The different calculation methods for the control deviation for direct and indirect control direction result in the following switching characteristics in relation to the actual value rX:
- direct control direction (cooling): Control deviation = actual value - setpoint rXW = rX - rW

- indirect control direction (heating): Control deviation = actual value - setpoint rXW = rW-rX

VAR_INPUT
eDataSecurityType : E_HVACDataSecurityType;
bSetDefault : BOOL;
bEnable : BOOL;
rW : REAL;
rX : REAL;
tTaskCycleTime : TIME;
uiCycleCall : UINT;
bSetSyncValue : BOOL;
eDataSecurityType: If eDataSecurityType:= eHVACDataSecurityType_Persistent, the persistent VAR_IN_OUT variables of the function block are stored in the flash of the computer if a value changes. For this to work, the function block FB_HVACPersistentDataHandling must be instanced once in the main program, which is called cyclically. Otherwise the instanced FB is not released internally.
A change of value can be initiated by the building management system, a local operating device or via a write access from TwinCAT. When the computer is restarted the saved data are automatically read back from the flash into the RAM.
Application example: example_persistent.zip
If eDataSecurityType:= eHVACDataSecurityType_Idle the persistently declared variables are not saved in a fail-safe manner.
Notice | |
A cyclically changing variable must never be linked with the IN_OUT variable of a function block, if eDataSecurityType:= eHVACDataSecurityType_Persistent. It would lead to early wear of the flash memory. |
bSetDefault: If the variable is TRUE, the default values of the VAR_IN_OUT variables are adopted.
bEnable: Controller activation. At the moment of activation the controller reacts directly to the control deviation without internal synchronization to a value.
rW: Setpoint
rX: Actual value
tTaskCycleTime: Cycle time with which the function block is called. If the function block is called in every cycle this corresponds to the task cycle time of the calling task.
uiCycleCall: Call cycle of the function block as a multiple of the cycle time. A zero entry is automatically interpreted as uiCycleCall=1.
Example: tTaskCycleTime = 20 ms, uiCycleCall = 10 -> the control algorithm is called every 200 ms. Thus the outputs are also updated only every 200 ms.
bSetSyncValue: The control value rY is set to the value rSyncValue (VAR_IN_OUT) on a rising edge at the input bSetSyncValue. In addition, the I-component is changed internally. If the I-component doesn't exist (PD controller), the D-component is changed.
VAR_OUTPUT
rY : REAL;
rXW : REAL;
bMaxLimit : BOOL;
bMinLimit : BOOL;
bDecLimit : BOOL;
bIncLimit : BOOL;
bActive : BOOL;
bARWactive : BOOL;
b2Ptactive : BOOL;
bError : BOOL;
eErrorCode : E_HVACErrorCodes;
rY: Control value. Range limited by rYMin and rYMax.
rXW: Control deviation (calculation dependent on control direction)
bMaxLimit: The control value has reached its upper limit value.
bMinLimit: The control value has reached its lower limit value.
bDecLimit: The control value slope has reached its limit value for the maximum decrease, see tMaxToMin (VAR_IN_OUT).
bIncLimit: The control value slope has reached its limit value for the maximum increase, see tMinToMax (VAR_IN_OUT).
bActive: The controller is active, i.e. enabled (bEnable = TRUE) and not in the error state (bError = FALSE).
bARWactive: Anti-Reset-Windup function is active.
b2Ptactive: The 2-point behavior of the controller is active.
bError: This output is switched to TRUE if the parameters entered are erroneous.
eErrorCode: Contains the command-specific error code (see E_HVACErrorCodes).
VAR_IN_OUT
rDeadRange : REAL;
rSyncValue : REAL;
bDirection : BOOL;
rKp : REAL;
tTi : TIME;
tTv : TIME;
tTd : TIME;
rYMin : REAL;
rYMax : REAL;
tMinToMax : TIME;
tMaxToMin : TIME;
rDeadRange: A dead range can be set for the control deviation in order to avoid unnecessary movement and thus premature wear in the valves or damper drives. The P-I-D calculation and thus the control output rY are "frozen" if the value of the control deviation is smaller than half of the dead range rDeadRange. The variable is saved persistently. Preset to 0.
rSyncValue: The control value rY is set to this value on a rising edge at the input bSync. In addition, the I-component is changed internally. If the I-component doesn't exist (PD controller), the D-component is changed. The variable is saved persistently. Preset to 0.
bDirection: The control direction of the controller can be changed with the parameter bDirection. If bDirection is TRUE, then the direct control direction is active for cooling operation of the controller. If bDirection is FALSE, then the indirect control direction of the controller is activated for heating operation. The variable is saved persistently. Preset to 0.
rKp: Proportional factor amplification. Only affects the P-component. The variable is saved persistently. Preset to 1.0.
tTi: Integration time [s]. The I-component corrects the residual control deviation following correction of the P-component. The smaller tTi is set, the faster the controller corrects. The control loop becomes unstable if the time is too short. Larger tTi-times must be entered in order to reduce the integration component. The integral action time should be selected to be longer than the stroke time of the valve or damper actuator. A zero value at this parameter disables the I-component. The variable is saved persistently. Preset to 30 s.
tTv: Rate time [s]. The larger tTv is, the stronger the controller corrects. The control loop becomes unstable if the time is too long. Often in normal building automation applications only a PI controller is used. A zero value at this parameter disables the D-component. The variable is saved persistently. Preset to 0 s.
tTd: Damping time [s]. The variable is saved persistently. Preset to 0 s.
rYMin / rYMax: Limit the working range of the controller. Several other function blocks, e.g. sequencers, require a symmetrical control range (-100 to +100). In the case of a cascade structure, the working range of the master controller determines the setpoint of the slave controller. For example, 15° to 25° as the limitation of the supply air setpoint for an exhaust/supply air cascade control. The variables are saved persistently. rYMin preset to 0. rYMax preset to 100.
tMinToMax: Slope limitation [s] of the controller output for increase: tMinToMax in seconds in reference to a change from rYMin to rYMax. The variable is saved persistently. Preset to 0 s.
tMaxToMin: Slope limitation [s] of the controller output for decrease: tMaxToMin in seconds in reference to a change from rYMax to rYMin. The variable is saved persistently. Preset to 0 s.
Requirements
Development environment | required library | required function |
---|---|---|
TwinCAT 3.1 build 4022.16 or higher | Tc2_HVAC V3.3.1.0 | TF8000 | TC3 HVAC V1.0.0.0 |