FB_HVACMUX_INT_16

FB_HVACMUX_INT_16 1:

Application

Application

This function block contains two different types of multiplexers, one each for the operation modes eHVACCtrlMode_Auto or eHVACCtrlMode_Manual. This selection is made with the help of the enum eCtrlMode.
The following conditions must be met in advance:

bEnable = TRUEANDbError = FALSE

If eCtrlMode = eHVACCtrlMode_Auto, the variable bDirection determines whether the output variable iValueNumber is incremented or decremented when using the input bEdgeNewValue. If bDirection = FALSE it is incremented, if bDirection = TRUE it is decremented.

If eCtrlMode = eHVACCtrlMode_Manual, the output iValueNumber is determined by the variable iManualValue. The variables iNumberOfValues, bEdgeNewValue and bDirection are not taken into account in this operation mode.

The output iValueNumber always indicates the number of the variable iValueX, whose content is output in the output variable iValueOut.

Examples of eCtrlMode = eHVACCtrlMode_Auto

- If bDirection = FALSEAND iNumberOfValues = 12 and there is a rising edge on bEdgeNewValue, then iValueNumber increments. If iValueNumber = 6, then iValueOut = iValue6. If iValueNumber= iNumberOfValues(12) and there is a rising edge on bEdgeNewValue, then iValueNumber = 1 and hence iValueOut = iValue1.

- If bDirection = TRUEANDiNumberOfValues = 8 and there is a rising edge on bEdgeNewValue, then iValueNumber decrements. If iValueNumber = 5, then iValueOut = iValue5. If iValueNumber= 1 and there is a rising edge on bEdgeNewValue, then iValueNumber = iNumberOfValues(8) and hence iValueOut = iValue8.

The start behavior of the outputs iValueNumber and iValueOut is as follows:

- If bDirection = FALSEANDiNumberOfValues > 0, then iValueNumber = 1 and hence iValueOut = iValue1.

- If bDirection = TRUEANDiNumberOfValues = 12, then iNumberOfValues = 12 and hence iValueOut = iValue12.

Examples of eCtrlMode = eHVACCtrlMode_Manual

- The value of iValueNumber is determined by iManualValue. If iManualValue = 7, then iValueNumber = 7, which then means that iValueOut = iValue7.

The start behavior of the outputs iValueNumber and iValueOut is as follows:

- If iManualValue = 13, then iValueNumber = 13 and hence iValueOut = iValue13.

- If iManualValue = 0, then iValueNumber = 0 and hence iValueOut = 0.

Notice

A frequently changing variable may not be applied to the VAR_IN_OUT variables iValue1-16 if eDataSecurityType = eHVACDataSecurityType_Persistent. This would lead to premature wear of the storage medium of the controller. If the VAR_IN_OUT variables iValue1-16 change frequently and are not to be stored persistently, then eDataSecurityType must be eDataSecurityType_Idle.

Application example

Download

Required library

TcHVAC.pro

TcHVAC.lib

VAR_INPUT

eDataSecurityType : E_HVACDataSecurityType;
bEnable           : BOOL;
iNumberOfValues   : INT;              1..16
bEdgeNewValue     : BOOL;
bDirection        : BOOL;
eCtrlMode         : E_HVACCtrlMode;
iManualValue      : INT;              0..16

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: FB_HVACMUX_INT_16 2: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.

bEnable: the function block is enabled via TRUE. If bEnable = FALSE, then iValueOut and iValueNumber are set constantly to 0.

iNumberOfValues: indicates the number of variables iValue1-16 that can be output via iValueOut. If iNumberOfValues = 8, the output iValueNumber moves between 1 and 8. Then for the output iValueOut the variables iValue1 to iValue8 are taken into account, see Application
iNumberOfValues
determines the start behavior of the outputs iValueOut and iValueNumber, see Application
iNumberOfValues
is not taken into account in the operation mode eCtrlMode = eHVACCtrlMode_Manual.
iNumberOfValues must not fall below 1 and must not exceed 16. Otherwise an error is indicated by bError = TRUE and the execution of the function block is stopped.

bEdgeNewValue: if there is a rising edge at bEdgeNewValue, then iValueNumber increments or decrements.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_AutoANDbDirection = FALSEANDiNumberOfValues > 0 and there is a rising edge at bEdgeNewValue, then iValueNumber increments. If iValueNumber = 6, then iValueOut = iValue6. If iValueNumber= iNumberOfValues and there is a rising edge at bEdgeNewValue, then iValueNumber = 1 and thusiValueOut = iValue1.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_AutoANDbDirection = TRUEANDiNumberOfValues = 12 and there is a rising edge at bEdgeNewValue, then iValueNumber decrements. If iValueNumber = 5, then iValueOut = iValue5. If iValueNumber= 1 and there is a rising edge at bEdgeNewValue, then iValueNumber = iNumberOfValues(12) and thus iValueOut = iValue12.
bEdgeNewValue
is not taken into account in the operation mode eCtrlMode = eHVACCtrlMode_Manual.

