Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » Measurement of time interval with KOP?(Is it possible to measue a time interval by the use of KOP?)
Measurement of time interval with KOP? [message #1751392] Mon, 09 January 2017 16:45 Go to next message
Ernst Murnleitner is currently offline Ernst MurnleitnerFriend
Messages: 19
Registered: December 2016
Junior Member
I want to make a FB by the use of KOP which needs to know how many seconds are elapsed since the last call or event.

It is needed for calculation of the "exponential weighted moving average" of a sensor value:

IF QI = true then
IF (ElapsedTime < WholeDuration) THEN
AverageValue := (AverageValue * (WholeDuration - ElapsedTime) + NewValue) / WholeDuration;
Age := Age + ElapsedTime;
ELSE
AverageValue := NewValue;
Age := ElapsedTime;
END_IF;
IF (AverageValue > 0 AND AverageValue < Treshold) THEN
AverageValue := 0;
ELSIF (AverageValue < 0 AND AverageValue > Treshold) THEN
AverageValue := 0;
END_IF;
end_if;


Are there any standard functions in KOP? Is there any function to get the actual time in IEC61499?
Or should I use a timer?

I think it could work using a timer because I can query the elapsed time. Other ideas?



Re: Measurement of time interval with KOP? [message #1751397 is a reply to message #1751392] Mon, 09 January 2017 17:14 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

We have a function called TIME() this function returns you the time since FORTE was started. With the following code snippet you could get your Elapsed time.

VAR
 newTime : TIME;
 elapsedTime:  TIME;
END_VAR;

newTime := TIME();
elapsedTime := newTime - oldTime;
oldTime := newTime


Assuming that oldTime is a internal variable of your basic FB.

I hope this helps.
Re: Measurement of time interval with KOP? [message #1751434 is a reply to message #1751397] Tue, 10 January 2017 11:04 Go to previous messageGo to next message
Ernst Murnleitner is currently offline Ernst MurnleitnerFriend
Messages: 19
Registered: December 2016
Junior Member
Alois Zoitl wrote on Mon, 09 January 2017 17:14
We have a function called TIME()


How can I see which functions are available? I cannot find it in 4Diac. Would be nice if there is a list somewhere. I think this function is not part of the standard, is it?

In the standard 61499 there are some functions defined, but as far as I have read no such functions.
Re: Measurement of time interval with KOP? [message #1751815 is a reply to message #1751434] Sat, 14 January 2017 20:26 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

Currently there is no such list of functions we support. Would be a good point for a new page in our documentation.

Furthermore IEC 61499 itself does not define any functions. It hands this over to the languages that are used for algorithms. in 4diac's case this would be IEC 61131-3 Structured Text (ST). For that 4diac supports all functions defined in IEC 61131-3. In FORTE these functions are in the files core/iec61131_functions.h and core/convert_functions.h. If you don't want to dig around in the FORTE source code you can also have a look into the IEC 61131-3 directory. There the IEC 61131-3 functions and function blocks have been ported from IEC 61131-3 to IEC 61499. All FBs there prefixed with 'F_' can be used in ST algorithm with out the 'F_' prefix.

The TIME function I've mentioned above was added as prototype for an experiment when we experimented with porting some of the FBs from the open source IEC 61131-3 library OSCAT. As we found this function very helpfull we kept it. In FORTE it is implemented in the file forte_time.h

I hope this helps.
Re: Measurement of time interval with KOP? [message #1779864 is a reply to message #1751815] Mon, 15 January 2018 03:44 Go to previous messageGo to next message
Daniel Ng is currently offline Daniel NgFriend
Messages: 23
Registered: October 2017
Junior Member
Dear Dr Zoitl,

I'm trying to measure for the execution time of either a single function block or a series of it within 4DIAC. Making use of the TIME() function, I've created a simple function block with 2 events to represent the Start and End of the timing measurement. The highest resolution I get with the TIME() function seems to be only at the milliseconds level.

index.php/fa/31805/0/
index.php/fa/31806/0/

Likewise for TIME related function blocks like E_CYCLE, we can set DT in ms at best.

Would it be possible to obtain a higher resolution say microseconds (us)? I understand that FORTE TimeBaseUnitsPerSecond is set to 1ns by default.

Thank you for your help.

Regards,
Daniel
Re: Measurement of time interval with KOP? [message #1779940 is a reply to message #1779864] Mon, 15 January 2018 22:10 Go to previous message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

Hi,

currently TIME(), E_CYCLE, E_DELAY are using the time base configured in cmake for forte. In windows or linux based systems with the current implementation I would expact the best resolution you get is roughly in the ms range. If you want to get higher accuracy measurements you need to use system specific time units. E.g., clock_get_time and calculate the difference in c code.
Previous Topic: Build Forte error using libmodbus
Next Topic:problems in using client and server
Goto Forum:
  


Current Time: Tue Apr 23 13:29:31 GMT 2024

Powered by FUDForum. Page generated in 0.03523 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top