FB_HVACMUX_REAL_16

FB_HVACMUX_REAL_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 rValueX, whose content is output in the output variable rValueOut.

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 rValueOut = rValue6. If iValueNumber= iNumberOfValues(12) and there is a rising edge on bEdgeNewValue, then iValueNumber = 1 and thus rValueOut = rValue1.

- If bDirection = TRUEANDiNumberOfValues = 8 and there is a rising edge on bEdgeNewValue, then iValueNumber decrements. If rValueNumber = 5, then rValueOut = rValue5. If iValueNumber= 1 and there is a rising edge on bEdgeNewValue, then iValueNumber = iNumberOfValues(8) and thus rValueOut = rValue8.

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

- If bDirection = FALSEANDiNumberOfValues > 0, then iValueNumber = 1 and hence rValueOut = rValue1.

- If bDirection = TRUEANDiNumberOfValues = 12, then iNumberOfValues = 12 and hence rValueOut = rValue12.

Examples of eCtrlMode = eHVACCtrlMode_Manual

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

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

- If iManualValue = 13, then iValueNumber = 13 and rValueOut = rValue13.

- If iManualValue = 0, then iValueNumber = 0 and rValueOut = 0.

Notice

A frequently changing variable may not be applied to the VAR_IN_OUT variables rValue1-16 if eDataSecurityType = eHVACDataSecurityType_Persistent. This would lead to premature wear of the storage medium of the controller. If the VAR_IN_OUT variables rValue1-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_REAL_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 rValueOut and iValueNumber are set constantly to 0.

iNumberOfValues: indicates the number of variables rValue1-16 that can be output via rValueOut. If iNumberOfValues = 8, the output iValueNumber moves between 1 and 8. The variables rValue1 to rValue8 are then taken into account for the output rValueOut, see Application
iNumberOfValues
determines the start behavior of the outputs rValueOut 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 rValueOut = rValue6. If iValueNumber= iNumberOfValues and there is a rising edge at bEdgeNewValue, then iValueNumber = 1 and thus rValueOut = rValue1.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_AutoANDbDirection = TRUEANDiNumberOfValues = 12 and there is a rising edge at bEdgeNewValue, then iValueNumber decrements. If iValueNumber = 5, then rValueOut = rValue5. If iValueNumber= 1 and there is a rising edge at bEdgeNewValue, then iValueNumber = iNumberOfValues(12) and thus rValueOut = rValue12.
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 rValueOut see Application
bDirection
= TRUE means, that iValueNumber decrements in decreasing order from iNumberOfValues to 1 and thereby determines the output value rValueOut, 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 rValue15 is then output via rValueOut, 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 rValueOut = 0.

VAR_OUTPUT

rValueOut          : REAL;
bActive            : BOOL;
bEdgeNewValueOut   : BOOL;
iValueNumber       : INT;
bError             : BOOL;
eErrorCode         : E_HVACErrorCodes;

rValueOut: the value of the variable rValue1-16 is output via rValueOut.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_AutoANDbDirection = FALSEANDiNumberOfValues > 0 and there is a rising edge at bEdgeNewValue, then iValueNumber increments. If iValueNumber = 6, then rValueOut = rValue6. If iValueNumber= iNumberOfValues and there is a rising edge at bEdgeNewValue, then iValueNumber = 1 and thus rValueOut = rValue1.
If bEnable = TRUEANDbError = FALSEANDeCtrlMode = eHVACCtrlMode_AutoANDbDirection = TRUEANDiNumberOfValues = 12 and there is a rising edge at bEdgeNewValue, then iValueNumber decrements. If iValueNumber = 5, then rValueOut = rValue5. If iValueNumber= 1 and there is a rising edge at bEdgeNewValue, then iValueNumber = iNumberOfValues(12) and thus rValueOut = rValue12.
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 rValueOut = rValue7.

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

- eCtrlMode = eHVACCtrlMode_AutoANDbDirection = FALSEANDiNumberOfValues > 0, so iValueNumber = 1 and rValueOut = rValue1.

- eCtrlMode = eHVACCtrlMode_AutoANDbDirection = TRUEANDiNumberOfValues = 12, so iNumberOfValues = 12 and rValueOut = rValue12.

- eCtrlMode = eHVACCtrlMode_ManualANDiManualValue = 13, so iValueNumber = 13 and rValueOut = rValue13.

- eCtrlMode = eHVACCtrlMode_ManualANDiManualValue = 0, so iValueNumber = 0 and rValueOut = 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 rValueX, whose content is output in the output variable rValueOut.
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. rValueOut 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_REAL_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

rValue1-16        : REAL;            

rValue1-16: the value of the output variable rValueOut is determined by the variables rValue1 to rValue16. If iValueNumber = 6, then rValueOut = rValue6.
If iNumberOfValues = 8, the output iValueNumber moves between 1 and 8. The variables rValue1 to rValue8 are taken into account for the output rValueOut if the operation mode is eCtrlMode = eHVACCtrlMode_Auto, see Application: the variable is saved persistently.