Currently using Version 2.3.9.34 with an ABB AC500 PLC (PM591).
I am trying to get the timing between two events. I won't go into high detail, let's just say, for the sake of discussion, when either of the two events occur, they set a corresponding boolean variable = TRUE.
So, if Machine Starts, bStart = TRUE.
And, if Machine Stops, bStop = TRUE.
I'm over simplifying to make this easy to answer.
I just need the elapsed system time between the two events. Here is the code I am currently using:
(* SYSTEM TIME *)TIME_SYSÂ Â :=SYS_TIME(TRUE);TIME_ENDÂ Â :=TIME_SYS;(* RTC IN SECONDS *)RTC_TIMEÂ Â :=SysRtcGetTime(TRUE);TIME_END2Â Â :=RTC_TIME;(* EVENT TIMER *)RTRIG(CLK:=ESC_FAULT,Q=>);Â Â Â Â (* START TIMER Â Â *)FTRIG(CLK:=ESC_RUN,Q=>);Â Â Â Â (* STOP TIMER Â Â *)IFRTRIG.QORFTRIG.Q=TRUETHENÂ Â COUNTÂ Â Â Â Â Â Â Â :=Â Â COUNT+1;Â Â EVENT_TIMEÂ Â Â Â Â Â :=Â Â TIME_END-TIME_START;Â Â TIME_STARTÂ Â Â Â Â Â :=Â Â TIME_SYS;Â Â EVENT_TIME2Â Â Â Â Â Â :=Â Â TIME_END2-TIME_START2;Â Â TIME_START2Â Â Â Â Â Â :=Â Â RTC_TIME;END_IF;
The two times are redundant. One is DWORD and the other is DT format.
This seems to work in my current configuration, but if I want to test a scenario where the event is defined by a value reaching or exceeding a set point, it doesn't seem to function properly.
Does anyone have a function block they use for timing system events?
Any help is surely appreciated. Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FUNCTION_BLOCKTIMER_SYS(*INPUTVARIABLES Â Â *)VAR_INPUTÂ Â bSTART:BOOL;Â Â bSTOP:BOOL;END_VAR(*OUTPUTVARIABLESÂ Â *)VAR_OUTPUTÂ Â dwLAP_TIME: Â Â DWORD;END_VAR(*LOCALVARIABLESÂ Â *)VARÂ Â dwTIME_SYS: Â Â Â Â DWORD;Â Â dwTIME_END: Â Â Â Â DWORD;Â Â dwTIME_START: Â Â DWORD;Â Â rtSTART: Â Â Â Â R_TRIG;Â Â rtSTOP: Â Â Â Â R_TRIG;END_VARdwTIME_SYSÂ Â :=SYS_TIME(TRUE);dwTIME_ENDÂ Â :=dwTIME_SYS;rtSTART(CLK:=bSTART,Q=>);Â Â Â Â Â Â Â Â (*STARTTIMER Â Â *)rtSTOP(CLK:=bSTOP,Q=>);Â Â Â Â Â Â Â Â Â Â (*STOPTIMER Â Â *)IFrtSTART.QORrtSTOP.Q=TRUETHENÂ Â dwLAP_TIMEÂ Â Â Â :=Â Â dwTIME_END-dwTIME_START;Â Â dwTIME_STARTÂ Â Â Â :=Â Â dwTIME_SYS;END_IF;
Now, I have this function block to use to find the time between two events:
Time is output to dwLAP_TIME in milliseconds.
Feel free to use this!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey Guys!
Currently using Version 2.3.9.34 with an ABB AC500 PLC (PM591).
I am trying to get the timing between two events. I won't go into high detail, let's just say, for the sake of discussion, when either of the two events occur, they set a corresponding boolean variable = TRUE.
So, if Machine Starts, bStart = TRUE.
And, if Machine Stops, bStop = TRUE.
I'm over simplifying to make this easy to answer.
I just need the elapsed system time between the two events. Here is the code I am currently using:
The two times are redundant. One is DWORD and the other is DT format.
This seems to work in my current configuration, but if I want to test a scenario where the event is defined by a value reaching or exceeding a set point, it doesn't seem to function properly.
Does anyone have a function block they use for timing system events?
Any help is surely appreciated. Thanks!
yes have a look at w www.oscat.de w it is english library for codesys with lots of functions etc.
keep all times in DT format easier to work .
I simplified the code:
Now, I have this function block to use to find the time between two events:
Time is output to dwLAP_TIME in milliseconds.
Feel free to use this!
Hi
Just wanted to know which library is used to get sys_time
a few seconds later with google search...
https://stackoverflow.com/a/61986234
SYS_TIME is definitely an ABB AC500 specific function, included in library SysInt_AC500_V10.lib.