CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Tue Apr 25, 2017 5:35 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Convert TIME to REAL
PostPosted: Sat Feb 04, 2017 11:57 am 
Offline

Joined: Wed May 20, 2015 10:20 am
Posts: 4
Hi,

I need to calculate step value for some time period like this:
bStep=(targetLevel-currentLevel)/(timePeriod/t#10ms)

targetLevel,currLevel,bStep - REAL
timePeriod - TIME

my TON1 has PT:=t#10ms and when TON1.Q I need to add bStep to bValue

Now I have Type mismatch in division so I think I need to convert TIME to REAL, or TIME to INT and INT to REAL
Is it possible?

Best Regards
Marek


Top
   
 Post subject: Re: Convert TIME to REAL
PostPosted: Sat Feb 04, 2017 1:05 pm 
Offline

Joined: Wed May 20, 2015 10:20 am
Posts: 4
Sorry newbie question ;)
Conversion Operator TIME_TO_REAL

Best Regards
Marek


Top
   
 Post subject: Re: Convert TIME to REAL
PostPosted: Sat Feb 04, 2017 9:45 pm 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 974
because the scantime is a problem, check if you can get the needed precision.
maybe you need the clocktime to get enough accuracy of the step.

another way to get correct results, is by adding the step/time in a way like an x/y line can be computed.

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


Top
   
 Post subject: Re: Convert TIME to REAL
PostPosted: Mon Feb 13, 2017 10:58 am 
Offline

Joined: Mon Jun 30, 2014 9:35 am
Posts: 53
You can make use of the SysTime library, get the starting time in st1 and the stop time in st2, then calculate the elapsed time inbetween. It can be within a cycle or several cycles later, it doesn't matter.


Code:
VAR
    st1, st2: SysTime;
    diElapsedTimeUs: DINT;
END_VAR

Code:
//Get starting time (in us)
SysTimeGetUs(pUsTime:=st1);

//Do something

//Get stop time (in us)
SysTimeGetUs(pUsTime:=st2);

//Calculate elapsed time (in us)
diElapsedTimeUs:=ANY_TO_DINT(st2-st1);


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited