FB_HVACTemperatureSensorEx
Application
This function block is used for the acquisition and subsequent processing of temperature values, e.g. for the sensor types PT100, PT200, PT1000, NI100, NI120, NI1000, NI1000Tk5000. The function block FB_HVACTemperatureSensorEx is tailored to the Bus Terminals KL3201/02/04 and KL3228. These Bus Terminals can either be ordered preconfigured or set to the corresponding sensor types by software.
The raw temperature value is transferred to the function block in 1/10 °C via the input variable iRawValue and output as a floating point number via rPresentValue.iRawValue can, for example, be linked directly to the raw temperature value of the following Bus Terminals: KL3201/02/04 and KL3228.
The output value rPresentValue depends on the following smoothing function:
:= (( / 10 + ) - rPresentValueOld) / + rPresentValueOld; rPresentValue iRawValue rOffset rSmoothFactor
rPresentValueOld is the value of rPresentValue that was output in the previous PLC cycle. If bEnable goes TRUE, then rPresentValue = rPresentValueOld for one PLC cycle. If bErrorSensor = TRUE, the error has been corrected and bErrorSensor = FALSE, then rPresentValue = rPresentValueOld for one PLC cycle.
The status of the connected temperature sensor is monitored via the input variable byStatusRawValue and returned to the controller via the variable bErrorSensor in the event of an error. byStatusRawValue can, for example, be linked directly to the status byte of the following Bus Terminals: KL3201/02/04 and KL3228.
rHighLimit/rLowLimit can be used to specify temperature limit values.
Unlike FB_HVACTemperatureSensor, this function block has the input variable bEnable, which is useful when the sensor characteristic curves in the Bus Terminals KL3201/02/04 and KL3228 are to be adjusted from the PLC via the function block FB_HVACConfigureKL32xx. In this function block the second order filter in FB_HVACTemperatureSensor is replaced by the smoothing function described above. The output bErrorSensor is new and replaces the two outputs bErrorShortCircuit/bErrorBrokenSensor. These outputs continue to be available in the error byte byError.
VAR_INPUT
eDataSecurityType : E_HVACDataSecurityType;
bSetDefault : BOOL;
bEnable : BOOL;
iRawValue : INT;
byStatusRawValue : BYTE;
bEnableLimitCtrl : BOOL;
bReset : 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: the function block is enabled if bEnable = TRUE. If bEnable = FALSE, the value of rReplacementValue is output at the rPresentValue output. All error messages and bInvalidParameter are set to FALSE. If bEnable goes TRUE, then rPresentValue = rPresentValueOld for one PLC cycle.
iRawValue: raw value of the temperature sensor in 1/10 °C from the Bus Terminal.
byStatusRawValue: status byte of the temperature sensor from the Bus Terminal. Serves for error diagnosis, e.g. wire break or short circuit. If the KL32xx is set to resistance measurement (Ω) there is no error diagnosis.
bEnableLimitCtrl: enables rHighLimit and rLowLimit for limit monitoring
bReset: acknowledgement input in the event of an error with rising edge from bReset. Depending on operation mode eTemperatureSensorMode, errors are acknowledged either with bReset or automatically.
VAR_OUTPUT
rPresentValue : REAL;
bErrorGeneral : BOOL;
byError : BYTE;
bErrorSensor : BOOL;
bErrorHighLimit : BOOL;
bErrorLowLimit : BOOL;
bInvalidParameter : BOOL;
rPresentValue: temperature output variable with one decimal place.
The value for rPresentValue is calculated and output according to the following formula:
rPresentValue := ((iRawValue / 10 + rOffset) - rPresentValueOld) / rSmoothFactor + rPresentValueOld;
rPresentValueOld is the value of rPresentValue that was output in the previous PLC cycle. If bEnable goes TRUE, then rPresentValue = rPresentValueOld for one PLC cycle. If bErrorSensor = TRUE, the error is rectified and bErrorSensor = FALSE, then for one PLC cycle rPresentValue = rPresentValueOld.
If bErrorSensor = TRUE, then the value of rPresentValue depends on the operation mode eTemperatureSensorMode.
bErrorGeneral: the error message bErrorGeneral becomes TRUE as soon as one of the error messages bErrorHighLimit, bErrorLowLimit or bErrorSensor = = TRUE. The value of the output variable rPresentValue is then dependent on the operation mode eTemperatureSensorMode and is enabled once the error has been rectified and, depending on the operation mode eTemperatureSensorMode, acknowledged with bReset.
byError: returns all error messages and warnings,
byError.1 := bInvalidParameter
byError.2 := bErrorGeneral
byError.3 := bErrorHighLimit
byError.4 := bErrorLowLimit
byError.5 := bErrorShortCircuit
byError.6 := bErrorBrokenSensor
byError.7 := bErrorSensor
byError.5 := bErrorShortCircuit: error, short circuit at the connected temperature sensor. After the error has been rectified, the message is either acknowledged with bReset or automatically, depending on the operation mode eTemperatureSensorMode.
byError.6 := bErrorBrokenSensor:error, wire break at the connected temperature sensor. Once the fault has been corrected, the message is acknowledged either with bReset or automatically, depending on mode eTemperatureSensorMode.
bErrorSensor: becomes TRUE, if byError.5/bErrorShortCircuit or byError.6/bErrorBrokenSensor = TRUE. Once the fault has been corrected, the message is acknowledged either with bReset or automatically, depending on mode eTemperatureSensorMode. If bErrorSensor = TRUE, the error has been corrected and bErrorSensor = FALSE, then rPresentValue = rPresentValueOld for one PLC cycle.
bErrorHighLimit: warning upper limit value exceeded; becomes TRUE if rPresentValue >= rHighLimit. The warning that the upper limit value has been exceeded can only be acknowledged if rPresentValue <= rHighLimit - 1.0 for a time duration of 5 seconds. Depending on mode eTemperatureSensorMode, the warning is acknowledged either with bReset or automatically.
bErrorLowLimit: warning lower limit value undershot; becomes TRUE if rPresentValue <= rLowLimit. The warning that the lower limit value has been undershot can only be acknowledged if rPresentValue >= rLowLimit + 1.0 for a time duration of 5 seconds. Depending on mode eTemperatureSensorMode, the warning is acknowledged either with bReset or automatically.
bInvalidParameter: indicates that an incorrect parameter is present at one of the variables rHighLimit, rLowLimit, rSmoothFactor or eTemperatureSensorMode. An incorrect parameter specification does not lead to a standstill of the function block; see description of variables. Once the incorrect parameter specification has been corrected, the message bInvalidParameter is acknowledged either with bReset or automatically, depending on mode eTemperatureSensorMode.
VAR_IN_OUT
rOffset : REAL;
rHighLimit : REAL;
rLowLimit : REAL;
rReplacementValue : REAL;
rSmoothFactor : REAL;
eTemperatureSensorMode: E_HVACTemperatureSensorMode;
rOffset: temperature compensation in Kelvin, rPresentValue = (iRawValue / 10.0) + rOffset. The variable is saved persistently. Preset to 0.
rHighLimit: upper limit value. If rPresentValue >= rHighLimit, then the output bErrorHighLimit is set. rHighLimit must be greater than rLowLimit. The variable is saved persistently. Preset to 120.
If an incorrect variable value is present, the last valid variable value, if available, is used. If there is no valid last value, then the default value is used. bInvalidParameter is set if the parameter is incorrect.
rLowLimit: lower limit. The output bErrorLowLimit is set if rPresentValue <= rLowLimit. The variable is saved persistently. Preset to -60.
If an incorrect variable value is present, the last valid variable value, if available, is used. If there is no valid last value, then the default value is used. bInvalidParameter is set if the parameter is incorrect.
rReplacementValue: replacement value that is output at rPresentValue in the case of the errors bErrorShortCircuit and bErrorBrokenSensor, if the selected operation mode eTemperatureSensorMode = eHVACTemperatureSensorMode_ReplacementValue or eTemperatureSensorMode = eHVACTemperatureSensorMode_AutoResetReplacementValue. The variable is saved persistently. Preset to 0.
rSmoothFactor: smoothing factor (>=1) for the output value rPresentValue. The variable is saved persistently. Preset to 100.
According to the following formula the value for rPresentValue is calculated and output:
rPresentValue := ((iRawValue / 10 + rOffset) - rPresentValueOld) / rSmoothFactor + rPresentValueOld;
rPresentValueOld is the value of rPresentValue, which was output one PLC cycle before.
If rSmoothFactor = 1, then rPresentValue:= ((iRawValue / 10 + rOffset)
If there is an incorrect variable value at rSmoothFactor, then the last valid variable value is used, if available. If there is no valid last value, then the default value is used. bInvalidParameter is set if the parameter is incorrect.
eTemperatureSensorMode: Enum, via which the operation mode of the function block is specified.
eTemperatureSensorMode = eHVACTemperatureSensorMode_ReplacementValue: if bErrorSensor = TRUE, then rPresentValue = rReplacementValue. After the error has been corrected, the function block must be acknowledged by a rising edge at the input variable bReset.
eTemperatureSensorMode = eHVACTemperatureSensorMode_LastValue: if bErrorSensor = TRUE, then the last valid temperature value that was present 10 seconds before is output at the output variable rPresentValue. After the error has been corrected, it must be acknowledged by a rising edge at the input variable bReset.
eTemperatureSensorMode = eHVACTemperatureSensorMode_AutoResetReplacementValue: if bErrorShortCircuit or bErrorBrokenSensor = TRUE, then rPresentValue = rReplacementValue. After the error has been corrected, the function block acknowledges itself automatically.
eTemperatureSensorMode = eHVACTemperatureSensorMode_AutoResetLastValue: if bErrorSensor = TRUE, then the last valid temperature value that was present 10 seconds before is output at the output variable rPresentValue. After the error has been corrected, the function block acknowledges itself automatically.
If there is an incorrect variable value at eTemperatureSensorMode, the default value is used. bInvalidParameter is set if an incorrect parameter is specified.
The variable is saved persistently. Preset to 3%.