RobotStudio event

Stop-watch used for timing

jnielsen
jnielsen
edited April 2015 in Robot Controller
Hi,

I have implemented a stop-watch in my RAPID code (ClkStart) and it is almost doing as intended. I have one major problem though, that when I am reading my clock timer, it does not fit with the actual time passed. The longer it runs, the more off course the time from the clock timer is. 
E.g. my latest test shows this:

Start time: 2015-04-28 08:35:21
Stop time: 2015-04-28 08:36:55
Auto-mode: 0:1:17:

This doesnt add up. The actual time the timer have been counting should have been 94s (1m34s) but is 77s (1m17s). Start time and stop time are from the function CDate() and CTime(). 

My code is implemented as follows:

MODULE AutoFunctions
 VAR intnum inClockStart;
 VAR intnum inClockStop;
 VAR clock cAutoMode;
 VAR num ntimerAuto;
 VAR num seconds := 0;
 VAR num minutes := 0;
 VAR num hours := 0;
 VAR string sDateTime{2};
PROC Main()
    
        IDelete inClockStop;
        IDelete inClockStart;
                
        CONNECT inClockStop WITH trapClockStop;
        ISignalDO doEmneFaerdig,1,inClockStop;
        
        CONNECT inClockStart WITH trapClockStart;
        ISignalDO doStationAktiv,1,inClockStart;

    WHILE TRUE DO
        WaitTime 1;
    ENDWHILE
ENDPROC

TRAP trapClockStart
    sDateTime{1} := CDate() + " " + CTime();
    ClkStart cAutoMode;           
ENDTRAP

TRAP trapClockStop
        sDateTime{2} := CDate() + " " + CTime();

        ClkStop cAutoMode; 
        nTimerAuto:=ClkRead(cAutoMode);
TPWrite sDateTime{1};
TPWrite sDateTime{2};
TPWrite SecondsToTime(ntimerAuto);
        ClkReset cAutoMode;
ENDTRAP

FUNC string SecondsToTime(num s)
        s := ROUND(s);
        seconds := 0;
        minutes := 0;
        hours := 0;
        !s := TRUNC(s, \Dec:=2);
        IF s >= 60 THEN
            minutes := s DIV 60;
            seconds := s MOD 60;
        ELSE 
            seconds := s;
        ENDIF
        
        minutes := TRUNC(minutes);
        !minutes := TRUNC(minutes, \Dec:=2);
        
        IF minutes >= 60 THEN
           hours := minutes DIV 60;
           minutes := minutes MOD 60;
        ELSE
            minutes := minutes;
        ENDIF
        RETURN NumToStr (hours, 0) + ":" + NumToStr (minutes,0) + ":" + NumToStr(seconds,0) + ":";
ENDFUNC
ENDMODULE

Answers

  • I have had the same problem, the clock seems to be drifting. The longer it runs, the more off the clock gets. I would also like to get some information on this.