> For the complete documentation index, see [llms.txt](https://support.powerio.com/hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.powerio.com/hub/codesys-hvac/en/hvac-library/functionblocks/counter/servicecounter.md).

# 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 the last maintenance                            |
| *dNextService*      | DATE      |             |               | Due date of the next maintenance                        |
| *xAlarm1*           | BOOL      |             |               | Indication that maintenance will be due soon            |
| *xAlarm2*           | BOOL      |             |               | Indication that maintenance is due today                |
| *xAlarm3*           | BOOL      |             |               | Indication that maintenance was already due             |
| *diServiceInDay*    | DINT      |             |               | Display of in how many days 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 will be 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 day counter                            |
| **xEn**               | BOOL      |                         | TRUE          | Enable outputs xAlarm1 to 3                              |

### Functional description

#### General

This function block provides functionality for signaling maintenance intervals and for resetting the counter after maintenance has been carried out.\
The three outputs for signaling can be temporarily switched off.\
The number of days until the next maintenance (maintenance interval) can be set freely. The number of days since the last maintenance is calculated and displayed.

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

With the setpoint / parameter **xEn** set to FALSE, the outputs *xAlarm1*, *xAlarm2* and *xAlarm3* are temporarily disabled.\
When the next service interval expires, the setpoint / parameter is reset to the initial value TRUE again.\
\
The output *xAlarm1* is TRUE when the next maintenance date is reached in less than *iAlarm1* days. Since the period is before the maintenance date, the value must be **negative** entered.\
The output *xAlarm2* is TRUE when maintenance is due today (*diServcieInDay* <= 0).\
The output *xAlarm3* is TRUE when the next maintenance date is already at least *iAlarm3* days in the past.\
The three outputs are set to FALSE again when the maintenance day counter is reset with the setpoint / parameter **xReset** . In the process, the variable *dLastService* is assigned 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, if necessary, limited to the corresponding limit values.\
Any change to a setpoint / parameter can therefore cause a change in another setpoint / parameter.

{% hint style="info" %}
Prerequisite for using the ServiceCounter function block

For correct operation, the use of the TimeRead2 function block is required.
{% endhint %}

### 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` |         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://support.powerio.com/hub/codesys-hvac/en/hvac-library/functionblocks/counter/servicecounter.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
