# AverageCh

## `AverageCh` (FB)

FUNCTION\_BLOCK AverageCh

### Short description

> Formation of an average from up to six weighted numerical input values\
> Typical application: formation of an ambient temperature average from different sensors

### Representation

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-c8d5ef42637881fa61780a8842664e1224b606d9%2Fimage%20(41)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name   | Data type | Value range | Initial value | Function                    |
| ------ | --------- | ----------- | ------------- | --------------------------- |
| *rIn1* | REAL      |             |               | Analog value input 1        |
| *rIn2* | REAL      |             |               | Analog value input 2        |
| *rIn3* | REAL      |             |               | Analog value input 3        |
| *rIn4* | REAL      |             |               | Analog value input 4        |
| *rIn5* | REAL      |             |               | Analog value input 5        |
| *rIn6* | REAL      |             |               | Analog value input 6        |
| *xEn1* | BOOL      |             |               | Enable analog value input 1 |
| *xEn2* | BOOL      |             |               | Enable analog value input 2 |
| *xEn3* | BOOL      |             |               | Enable analog value input 3 |
| *xEn4* | BOOL      |             |               | Enable analog value input 4 |
| *xEn5* | BOOL      |             |               | Enable analog value input 5 |
| *xEn6* | BOOL      |             |               | Enable analog value input 6 |

#### Outputs

| Name   | Data type | Value range | Initial value | Function        |
| ------ | --------- | ----------- | ------------- | --------------- |
| *rOut* | REAL      |             |               | Average         |
| *xErr* | BOOL      |             |               | Aggregate fault |

#### Setpoints / parameters

| Name          | Data type | Value range | Initial value | Function                         |
| ------------- | --------- | ----------- | ------------- | -------------------------------- |
| **iLoading6** | INT       |             | 10            | Weighting - analog value input 6 |
| **iLoading5** | INT       |             | 10            | Weighting - analog value input 5 |
| **iLoading4** | INT       |             | 10            | Weighting - analog value input 4 |
| **iLoading3** | INT       |             | 10            | Weighting - analog value input 3 |
| **iLoading2** | INT       |             | 10            | Weighting - analog value input 2 |
| **iLoading1** | INT       |             | 10            | Weighting - analog value input 1 |

### Function description

#### Average *rOut*

The average is formed by multiplying the analog value inputs *rInX* with their individual weighting **iLoadingX** and then summing all products (dividend).\
The sum of the weightings is formed by adding the individual weightings (= divisor).\
The quotient thus obtained is finally available as the average *rOut* .\
\
The individual weighting of an analog value input X always has the value 0.0 as long as the enable for analog value input X *xEnX* is disabled (= FALSE).\
If the sum of the weightings (divisor) = zero, then the output *rOut* constantly outputs the value 0.0.\
\
Legend: X = 1 to 6\\

#### Aggregate fault *xErr*

The collective error is active (= TRUE) if at least one of the analog value inputs *rInX* is disabled ( *xEnX* = FALSE ).\
In all other cases the collective error is not active (= FALSE).\\

### CODESYS

InOut:

| Scope       | Name        | Type   | Initial |
| ----------- | ----------- | ------ | ------- |
| Input       | `rIn1`      | `REAL` |         |
| Input       | `rIn2`      | `REAL` |         |
| Input       | `rIn3`      | `REAL` |         |
| Input       | `rIn4`      | `REAL` |         |
| Input       | `rIn5`      | `REAL` |         |
| Input       | `rIn6`      | `REAL` |         |
| Input       | `xEn1`      | `BOOL` |         |
| Input       | `xEn2`      | `BOOL` |         |
| Input       | `xEn3`      | `BOOL` |         |
| Input       | `xEn4`      | `BOOL` |         |
| Input       | `xEn5`      | `BOOL` |         |
| Input       | `xEn6`      | `BOOL` |         |
| Input Const | `iLoading6` | `INT`  | 10      |
| Input Const | `iLoading5` | `INT`  | 10      |
| Input Const | `iLoading4` | `INT`  | 10      |
| Input Const | `iLoading3` | `INT`  | 10      |
| Input Const | `iLoading2` | `INT`  | 10      |
| Input Const | `iLoading1` | `INT`  | 10      |
| Output      | `rOut`      | `REAL` |         |
| Output      | `xErr`      | `BOOL` |         |
