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_HVACTemperatureSensorEx2 is tailored to the Bus Terminals KL3201/02/04, KL3222, KL3228 and KL3208-0010. 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 or 1/100 °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, KL3222, KL3228 and KL3208-0010.
The output value rPresentValue depends on one of the following two smoothing functions:
= 0: := (( / iConversionFactor rPresentValue iRawValue 10 + ) - rPresentValueOld) / + rPresentValueOld; rOffset rSmoothFactor
= 1: := (( / iConversionFactor rPresentValue iRawValue 100 + ) - rPresentValueOld) / + rPresentValueOld; 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, KL3222, KL3228 and KL3208-0010.
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, KL3222, KL3228 and KL3208-0010 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 udiError.
Unlike FB_HVACTemperatureSensorEx, sensors with the raw temperature value 1/10 or 1/100 °C can be transferred on this function block.
VAR_INPUT
eDataSecurityType : E_HVACDataSecurityType;
bSetDefault : BOOL;
bEnable : BOOL;
iRawValue : INT;
byStatusRawValue : BYTE;
iConversionFactor : INT; 0..1
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 either in 1/10 or 1/100 °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.
iConversionFactor: conversion factor for the output value rPresentValue.
iConversionFactor = 0: rPresentValue := ((iRawValue / 10 + rOffset) - rPresentValueOld) / rSmoothFactor + rPresentValueOld;
iConversionFactor = 1: rPresentValue := ((iRawValue / 100 + rOffset) - rPresentValueOld) / rSmoothFactor + rPresentValueOld;
If a value outside its range of 0 to 1 is specified at iConversionFactor, this is signaled by bErrorConversionFactor = TRUE.
bEnableLimitCtrl: enables rHighLimit and rLowLimit for limit monitoring
bReset: acknowledgement input in the event of an error with rising edge from bReset. Depending on mode iTemperatureSensorMode, errors are acknowledged either with bReset or automatically.
VAR_OUTPUT
rPresentValue : REAL;
bErrorGeneral : BOOL;
udiError : UDINT;
bErrorSensor : BOOL;
bErrorHighLimit : BOOL;
bErrorLowLimit : BOOL;
bErrorConversionFactor: BOOL;
bInvalidParameter : BOOL;
rPresentValue: temperature output variable with two decimal places.
The value for rPresentValue is calculated and output according to the following formula:
iConversionFactor = 0: rPresentValue := ((iRawValue / 10 + rOffset) - rPresentValueOld) / rSmoothFactor + rPresentValueOld;
iConversionFactor = 1: rPresentValue := ((iRawValue / 100 + 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 corrected and bErrorSensor = FALSE, then for one PLC cycle rPresentValue = rPresentValueOld.
If bErrorSensor = TRUE, then the value of rPresentValue depends on the operation mode iTemperatureSensorMode.
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 iTemperatureSensorMode and is enabled once the error has been rectified and, depending on the operation mode iTemperatureSensorMode, acknowledged with bReset.
udiError: returns all error messages and warnings,
udiError.1 := bInvalidParameter
udiError.2 := bErrorGeneral
udiError.3 := bErrorHighLimit
udiError.4 := bErrorLowLimit
udiError.5 := bErrorShortCircuit
udiError.6 := bErrorBrokenSensor
udiError.7 := bErrorSensor
udiError.8 := bErrorConversionFactor
byError.5 := bErrorShortCircuit: error, short circuit at the connected temperature sensor. After the error has been corrected, the message is either acknowledged with bReset or automatically, depending on the operation mode iTemperatureSensorMode.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 iTemperatureSensorMode.
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 iTemperatureSensorMode. 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 iTemperatureSensorMode, 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 iTemperatureSensorMode, the warning is acknowledged either with bReset or automatically.
bErrorConversionFactor: if a value outside its range of 0 to 1 is specified at iConversionFactor, this is signaled by bErrorConversionFactor = TRUE. The message need not be acknowledged after rectifying the cause.
bInvalidParameter: indicates that an incorrect parameter is present at one of the variables rHighLimit, rLowLimit, rSmoothFactor, iConversionFactor or iTemperatureSensorMode. 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 iTemperatureSensorMode.
VAR_IN_OUT
rOffset : REAL;
rHighLimit : REAL;
rLowLimit : REAL;
rReplacementValue : REAL;
rSmoothFactor : REAL;
iTemperatureSensorMode:INT;
rOffset: temperature compensation in Kelvin. The variable is saved persistently. Preset to 0.
rHighLimit: upper limit value. The variable is saved persistently. Preset to 120.
If rPresentValue >= rHighLimit, then the output bErrorHighLimit is set. rHighLimit must be greater than rLowLimit.
If an incorrect variable value is present, 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.
rLowLimit: lower limit. The variable is saved persistently. Preset to -60.
If rPresentValue <= rLowLimit, then the output bErrorLowLimit is set.
If an incorrect variable value is present, then the last valid variable value is taken, if available. 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 iTemperatureSensorMode = 0 or iTemperatureSensorMode = 2.
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.
The value for rPresentValue is calculated and output according to the following formula:
iConversionFactor = 0: rPresentValue := ((iRawValue / 10 + rOffset) - rPresentValueOld) / rSmoothFactor + rPresentValueOld;
iConversionFactor = 1: rPresentValue := ((iRawValue / 100 + rOffset) - rPresentValueOld) / rSmoothFactor + rPresentValueOld;
rPresentValueOld is the value of rPresentValue that was output in the previous PLC cycle.
If an incorrect variable value is present at rSmoothFactor , then the last valid variable value is taken, if available. If there is no valid last value, then the default value is used. bInvalidParameter is set if the parameter is incorrect.
iTemperatureSensorMode: specifies the operation mode of the function block.
iTemperatureSensorMode = 0: 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.
iTemperatureSensorMode = 1: 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.
iTemperatureSensorMode = 2: if bErrorShortCircuit or bErrorBrokenSensor = TRUE, then rPresentValue = rReplacementValue. After the error has been corrected, the function block acknowledges itself automatically.
iTemperatureSensorMode = 3: 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 iTemperatureSensorMode, the default value is used. bInvalidParameter is set if the parameter is incorrect.
The variable is saved persistently. Preset to 3%.