<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Help me understand Oscat time function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/58b69899ff/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/58b69899ff/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/58b69899ff/</id><updated>2020-02-27T14:22:59.897000Z</updated><subtitle>Recent posts to Help me understand Oscat time function</subtitle><entry><title>Help me understand Oscat time function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/58b69899ff/?limit=25#ecf6" rel="alternate"/><published>2020-02-27T14:22:59.897000Z</published><updated>2020-02-27T14:22:59.897000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.coma18dd00f255607d12f4d468201e370386ddb6cef</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;The debug section has some bit hackery tools for fast computation which make it hard to read.&lt;br/&gt;
Essentially N increases the speed of the clock, forcing a rollover not every 49 days, but every 49/(2^N) days. Offset also allows you to change the start value of your clock so the first rollover happens in say 1 minute instead of waiting a full 49/(2^N) days.&lt;br/&gt;
You would use this to test how your own code (which uses the T_PLC_MS()) functions at the rollover. For example do you have code that says:&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="nv"&gt;input1&lt;/span&gt; &lt;span class="nv"&gt;AND&lt;/span&gt; &lt;span class="nv"&gt;NOT&lt;/span&gt; &lt;span class="nv"&gt;AlreadySeenInput1&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
  &lt;span class="nv"&gt;StoredTime&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;T_PLC_MS&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;AlreadySeenInput1&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;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;&lt;span class="c1"&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;T_PLC_MS&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;StoredTime&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;30000&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
  &lt;span class="nv"&gt;ThirtySecondsLater&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;;&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;p&gt;If StoredTime was 10000ms less than the rollover,&lt;br/&gt;
(StoredTime + 30000) would then be only 20000, and ThirtySecondsLater would come on immediately.&lt;br/&gt;
You could test that scenario in simulation in a matter of minutes with the debug code, just don't leave it on the real machine!&lt;/p&gt;
&lt;p&gt;Warm welcome to all things Codesys!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Help me understand Oscat time function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/58b69899ff/?limit=25#fb91" rel="alternate"/><published>2020-02-27T14:22:58.713000Z</published><updated>2020-02-27T14:22:58.713000Z</updated><author><name>boompy</name><uri>https://forge.codesys.com/u/boompy/</uri></author><id>https://forge.codesys.com2ca1439ebe92b3d5fec00b61ebd10c7bdae7706e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi all&lt;/p&gt;
&lt;p&gt;I'm pretty new to all things Codesys.&lt;/p&gt;
&lt;p&gt;I'm been playing with Oscat libraries and trying to learn from them.&lt;/p&gt;
&lt;p&gt;Now I'm trying to understand what the 'debug' component of the T_PLC_MS function actually does. As I understand it, the PLC should reach an overflow condition every 49 days and the debug component is somehow meant to circumvent this. Is that right?&lt;/p&gt;
&lt;p&gt;Could somebody please explain to me how this works. The Oscat explanation is a bit lost on me.&lt;/p&gt;
&lt;p&gt;If somebody could help me I'd be very grateful.&lt;/p&gt;
&lt;p&gt;Why wouldn't I just use the time() function? What is the benefit of the Oscat function??&lt;/p&gt;
&lt;p&gt;FUNCTION T_PLC_MS : DWORD&lt;br/&gt;
VAR CONSTANT&lt;br/&gt;
    debug : BOOL := 0;&lt;br/&gt;
    N : INT := 0;&lt;br/&gt;
    offset : DWORD := 0;&lt;br/&gt;
END_VAR&lt;br/&gt;
VAR&lt;br/&gt;
    tx : TIME;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;##############&lt;/p&gt;
&lt;p&gt;tx := TIME();&lt;br/&gt;
T_PLC_MS := TIME_TO_DWORD(Tx);&lt;/p&gt;
&lt;p&gt;IF debug THEN&lt;br/&gt;
    T_PLC_MS := (SHL(T_PLC_MS,N) OR SHL(DWORD#1,N)-1) + OFFSET;&lt;br/&gt;
END_IF;&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>