ImpulseCounter (FB)

FUNCTION_BLOCK ImpulseCounter

Short Description

Counter for input impulses with reset input and adjustable reduction


Portrayal

../_images/ImpulseCounter_FB.png

Interfaces

Inputs

Name

Datatype

Range

Init-Value

Function

xImpulse BOOL    

Counter input

xReset BOOL   FALSE

Reset input

Outputs

Name

Datatype

Range

Init-Value

Function

udiImpulseCounter UDINT    

Impulse counter

udiEnergy UDINT    

Impulse counter after reduction

dtLastImpulse DATE_AND_TIME    

Date/time of the end of the latest count impulse

Setpoints / Parameters

Name

Datatype

Range

Init-Value

Function

udiEnergyFactor UDINT   1

Reduction factor

Functional Description

General

This function block is used to count the impulses (= rising edges) at the counter input xImpulse within of the technical limits.
The counter reading is displayed at the output udiImpulseCounter.

If the counter reading udiImpulseCounter exceeds / reaches the limit value udiEnergyFactor, the output udiEnergy is incremented.
The output udiImpulseCounter is then reset to 0.

The outputs udiImpulseCounter and udiEnergy are reset to 0 as long as an rising edge is detected at input xReset.

At output dtLastImpulse, the current date/time is available after each rising edge at input xImpulse.
For all other states at the input xImpulse, the date of the last rising edge will be displayed at the output dtLastImpulse.
Before the first rising edge is triggerd, the output dtLastImpulse shows the initialization value DT#1970-1-1-1-0.0.0.

Value ranges of the outputs udiImpulseCounter and udiEnergy

Valid counter readings are within the limits 0 and 4294967295.
The incrementing of the counter reading 4294967295 resets the counter reading to 0.
The counter is then incremented again continuously.

Reduction factor udiEnergyFactor

The reduction factor udiEnergyFactor is overwritten with the value 1 it the value is set to 0.

Example - Reduction factor

udiImpulseCounter = 9, udiEnergy = 0, udiEnergyFactor = 10

After a rising edge at input xImpulse, the counter readings change as follows:

udiImpulseCounter = 0, udiEnergy = 1, udiEnergyFactor = 10

Visualization




Information

Element

Authors

Datum Version

Notes

Function

Adam Bartod XX.XXX 1.0

Initial version

Programming

Adam Bartod 09.2016 1.0

Initial version

Test Jochen Reu 10.2017 1.0

Initial version

Documentation

Lukas Pfänder 11.2017 0.1.3.0 Revision

Codesys

InOut:
Scope Name Type Initial Comment
Input xImpulse BOOL  

Counter input

xReset BOOL FALSE

Reset input

udiEnergyFactor UDINT  

Reduction factor

Output udiImpulseCounter UDINT  

Impulse counter

udiEnergy UDINT  

Impulse counter after reduction

dtLastImpulse DT  

Date/time of the end of the latest count impulse