# ServiceCounter

## `ServiceCounter` (FB)

FUNCTION\_BLOCK ServiceCounter

### Short description

> Signaling of maintenance

### Representation

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

### Interfaces

#### Inputs

\\

#### Outputs

| Name                | Data type | Value range | Initial value | Function                                                      |
| ------------------- | --------- | ----------- | ------------- | ------------------------------------------------------------- |
| *dLastService*      | DATE      |             |               | Date of last maintenance                                      |
| *dNextService*      | DATE      |             |               | Date of due next maintenance                                  |
| *xAlarm1*           | BOOL      |             |               | Indication that maintenance is due soon                       |
| *xAlarm2*           | BOOL      |             |               | Indication that maintenance is due today                      |
| *xAlarm3*           | BOOL      |             |               | Indication that maintenance was already due                   |
| *diServiceInDay*    | DINT      |             |               | Indication of how many days until the next maintenance is due |
| *diServiceSinceDay* | DINT      |             |               | Days since the last maintenance                               |

#### Setpoints / parameters

| Name                  | Data type | Value range             | Initial value | Function                                                |
| --------------------- | --------- | ----------------------- | ------------- | ------------------------------------------------------- |
| **iAlarm1**           | INT       | (0-diServiceInterval)…0 | -10           | Alarm threshold 1 in days (maintenance is due soon)     |
| **iAlarm3**           | INT       | 0…diServiceInterval     | 10            | Alarm threshold 3 in days (maintenance was already due) |
| **diServiceInterval** | UINT      | 1…1825                  | 365           | Maintenance interval (in days)                          |
| **xReset**            | BOOL      |                         | FALSE         | Reset maintenance days counter                          |
| **xEn**               | BOOL      |                         | TRUE          | Enable outputs xAlarm1 to 3                             |

### Function description

#### General

This function block provides functionalities for signaling maintenance intervals and for resetting the counter after maintenance has been performed.\
The three signaling outputs can be temporarily disabled.\
The number of days until the next maintenance (maintenance interval) is freely adjustable. The number of days since the last maintenance is calculated and displayed.\
\\

#### Outputs *xAlarm1*, *xAlarm2* and *xAlarm3*

With the setpoint / parameter **xEn** equal to FALSE the outputs are *xAlarm1*, *xAlarm2* and *xAlarm3* temporarily disabled.\
When the next service interval elapses, the setpoint / parameter is reset to the initial value TRUE.\
\
The output *xAlarm1* will be TRUE when the next maintenance date is reached in less than *iAlarm1* days. Since the period is before the maintenance date, the value is **negative** to be entered.\
The output *xAlarm2* is TRUE when maintenance is due today (*diServcieInDay* <= 0).\
The output *xAlarm3* is TRUE when the next maintenance date was already at least *iAlarm3* days ago.\
The three outputs are set back to FALSE when the maintenance days counter is reset with the setpoint / parameter **xReset** During this, the variable *dLastService* is written with the current date.\
\\

#### Setpoints / parameters **iAlarm1**, **iAlarm3** and **diServiceInterval**

The setpoints / parameters are provided with input limits according to the following table:\\

| Setpoint / Parameter                                                | Minimum value         | Maximum value              | Note                           |
| ------------------------------------------------------------------- | --------------------- | -------------------------- | ------------------------------ |
| **diServiceInterval**                                               | 0                     | 5 \* **diServiceInterval** | Service interval               |
| **iAlarm1**                                                         | (0-diServiceInterval) | 0                          | Threshold for output *xAlarm1* |
| **iAlarm2**                                                         | **iAlarm1**           | **iAlarm3**                | Threshold for output *xAlarm2* |
| **iAlarm3**                                                         | **iAlarm2**           | diServiceInterval          | Threshold for output *xAlarm3* |
| The setpoint / parameter **iAlarm2** cannot be changed by the user. |                       |                            |                                |

> \
> The setpoints / parameters are checked cyclically and limited to the corresponding bounds if necessary.\
> Any change of one setpoint / parameter can therefore cause a change of another setpoint / parameter.\
> \
> \##### Prerequisite for using the ServiceCounter function block
>
> For correct operation, the use of the TimeRead2 function block is required.\\

### CODESYS

InOut:

| Scope       | Name                | Type   | Initial |
| ----------- | ------------------- | ------ | ------- |
| Input Const | `xEn`               | `BOOL` | TRUE    |
| Input Const | `xReset`            | `BOOL` | FALSE   |
| Input Const | `diServiceInterval` | `UINT` | 365     |
| Input Const | `iAlarm3`           | `INT`  | 10      |
| Input Const | `iAlarm1`           | `INT`  | -10     |
| Output      | `dLastService`      | `DATE` |         |
| Output      | `dNextService`      | `DATE` |         |
| Output      | `xAlarm1`           | `BOOL` |         |
| Output      | `xAlarm2`           | `BOOL` |         |
| Output      | `xAlarm3`           | `BOOL` |         |
| Output      | `diServiceInDay`    | `DINT` |         |
| Output      | `diServiceSinceDay` | `DINT` |         |
