> 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 reading 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="/files/3355443a5030e3b13c1f21cf328c9046b5387dea" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name            | Data type | Value range | Initial value | Function                                                     |
| --------------- | --------- | ----------- | ------------- | ------------------------------------------------------------ |
| *xEn*           | BOOL      |             | FALSE         | Enable / disable the counter monitoring (TRUE = enabled)     |
| *rCounterValue* | REAL      |             | 0.0           | Current absolute counter value (e.g. meter for water volume) |
| *xResetAlarm*   | BOOL      |             | FALSE         | Reset of the output 'xAlarm' (on each 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 |

### Function description

#### General

This function block is used to monitor a media consumption (water, electricity, etc.) (input 'rCounterValue')\
during the configurable 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 on the 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 is terminated if at least one of these conditions is no longer met.\
\
At the start of each monitoring interval the current counter value 'rCounterValue' is stored as the start value.\
During the monitoring interval the difference between the current counter value and the start value is continuously calculated (rConsumIntervall).\
The output xAlarm is activated (= TRUE) whenever this difference exceeds the threshold rConsumLimit.\
The output xAlarm is reset (= FALSE) by each rising edge at the input 'xResetAlarm'.\
\
The setting of the duration 'tMonIntervall' is made by the set values 'udiMonIntervall' (absolute numeric value) in combination with 'eScaleIntervall' (scaling)\
taking into account 'tMinIntervall' (absolute minimum) and 'tMaxIntervall' (absolute maximum).

#### Indicators

The following outputs are available to display the current operating status:

1. xAlarm Fault message - counter monitoring (FALSE = off, TRUE = on)
2. tMonIntervall Duration of a monitoring interval
3. tRemainIntervall Remaining 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 block (xEn = FALSE)

These outputs take 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