bDirection: bDirection determines the control direction of the function block.
bDirection
= FALSE means that iValueNumber increments in ascending order from 1 to iNumberOfValues and thereby determines the output value iValueOut see Application
bDirection
= TRUE means, that iValueNumber decrements in decreasing order from iNumberOfValues to 1 and thereby determines the output value iValueOut, see Application
bDirection is not taken into account in the operation mode eCtrlMode = eHVACCtrlMode_Manual.

eCtrlMode: the operation mode of the function block is specified by means of the enum, see Application
If the operation mode is eCtrlMode = eHVACCtrlMode_Auto, the variable iManualValue is not taken into account.
If the operation mode is eCtrlMode = eHVACCtrlMode_Manual, then the variables iNumberOfValues, bEdgeNewValue and bDirection are not taken into account.

iManualValue: if the operation mode eCtrlMode = eHVACCtrlMode_ManualANDbEnable = TRUEANDbError = FALSEANDiManualValue = 15, then iValueNumber = 15. The content of the variable iValue15 is then output via iValueOut, see Application.
iManualValue is only taken into account in the operation mode eCtrlMode = eHVACCtrlMode_Manual. The value of iValueNumber is determined by iManualValue. iManualValue should be in the range of 0 and 16. If iManualValue falls below the value 0, then 0 is output via iValueNumber. If iManualValue exceeds the value 16, then 16 is output via iValueNumber. If iManualValue = 0, then iValueNumber = 0 and hence iValueOut = 0.

VAR_OUTPUT

iValueOut           : INT;
bActive             : BOOL;
bEdgeNewValueOut    : BOOL;
iValueNumber        : INT;
bError              : BOOL;
eErrorCode          : E_HVACErrorCodes;

iValueOut: the value of the variable iValue1-16 is output via iValueOut.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_AutoANDbDirection = FALSEANDiNumberOfValues > 0 and there is a rising edge at bEdgeNewValue, then iValueNumber increments. If iValueNumber = 6, then iValueOut = iValue6. If iValueNumber= iNumberOfValues and there is a rising edge at bEdgeNewValue, then iValueNumber = 1 and thusiValueOut = iValue1.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_AutoANDbDirection = TRUEANDiNumberOfValues = 12 and there is a rising edge at bEdgeNewValue, then iValueNumber decrements. If iValueNumber = 5, then iValueOut = iValue5. If iValueNumber= 1 and there is a rising edge at bEdgeNewValue, then iValueNumber = iNumberOfValues(12) and thus iValueOut = iValue12.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_Manual, then the value of iValueNumber is determined by iManualValue. If iManualValue = 7, then iValueNumber = 7, which then means that iValueOut = iValue7.

The start behavior of the output iValueOut looks like this, if bEnable = TRUEANDbError = FALSEAND

- eCtrlMode = eHVACCtrlMode_AutoANDbDirection = FALSEANDiNumberOfValues > 0, so iValueNumber = 1 and iValueOut = iValue1.

- eCtrlMode = eHVACCtrlMode_AutoANDbDirection = TRUEANDiNumberOfValues = 12, so iNumberOfValues = 12 and iValueOut = iValue12.

- eCtrlMode = eHVACCtrlMode_ManualANDiManualValue = 13, so iValueNumber = 13 and iValueOut = iValue13.

- eCtrlMode = eHVACCtrlMode_ManualANDiManualValue = 0, so iValueNumber = 0 and iValueOut = 0.

bActive: bActive becomes TRUE , if

1. bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_Auto.

2. bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_ManualANDiManualValue > 0.

bEdgeNewValueOut: is TRUE for one PLC cycle if bEnable = TRUEANDbError = FALSEANDiValueNumber changes its value.

iValueNumber: the output iValueNumber always indicates the number of the variable iValueX, whose content is output in the output variable iValueOut.
If eCtrlMode = eHVACCtrlMode_Auto the variable bDirection determines whether the output variable iValueNumber is incremented or decremented when using the input bEdgeNewValue. If bDirection = FALSE it is incremented, if bDirection = TRUE it is decremented.
If eCtrlMode = eHVACCtrlMode_Manual the value of iValueNumber is determined by iManualValue.

bError: the output signals with a TRUE that an error is present and an incorrect parameter is present at the variable iNumberOfValues. iValueOut and iValueNumber are constantly set to 0 and the enum eErrorCode indicates the error number. The message bError does not have to be acknowledged after rectification of the error.

eErrorCode: returns the error number when the bError output is set. The following error can occur in this function block:

eHVACErrorCodes_InvalidParam_iNumberOfValues: there is an incorrect value at iNumberOfValues. iNumberOfValues must not fall below 1 and not exceed 16.

FB_HVACMUX_INT_16 3:

To access the enum error numbers in the PLC, eErrorCode can be assigned to a variable of the data type WORD. eHVACErrorCodes_InvalidParam_iNumberOfValues = 42

VAR_IN_OUT

iValue1-16        : INT;           

iValue1-16: the value of the output variable iValueOut is determined by the variables iValue1 to iValue16. If iValueNumber = 6, then iValueOut = iValue6.
If iNumberOfValues = 8, the output iValueNumber moves between 1 and 8. The variables iValue1 to iValue8 are then taken into account for the output iValueOut if the operation mode is eCtrlMode = eHVACCtrlMode_Auto, see Application