Hello,
Excuse me I don't speak english very well. I am discovering Codesys and I am trying to measure the time between two events. My main program is in LD but I can create function blocks with ST.
I already saw some programs using the function SYS_TIME but Codesys doesn't recognize this function when I use it.
Do you have any idea that could help me ?
Thank you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you know the scan time you can simply implement a counter in ST and count the cycles between the events.
Say you have a scan time of 100ms then do:
IF event1 THEN
Count := Count + 0.1; // Increment by 0.1s
END_IF;
IF event2 THEN
Time := Count; // Set time value to Count
Count := 0; // Rsset counter value for next run
END_IF;
This is just a simple example to give you inspiration.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hum, regular way to do this is using systime library. You need to add it to your project in the library manager.
Then use SysTimeGetMs to get actual CPU time in milliseconds ( ! This time is UTC time, not localized).
Then, just substract values to get the delta time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
Excuse me I don't speak english very well. I am discovering Codesys and I am trying to measure the time between two events. My main program is in LD but I can create function blocks with ST.
I already saw some programs using the function SYS_TIME but Codesys doesn't recognize this function when I use it.
Do you have any idea that could help me ?
Thank you
If you know the scan time you can simply implement a counter in ST and count the cycles between the events.
Say you have a scan time of 100ms then do:
IF event1 THEN
Count := Count + 0.1; // Increment by 0.1s
END_IF;
IF event2 THEN
Time := Count; // Set time value to Count
Count := 0; // Rsset counter value for next run
END_IF;
This is just a simple example to give you inspiration.
Hum, regular way to do this is using systime library. You need to add it to your project in the library manager.
Then use SysTimeGetMs to get actual CPU time in milliseconds ( ! This time is UTC time, not localized).
Then, just substract values to get the delta time.