> 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/monitoring/countermonitoring.md).

# CounterMonitoring

## `CounterMonitoring` (FB)

FUNCTION\_BLOCK CounterMonitoring

### Short description

> Monitoring of a counter value and generation of a fault message\
> \
> Typical application: Monitoring a water meter for exceeding a maximum consumption during a monitoring interval

### Representation

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

### Interfaces

#### Inputs

| Name            | Data type | Value range | Initial value | Function                                                           |
| --------------- | --------- | ----------- | ------------- | ------------------------------------------------------------------ |
| *xEn*           | BOOL      |             | FALSE         | Enable / disable counter monitoring (TRUE = enable)                |
| *rCounterValue* | REAL      |             | 0.0           | Current absolute counter value (e.g. meter for the water quantity) |
| *xResetAlarm*   | BOOL      |             | FALSE         | Resetting the output ‘xAlarm’ (on every rising edge)               |

#### Outputs

| Name               | Data type | Value range | Initial value | Function                                                                       |
| ------------------ | --------- | ----------- | ------------- | ------------------------------------------------------------------------------ |
| *xAlarm*           | BOOL      |             | FALSE         | Fault message - counter monitoring (FALSE = Off, TRUE = On)                    |
| *tMonIntervall*    | TIME      |             |               | Duration of a monitoring interval                                              |
| *tRemainIntervall* | TIME      |             |               | Remaining time in the monitoring interval                                      |
| *rConsumMax*       | REAL      |             |               | Maximum consumption in the monitoring interval                                 |
| *rConsumIntervall* | REAL      |             |               | Current consumption in the monitoring interval                                 |
| *rConsumRemain*    | REAL      |             |               | Remaining consumption in the monitoring interval before the alarm is triggered |

#### Setpoints / Parameters

| Name                | Data type | Value range | Initial value | Function                                               |
| ------------------- | --------- | ----------- | ------------- | ------------------------------------------------------ |
| **udiMonIntervall** | UDINT     |             | 24            | Duration of a monitoring interval (0 … 4294967295)     |
| **tMinIntervall**   | TIME      |             | T#0s          | Absolute minimum duration of a monitoring interval     |
| **tMaxIntervall**   | TIME      |             | T#7D          | Absolute maximum duration of a monitoring interval     |
| **eScaleIntervall** | eTime     |             | eTime.Hour    | Scaling of the duration ‘udiMonIntervall’              |
| **rConsumLimit**    | REAL      |             | 10.0          | Limit value for consumption in the monitoring interval |

### Functional description

#### General

This function block is used to monitor a media consumption (water, electricity, etc.) (input ‘rCounterValue’)\
during the adjustable monitoring interval ‘tMonIntervall’. If the consumption exceeds the maximum value for the\
monitoring interval ‘rConsumLimit’, an alarm (‘xAlarm’ = TRUE) is triggered. It can be reset by a rising\
edge at input ‘xResetAlarm’.

#### Monitoring

The cyclic monitoring interval starts if all of the following conditions are met simultaneously:

1. ‘xEn’ = TRUE
2. ‘rConsumLimit’ > 0.0
3. ‘tMonIntervall’ >= T#60s

\
The cyclic monitoring interval ends if at least one of these conditions is no longer met.\
\
At the beginning of each monitoring interval, the current counter value ‘rCounterValue’ is saved as the starting value.\
During the monitoring interval, the difference between the current counter value and the starting value is continuously calculated (rConsumIntervall).\
The output xAlarm is activated (= TRUE) whenever this difference exceeds the limit value rConsumLimit.\
The output xAlarm is reset (= FALSE) by each rising edge at input ‘xResetAlarm’.\
\
The definition of the duration ‘tMonIntervall’ is made by the setpoints ‘udiMonIntervall’ (absolute numeric value) in combination with ‘eScaleIntervall’ (scaling)\
taking into account ‘tMinIntervall’ (absolute minimum value) and ‘tMaxIntervall’ (absolute maximum value).

#### Displays

The following outputs are available for displaying the current operating state:

1. xAlarm Fault message - counter monitoring (FALSE = Off, TRUE = On)
2. tMonIntervall Duration of a monitoring interval
3. tRemainIntervall Remaining residual time in the monitoring interval
4. rConsumMax Maximum consumption in the monitoring interval (identical to **rConsumLimit**)
5. rConsumIntervall Current consumption in the monitoring interval (only consumptions >= 0.0 are displayed)
6. rConsumRemain Remaining consumption in the monitoring interval before the alarm is triggered (only consumptions >= 0.0 are displayed)

#### Locking of the function block (xEn = FALSE)

These outputs assume the following fixed states:

1. xAlarm FALSE
2. tMonIntervall T#0s
3. tRemainIntervall T#0s
4. rConsumMax 0.0
5. rConsumIntervall 0.0
6. rConsumRemain 0.0

### CODESYS

InOut:

| Scope       | Name               | Type    | Initial          |
| ----------- | ------------------ | ------- | ---------------- |
| Input       | `xEn`              | `BOOL`  | TRUE             |
| Input       | `rCounterValue`    | `REAL`  | 0.0              |
| Input       | `xResetAlarm`      | `BOOL`  | FALSE            |
| Input Const | `rConsumLimit`     | `REAL`  | 10.0             |
| Input Const | `eScaleIntervall`  | eTime   | eTime.Hour       |
| Input Const | `tMaxIntervall`    | `TIME`  | TIME#10080m0s0ms |
| Input Const | `tMinIntervall`    | `TIME`  | TIME#0ms         |
| Input Const | `udiMonIntervall`  | `UDINT` | 24               |
| Output      | `xAlarm`           | `BOOL`  |                  |
| Output      | `tMonIntervall`    | `TIME`  |                  |
| Output      | `tRemainIntervall` | `TIME`  |                  |
| Output      | `rConsumMax`       | `REAL`  |                  |
| Output      | `rConsumIntervall` | `REAL`  |                  |
| Output      | `rConsumRemain`    | `REAL`  |                  |


---

# 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/monitoring/countermonitoring.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.
