<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Convert TIME to REAL</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2244ad8757/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2244ad8757/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2244ad8757/</id><updated>2020-02-27T19:56:36.698000Z</updated><subtitle>Recent posts to Convert TIME to REAL</subtitle><entry><title>Convert TIME to REAL</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/2244ad8757/?limit=25#ffc1" rel="alternate"/><published>2020-02-27T19:56:36.698000Z</published><updated>2020-02-27T19:56:36.698000Z</updated><author><name>Kim</name><uri>https://forge.codesys.com/u/kim/</uri></author><id>https://forge.codesys.com8bd9b55125b3718ae8b067adf9792bcd0a7de2c5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;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.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nt"&gt;st1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;st2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;SysTime&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nt"&gt;diElapsedTimeUs&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;DINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Get&lt;/span&gt; &lt;span class="nv"&gt;starting&lt;/span&gt; &lt;span class="nv"&gt;time&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;us&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;SysTimeGetUs&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;pUsTime&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;st1&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="k"&gt;Do&lt;/span&gt; &lt;span class="nv"&gt;something&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Get&lt;/span&gt; &lt;span class="nv"&gt;stop&lt;/span&gt; &lt;span class="nv"&gt;time&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;us&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;SysTimeGetUs&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;pUsTime&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;st2&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Calculate&lt;/span&gt; &lt;span class="nv"&gt;elapsed&lt;/span&gt; &lt;span class="nv"&gt;time&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;us&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;diElapsedTimeUs&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;ANY_TO_DINT&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;st2&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;st1&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Convert TIME to REAL</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/2244ad8757/?limit=25#c639" rel="alternate"/><published>2020-02-27T19:56:33.060000Z</published><updated>2020-02-27T19:56:33.060000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com0452213318d24fd999909248defcf73ff409de95</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;because the scantime is a problem, check if you can get the needed precision.&lt;br/&gt;
maybe you need the clocktime to get enough accuracy of the step.&lt;/p&gt;
&lt;p&gt;another way to get correct results, is by adding the step/time in a way like an x/y line can be computed.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Convert TIME to REAL</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/2244ad8757/?limit=25#fca0" rel="alternate"/><published>2020-02-27T19:56:31.760000Z</published><updated>2020-02-27T19:56:31.760000Z</updated><author><name>frankiPL</name><uri>https://forge.codesys.com/u/frankipl/</uri></author><id>https://forge.codesys.com326e69c4922ffb5823abca3d498bad887a6bfd6f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Sorry newbie question &lt;br/&gt;
Conversion Operator TIME_TO_REAL&lt;/p&gt;
&lt;p&gt;Best Regards&lt;br/&gt;
Marek&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Convert TIME to REAL</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/2244ad8757/?limit=25#1211" rel="alternate"/><published>2020-02-27T19:56:30.444000Z</published><updated>2020-02-27T19:56:30.444000Z</updated><author><name>frankiPL</name><uri>https://forge.codesys.com/u/frankipl/</uri></author><id>https://forge.codesys.com63e624d976ad1099aae6baa8af3701ad0dacc114</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I need to calculate step value for some time period like this:&lt;br/&gt;
bStep=(targetLevel-currentLevel)/(timePeriod/t#10ms)&lt;/p&gt;
&lt;p&gt;targetLevel,currLevel,bStep - REAL&lt;br/&gt;
timePeriod - TIME&lt;/p&gt;
&lt;p&gt;my TON1 has PT:=t#10ms and when TON1.Q I need to add bStep to bValue&lt;/p&gt;
&lt;p&gt;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&lt;br/&gt;
Is it possible?&lt;/p&gt;
&lt;p&gt;Best Regards&lt;br/&gt;
Marek&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>