<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/</id><updated>2020-02-27T14:08:23.639000Z</updated><subtitle>Recent posts to How do i setup a setup task?</subtitle><entry><title>How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/?limit=25#0d70" rel="alternate"/><published>2020-02-27T14:08:23.639000Z</published><updated>2020-02-27T14:08:23.639000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com2126f713ed1214cbd0839fb5a63b1542dc0f2cf7</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;You must handle a wait/delay in a PLC way:&lt;/p&gt;
&lt;p&gt;Delay();&lt;br/&gt;
IF Delay.Q then&lt;br/&gt;
   Setup := TRUE;&lt;br/&gt;
END_IF&lt;/p&gt;
&lt;p&gt;Where Delay is a TON timer. &lt;/p&gt;
&lt;p&gt;Think of slicing your program - it must run in small steps until it is finished. For example, a FOR/NEXT loop of 10000 will probably fail. Instead, one iteration for PLC scan until all 10000 are completed. &lt;/p&gt;
&lt;p&gt;This is how a "machine" can keep running all of the time without "hanging" while some delay runs.  This is what I mean about not programming in a PC way. &lt;/p&gt;
&lt;p&gt;If you are still having issues, then specifically lay out what you are trying to do and someone will give you some code.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/?limit=25#711d" rel="alternate"/><published>2020-02-27T14:08:22.723000Z</published><updated>2020-02-27T14:08:22.723000Z</updated><author><name>Volvo742</name><uri>https://forge.codesys.com/u/volvo742/</uri></author><id>https://forge.codesys.com938ae20793d42804a43fcf58ea5fd2994902fb59</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;travlytle hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
I do something like the attached file:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Only one problem. &lt;br/&gt;
A PLC cannot wait/delay.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/?limit=25#a0d9" rel="alternate"/><published>2020-02-27T14:08:22.401000Z</published><updated>2020-02-27T14:08:22.401000Z</updated><author><name>travlytle</name><uri>https://forge.codesys.com/u/travlytle/</uri></author><id>https://forge.codesys.com5b3964fbe0562a8a15e4280ddccad18db1b1e769</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I do something like the attached file:&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: 2016" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=1976"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/?limit=25#c00b" rel="alternate"/><published>2020-02-27T14:08:22.035000Z</published><updated>2020-02-27T14:08:22.035000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com0839b18e3eee9fd78b4a57ab32897f1d41cda4a7</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;Your question hints at a problem I had when I started with IEC61131-3 programming.  If the following is already clear to you, I apologize in advance!&lt;/p&gt;
&lt;p&gt;IEC61131-3 is PLC style code.  That means the program loops over and over.  It is not like a PC program where the first line is the beginning and the last line is the end and it quits.  PLC code has a hidden forever loop outside of the main PLC_PRG program.  This means if you make a large FOR/NEXT or WHILE/WEND loop that takes too long, you will get a crash - basically a watch dog error.  It also means you don't want 20 tasks running at once with different priorities, because all of the tasks will always be called.&lt;/p&gt;
&lt;p&gt;I would suggest only starting with one task (PLC_PRG) and use the following in your PLC_PRG program:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;CASE&lt;/span&gt; &lt;span class="nv"&gt;Step&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt;
   &lt;span class="mi"&gt;0&lt;/span&gt;: &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;setup&lt;/span&gt;
      &lt;span class="nv"&gt;Setup&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;Setup&lt;/span&gt;.&lt;span class="nv"&gt;Done&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
         &lt;span class="nv"&gt;Step&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;IF&lt;/span&gt;
   &lt;span class="mi"&gt;1&lt;/span&gt;: &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;main&lt;/span&gt;
      &lt;span class="nv"&gt;DoMainWork&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
      
&lt;span class="nv"&gt;END_CASE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then your Setup program can step through what it needs to do over however many PLC scans (1 or 1000 calls).  When Done is set true, then the state machine moves to the main program and Setup is not called anymore.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/?limit=25#9018" rel="alternate"/><published>2020-02-27T14:08:21.048000Z</published><updated>2020-02-27T14:08:21.048000Z</updated><author><name>Volvo742</name><uri>https://forge.codesys.com/u/volvo742/</uri></author><id>https://forge.codesys.comed00a4791b9b10db330278eb5be5112c9734f8c9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;This will be like programming with arduino ?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/?limit=25#d057" rel="alternate"/><published>2020-02-27T14:08:20.650000Z</published><updated>2020-02-27T14:08:20.650000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com95f0db98fc50a6d8da56c5079076293009240a0d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;I do this with only one task. My main program (PLC_PRG) calls both my setup program and main program. There are several ways to do this, but here is one way:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;SetupCode&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;If&lt;/span&gt; &lt;span class="nv"&gt;NOT&lt;/span&gt; &lt;span class="nv"&gt;SetupCode&lt;/span&gt;.&lt;span class="nv"&gt;Done&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="k"&gt;RETURN&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;span class="nv"&gt;MainCode&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;MoreCode&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;p&gt;Your SetupCode program must be smart enough to set a Done output and stay there.&lt;/p&gt;
&lt;p&gt;There are other ways... Some people use a VAR_INPUT on every POU to Enable running the code instead of using a IF/THEN/RETURN like above... Some people use a state machine (CASE statement) with state 0 = setup, state 1 = run, etc&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How do i setup a setup task?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b45c58346a/?limit=25#4be3" rel="alternate"/><published>2020-02-27T14:08:20.288000Z</published><updated>2020-02-27T14:08:20.288000Z</updated><author><name>Volvo742</name><uri>https://forge.codesys.com/u/volvo742/</uri></author><id>https://forge.codesys.comd49f949b283d91412b45a66ae93203dc9a1df682</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;I have a task who call a program in my codesys. But i want other program run after the man setup program is finished? &lt;/p&gt;
&lt;p&gt;I sett the main setup program at prior #1 and after that program has finished, other program can now loop.&lt;/p&gt;
&lt;p&gt;How do i can figure that?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>