|
Re: Time to real conversion in FORTE 10 [message #1807448 is a reply to message #1807439] |
Thu, 30 May 2019 10:53 |
|
IEC 61131-3 does not define such functions. From the current definitions in IEC 6113-3 it would also be rather hard to define such functions. What should be the the according time value of your 1.0 REAL value? Given the current definitions I would recommend that you give also the time values directly in REAL.
Cheers,
Alois
|
|
|
|
Re: Time to real conversion in FORTE 10 [message #1807463 is a reply to message #1807450] |
Thu, 30 May 2019 15:12 |
|
Thanks for the use case.
First of all, please accept our apology that we provided means like the one you mentioned. After reviewing IEC 61131-3 this is wrong on many ways.
First of all the TIME data type should be used for time duration. TIME can never hold a value of now. For this any of the DATE, DATE_AND_TIME, or TIME_OF_DAY data types should be used.
Therefore I think we should clean-up 4diac here and also remove the TIME() function and replace it with something like NOW. However I'm not sure if the return value should be DATE_AND_TIME or TIME_OF_DAY.
Based on that There are functions for subtracting values of these date types to get TIME and for TIME introduce new functions: TIME_TO_REAL_S, TIME_TO_REAL_MS, TIME_TO_REAL_US, TIME_TO_REAL_NS. So that it is clear what the resulting value would be.
What do you think?
Cheers,
Alois
P.S.: May I ask why are you needing the real time in your algorithm? Currently I would mostly need it only for time_stamping and measuring things. But I don't think this is your intention.
|
|
|
Re: Time to real conversion in FORTE 10 [message #1807480 is a reply to message #1807463] |
Thu, 30 May 2019 20:08 |
ardianto vn Messages: 31 Registered: May 2019 |
Member |
|
|
I want to do integral calculations
##Internal Variabel
t_now,t_last,Error_Old,Ki_in,dtOut_in (All in REAL data type)
============================
##Variables in the FBT interface
Error(REAL), Reset(BOOL), Out(REAL)
============================
t_now := TIME_TO_REAL(TIME());
dt := t_now - t_last;
t_last := t_now;
IF Reset THEN
Out := 0;
Out_in := 0;
ELSE
Out_in := (Error + Error_Old)*0.5*dt + Out_in;
Error_Old := Error;
Out := Out_in*Ki_in;
END_IF;
This code runs on FORTE 8 but does not work on FORTE 10.
Are there alternative ways to do integral calculations on FORTE 10?
[Updated on: Thu, 30 May 2019 20:12] Report message to a moderator
|
|
|
Re: Time to real conversion in FORTE 10 [message #1807484 is a reply to message #1807480] |
Thu, 30 May 2019 22:03 |
|
Are you invoking the FB in an E_CYCLE chain? If yes then it is a better option to specify the dt as input parameter. This has the advantage that you can also easily speed up your calculations.
Futhermore the if Reset would be better as state and event. This results in much better readable code.
Cheers,
Alois
|
|
|
Re: Time to real conversion in FORTE 10 [message #1807508 is a reply to message #1807484] |
Fri, 31 May 2019 12:22 |
Martin Melik Merkumians Messages: 117 Registered: March 2016 |
Senior Member |
|
|
Hi all,
Quote:First of all the TIME data type should be used for time duration. TIME can never hold a value of now
I support Alois here, the IEC 61131 says that TIME is only for duration, so NOW does not make any sense for this.
Quote:Therefore I think we should clean-up 4diac here and also remove the TIME() function and replace it with something like NOW. However I'm not sure if the return value should be DATE_AND_TIME or TIME_OF_DAY.
I like the name NOW, and it should return DATE_AND_TIME, as it is explicitly castable into DATE and TIME_OF_DAY, which would cover all data type holding times.
Quote:TIME_TO_REAL_S, TIME_TO_REAL_MS, TIME_TO_REAL_US, TIME_TO_REAL_NS
In principle I think such functions are needed but providing them with this kind of names would mean that there would be a lot of them as we would have to provide them for a variaty of type.
How about leaning even a little more to the CAST function of IEC 61131 and naming them TIME_IN_[S/MS/US/NS]_TO , so we could provide a *-cast version which types itself to the correct type?
Best,
Martin
|
|
|
Re: Time to real conversion in FORTE 10 [message #1807510 is a reply to message #1807508] |
Fri, 31 May 2019 13:46 |
|
Martin Melik-Merkumians wrote on Fri, 31 May 2019 12:22
I like the name NOW, and it should return DATE_AND_TIME, as it is explicitly castable into DATE and TIME_OF_DAY, which would cover all data type holding times.
Thanks for pointing that out.
Martin Melik-Merkumians wrote on Fri, 31 May 2019 12:22
How about leaning even a little more to the CAST function of IEC 61131 and naming them TIME_IN_[S/MS/US/NS]_TO , so we could provide a *-cast version which types itself to the correct type?
I like the naming for TIME_IN_[]_TO_xxx. Maybe we should start with a view concrete ones before doing the generic version.
Can you please submit bug reports for your suggestions?
Cheers,
Alois
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04524 seconds