# ImpulseCounter

## `ImpulseCounter` (FB)

FUNCTION\_BLOCK ImpulseCounter

### Short description

> Counter for input pulses with reset input and adjustable reduction

### Representation

<figure><img src="/files/41d2f5337297f13b17662deca319d1382ee40b82" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name       | Data type | Value range | Initial value | Function      |
| ---------- | --------- | ----------- | ------------- | ------------- |
| *xImpulse* | BOOL      |             |               | Counter input |
| *xReset*   | BOOL      |             | FALSE         | Reset input   |

#### Outputs

| Name                | Data type       | Value range | Initial value | Function                                        |
| ------------------- | --------------- | ----------- | ------------- | ----------------------------------------------- |
| *udiImpulseCounter* | UDINT           |             |               | Pulse counter                                   |
| *udiEnergy*         | UDINT           |             |               | Pulse counter after reduction                   |
| *dtLastImpulse*     | DATE\_AND\_TIME |             |               | Date/time of the end of the last counting pulse |

#### Setpoints / Parameters

| Name                | Data type | Value range | Initial value | Function         |
| ------------------- | --------- | ----------- | ------------- | ---------------- |
| **udiEnergyFactor** | UDINT     |             | 1             | Reduction factor |

### Function description

#### General

This function block is used to count the pulses (= rising edges) at the counter input *xImpulse* within the technical limits.\
The counter value is shown at output *udiImpulseCounter* displayed.\
\
If the counter value *udiImpulseCounter* the limit value **udiEnergyFactor**, then the output *udiEnergy* is incremented.\
Then the output *udiImpulseCounter* is reset to 0.\
\
The outputs *udiImpulseCounter* and **udiEnergy** are reset to 0 as long as at input *xReset* a rising edge is detected.\
\
At output *dtLastImpulse* is available after each rising edge at input *xImpulse* the current date / the current time *dtLastImpulse* is available in all other states at input *xImpulse* the date / time at the end of the last rising edge is available.\
At output *dtLastImpulse* the initialization value DT#1970-1-1-0.0.0 is output before the first rising edge.

> **Value ranges of the outputs&#x20;*****udiImpulseCounter*****&#x20;and&#x20;*****udiEnergy***
>
> Valid counter values are within the limits 0 and 4294967295.\
> Incrementing the counter value 4294967295 resets the counter value to 0.\
> Afterwards, the counter value is incremented continuously again.
>
> **Reduction factor udiEnergyFactor**
>
> The reduction factor **udiEnergyFactor** is overwritten with the value 1 after each input of the value 0.
>
> **Example - Reduction factor**
>
> *udiImpulseCounter* = 9, **udiEnergy** = 0, **udiEnergyFactor** = 10\
> \
> After a rising edge at input *xImpulse* the counter values change as follows:\
> \
> \&#xNAN;*udiImpulseCounter* = 0, **udiEnergy** = 1, **udiEnergyFactor** = 10

### CODESYS

InOut:

| Scope       | Name                | Type    | Initial |
| ----------- | ------------------- | ------- | ------- |
| Input       | `xImpulse`          | `BOOL`  |         |
| Input       | `xReset`            | `BOOL`  | FALSE   |
| Input Const | `udiEnergyFactor`   | `UDINT` |         |
| Output      | `udiImpulseCounter` | `UDINT` |         |
| Output      | `udiEnergy`         | `UDINT` |         |
| Output      | `dtLastImpulse`     | `DT`    |         |


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
