Counter retrieval - how it works
- Last UpdatedMar 03, 2025
- 2 minute read
The following illustration shows how the counter algorithm determines the count for an analog tag.

This example has a start time of TC0 and an end time of TC3. The resolution has been set in such a way that the historian returns data for three complete cycles starting at TC0, TC1, and TC2, and an incomplete cycle starting at TC3.
For the queried tag, a total of twelve points are found throughout the cycles represented by the markers P1 through P12. Of these points, eleven represent normal analog values. The point P9 represents a NULL due to an I/O Server disconnect, which causes a gap in the data between P9 and P10. Point P12 is not considered because it is outside of the query time frame.
All points are considered in the counter calculation, but only the yellow ones are actually used to determine which values to return to the client. The returned points are PC0, PC1, PC2 and PC3, shown in green at the top to indicate that there is no simple relationship between them and any of the actual points.
All cycle values are calculated as the delta change between the cycle time in question and the previous cycle time, taking into account the number of rollovers between the two points in time. The counter algorithm assumes that a rollover occurred if the current value is lower than the previous value. The initial value at the query start time (PC1) is calculated the same way, only based on a phantom cycle before the query start time.
For example, the formula to calculate PC1 is as follows:
PC1 = n * VR + P6 - P1
where:
-
n = the number of rollovers that have occurred during the cycle
-
VR = the rollover value for the tag
If either n or VR are equal to zero, PC1 is simply the difference between the values P1 and P6.
In the case of cycle C2, there is no value at the cycle time, so the NULL value represented by point P9 is returned. In the case of cycle C3, a NULL is again returned, because there is no counter value at the previous cycle boundary to use in the calculation. There must be a full cycle of values in order for the counter to be calculated.
If a gap is fully contained inside a cycle, and if points occur within the cycle on both sides of the gap, then a counter value is returned, even though it may occasionally be erroneous. Zero or one rollovers are assumed, even though the counter might have rolled over multiple times.