<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Controlling execution speed of function block</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/215f3aa775/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/215f3aa775/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/215f3aa775/</id><updated>2020-02-27T22:43:15.773000Z</updated><subtitle>Recent posts to Controlling execution speed of function block</subtitle><entry><title>Controlling execution speed of function block</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/215f3aa775/?limit=25#55a0" rel="alternate"/><published>2020-02-27T22:43:15.773000Z</published><updated>2020-02-27T22:43:15.773000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.comc290649195fabf4ec08023264ccb3102ae1869f9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;calc is not correct.&lt;br/&gt;
if overflow detected it should be&lt;br/&gt;
fulltime-prevtime+time()+1 is tdiff&lt;/p&gt;
&lt;p&gt;example pre is 250&lt;br/&gt;
time() is 5&lt;br/&gt;
full is 255&lt;br/&gt;
255-250=5&lt;br/&gt;
5+time()=10&lt;br/&gt;
10+1is 11&lt;/p&gt;
&lt;p&gt;yes the code is good, but it can deviate 100 ms due to other programs.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Controlling execution speed of function block</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/215f3aa775/?limit=25#6936" rel="alternate"/><published>2020-02-27T22:43:11.314000Z</published><updated>2020-02-27T22:43:11.314000Z</updated><author><name>softwaremonkey</name><uri>https://forge.codesys.com/u/softwaremonkey/</uri></author><id>https://forge.codesys.comdc01e98ffe182391dd320ed114e22b6d78715024</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks for the reply. Changing the task time to t#250mS is a really neat idea! Out of interest, if I decided to use the TIME() function, do you think the following code would handle the overflow? I dont really want to wait 49 days to see if it works   &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;   &lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;TIME&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;prevTime&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;         &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;Check&lt;/span&gt; &lt;span class="k"&gt;if&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;function&lt;/span&gt; &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="nv"&gt;overflowed&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
      &lt;span class="nv"&gt;prevTime&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;prevTime&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;T&lt;/span&gt;&lt;span class="sc"&gt;#49&lt;/span&gt;&lt;span class="nv"&gt;d17h2m47s295ms&lt;/span&gt;&lt;span class="c1"&gt;;   (* Make previous time overflow *)&lt;/span&gt;
   &lt;span class="nv"&gt;END_IF&lt;/span&gt;
   &lt;span class="nv"&gt;tdiff&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;TIME&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;prevTime&lt;/span&gt;&lt;span class="c1"&gt;;      (* Calculate elapsed time since algorithm was last run *)&lt;/span&gt;
   &lt;span class="k"&gt;IF&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;tdiff&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;LoopTime&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;      &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;Is&lt;/span&gt; &lt;span class="nv"&gt;it&lt;/span&gt; &lt;span class="nv"&gt;time&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;run&lt;/span&gt; &lt;span class="nv"&gt;algorithm&lt;/span&gt; &lt;span class="nv"&gt;again&lt;/span&gt;? &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
      &lt;span class="nv"&gt;prevTime&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;TIME&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;   (* Update the time when last run *)&lt;/span&gt;
      &lt;span class="nv"&gt;trigger&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;TRUE&lt;/span&gt;&lt;span class="c1"&gt;;      (* Flag that we should run *)&lt;/span&gt;
   &lt;span class="nv"&gt;END_IF&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Controlling execution speed of function block</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/215f3aa775/?limit=25#3b32" rel="alternate"/><published>2020-02-27T22:43:09.717000Z</published><updated>2020-02-27T22:43:09.717000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com7f25e228bb8699d5e6888363fb80f2e373c7c596</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;btw it does not work on a FB only on a program&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Controlling execution speed of function block</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/215f3aa775/?limit=25#742d" rel="alternate"/><published>2020-02-27T22:43:05.293000Z</published><updated>2020-02-27T22:43:05.293000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.comaf97e3087cc5ed9531378cb97c12b34e1d01056f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;go to resources, task configuration&lt;br/&gt;
add a task and add your program to that task&lt;br/&gt;
tell the task to run every t#250ms in cyclic mode.&lt;br/&gt;
that is all&lt;br/&gt;
no remember nor anything else to do it.&lt;br/&gt;
yes a timer will overflow (takes days but it does) then the task will not be done, but 250 msec later it does, so if critical you must check this, if not then just leave it.&lt;br/&gt;
a timer has the disadvantage it needs starting and that is taking time. about 10 ms, so one loop will be 260 msec.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Controlling execution speed of function block</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/215f3aa775/?limit=25#548c" rel="alternate"/><published>2020-02-27T22:43:03.697000Z</published><updated>2020-02-27T22:43:03.697000Z</updated><author><name>softwaremonkey</name><uri>https://forge.codesys.com/u/softwaremonkey/</uri></author><id>https://forge.codesys.come57326b721a302259cbf14c085b23981df642636</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have a function block written in ST that needs to run every 0.25 seconds but I am not sure how to do this. Ideally, I would like the timing to be internal to the function block so that you do not need to remember to trigger it externally.&lt;/p&gt;
&lt;p&gt;I thouhgt of using a timer but I could not figure out how to do this inside the FB. I also thought of using the TIME() function but i think that this will overflow in 49 days which would cause problems.&lt;/p&gt;
&lt;p&gt;Can anyone suggest what I can do?  &lt;/p&gt;&lt;/div&gt;</summary></entry></feed>