FUNCTION_BLOCK "FB_CycleTime"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_OUTPUT 
      CycleTime : DInt;
   END_VAR

   VAR 
      TimeOld : DInt;
      TimeNew : DInt;
   END_VAR


BEGIN
	//letzte Zykluszeit ermitteln
	
	IF "FirstScan" THEN
	    //first Cycle
	    //no Cycletime
	    #TimeNew := TIME_TCK();
	    #CycleTime := 0;
	    #TimeOld := TIME_TCK();
	ELSE
	    #TimeNew := TIME_TCK();
	    IF #TimeNew < #TimeOld THEN
	        //Systemzeit übergelaufen
	        #CycleTime := 2147483647 - #TimeOld + #TimeNew;
	    ELSE
	        #CycleTime := #TimeNew - #TimeOld;
	    END_IF;
	    #TimeOld := #TimeNew;
	END_IF;
END_FUNCTION_BLOCK

