Table of Contents

Counter with Overflow Protection

Full Name

Lib.Mervis.v1_0.IncrementalCounter

Required Project References

Description

A helper block used for handling counter inputs that are at risk of overflow.

Usage in ST

program test
    var
        inp: lib.mervis.v1_0.IncrementalCounter;
    end_var

    inp();
end_program

Inputs

Name Data TypeRetainMandatory Connection Meaning
In udint No Yes Counter input value
Set bool No No Counter reset
Overflow udint No No Maximum counter input value for overflow handling (if =0, not used)
Step udint No No
PulseWeightreal No No Pulse weight, used to convert the counter value to a physical value
Offset real No No Pulse count offset, used to convert the counter value to a physical value

Outputs

Name Data TypeMeaning
Out udint Output
Weighted real Output converted to a physical value using PulseWeight and Offset
OverflowFlag bool Overflow flag
OverflowCountudint Counter overflow count

Detailed Function Description

The block is used to handle the value from a counter that frequently overflows. The block contains an internal 32-bit counter, which always increments by the number of incoming pulses (the difference from the previous computation cycle). If this difference is negative, it is considered an overflow, and the behavior depends on the Overflow parameter:

The Weighted output is calculated as a linear transformation of the internal counter state, i.e., Weighted = PulseWeight * Out + Offset