ImpulseCounter

ImpulseCounter (FB)

FUNCTION_BLOCK ImpulseCounter

Short description

Counter for input impulses with reset input and adjustable reduction

Representation

Interfaces

Inputs

Name
Data type
Value range
Initial value
Function

xImpulse

BOOL

Count 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 count 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 impulses (= rising edges) at the counter input xImpulse within the technical limits. The counter value is shown at the output udiImpulseCounter . If the counter value exceeds / reaches udiImpulseCounter the threshold value udiEnergyFactor, the output udiEnergy is incremented. Subsequently the output udiImpulseCounter is reset to 0. The outputs udiImpulseCounter and udiEnergy are reset to 0 as long as a rising edge is detected at the input xReset . At the output dtLastImpulse the current date / time is available after each rising edge at the input xImpulse . At the output dtLastImpulse the date / time at the end of the last rising edge is available for all other states at the input xImpulse . At the output dtLastImpulse the initialization value DT#1970-1-1-0.0.0 is output before the first rising edge.

Value ranges of the outputs udiImpulseCounter and udiEnergy

Valid counter values are within the limits 0 and 4294967295. Incrementing the counter value 4294967295 resets the counter value to 0. Subsequently 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 the input xImpulse the counter values change as follows: 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

Last updated