INT
Ring counter100ms
The data register acts as a ring counter. The register value is increased by one every 100ms (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 100ms.
if (NOT bIsInitialized) then
bIsInitialized:=TRUE;
iRingCounter_Old:=sys_iRingCounter_100us;
iScans:=1;
else
iRingCounter_New:=sys_iRingCounter_100us;
iRingCounterDiff:=iRingCounter_New-iRingCounter_Old;
if (iRingCounterDiff>0) then (* Important to work also for shorter scan times *)
diScanTime_µs:=(INT_TO_DINT(iRingCounterDiff)*10000)/INT_TO_DINT(iScans);
iRingCounter_Old:=iRingCounter_New;
iScans:=1;
else
iScans:=iScans+1;
end_if;
end_if;