INT
环形计数器2,5ms
数据寄存器充当环形计数器。寄存器值每2,5ms增加一(计数范围:0–32767和-32768–0)。比较两个不同时间(v1和v2)的寄存器值(v)以确定经过时间(t): t = (v2-v1) x 2,5ms。
寄存器值在每次扫描开始时更新。
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;