INT
Ring counter 2.5ms
The data register acts as a ring counter. The register value is increased by one every 2.5ms (counting range: 0–32767 and -32768–0). Compare the register values (v) at two different times (v1 and v2) to determine the elapsed time (t): t = (v2-v1) x 2.5ms.
The register value is updated at the beginning of each scan.
if (NOT bIsInitialized) then
bIsInitialized:=TRUE;
iRingCounter_Old:=sys_iRingCounter_2ms5;
iScans:=1;
else
iRingCounter_New:=sys_iRingCounter_2ms5;
iRingCounterDiff:=iRingCounter_New-iRingCounter_Old;
if (iRingCounterDiff>0) then (* Important to work also for shorter scan times *)
diScanTime_µs:=(INT_TO_DINT(iRingCounterDiff)*2500)/INT_TO_DINT(iScans);
iRingCounter_Old:=iRingCounter_New;
iScans:=1;
else
iScans:=iScans+1;
end_if;
end_if;