<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Set memory in SFC</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/</id><updated>2020-02-27T13:48:34.648000Z</updated><subtitle>Recent posts to Set memory in SFC</subtitle><entry><title>Set memory in SFC</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/?limit=25#071a" rel="alternate"/><published>2020-02-27T13:48:34.648000Z</published><updated>2020-02-27T13:48:34.648000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comd5a4827df8c45db747e68a27454407797f2c8176</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;Yes, controlling a global variable from more than one program is a general thing to avoid as this makes debugging very difficult.  You may be best to move away from S/R on variables that many POUs access.  You can make a program that runs in your PLC_PRG as a replacement for your global variable, which controls the state based on information from the SFC and the LD.  Something like:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;PROGRAM&lt;/span&gt; &lt;span class="n"&gt;HissNer&lt;/span&gt;
&lt;span class="n"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;SfcInStep0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BOOL&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;LdVaning&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BOOL&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;span class="n"&gt;VAR_OUTPUT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;xTrue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BOOL&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;span class="n"&gt;xTrue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SfcInStep0&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LdVaning&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You will need to make VAR_OUTPUTS in the SFC program (output true when in step 0) and the LD program (true when vaning).  In you main PLC_PRG, add a line/rung call to: HissNer(SfcInStep0:=SFC.outputvar, LdVaning:=LD.outputvar).  Now, you don't need gmHissNer... you can just use HissNer.xTrue instead.  You can see what is used to determine TRUE/FALSE - much simpler for troubleshooting and testing.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Set memory in SFC</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/?limit=25#b16e" rel="alternate"/><published>2020-02-27T13:48:34.541000Z</published><updated>2020-02-27T13:48:34.541000Z</updated><author><name>timvh</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.com60b77b6d340bc379fd02a1197bd9bb0cf25206d8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;First of all I agree with you that this is not what you would expect, but ...&lt;/p&gt;
&lt;p&gt;It is a general advise not to use Global Variables when this can be avoided and if you use them, don't write to them from multiple POU's (only write in one and read in all).&lt;br/&gt;
With very small applications this is not so very important, but the bigger the application, the more problems you will get to keep the application stable.&lt;/p&gt;
&lt;p&gt;I'm not sure what the best solution is for your specific application, but an idea could be to read the state of Vaning1 in your SFC and then reset gmHissNer in the SFC.&lt;br/&gt;
Maybe others have better suggestions...&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Set memory in SFC</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/?limit=25#b4da" rel="alternate"/><published>2020-02-27T13:48:34.441000Z</published><updated>2020-02-27T13:48:34.441000Z</updated><author><name>Berben</name><uri>https://forge.codesys.com/u/berben/</uri></author><id>https://forge.codesys.com3e7c6dc922d744d849fdce5b7ffe97356720eca2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thank you for your answer. It seems like the SFC POU keeps setting the global memory even though the Step is no longer active and will continue doing so until a reset of the memory is activated within the same SFC POU. Is this something I just have to accept or is there any configuration I can do to changes this?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Set memory in SFC</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/?limit=25#09b1" rel="alternate"/><published>2020-02-27T13:48:34.299000Z</published><updated>2020-02-27T13:48:34.299000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com2ad139f1fae5f7e4441658bc0bd8c9ab8f7b6f95</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 don't think the problem is because of SFC directly. My feeling is the two programs - are stomping on each other about this global variable. Maybe because of execution order, or.... Many things are built up and occur behind the scenes with SFC, even for a basic one step program. Try a simple one step SFC program and a simple one line LD with the one global variable and step through the program with the debugger to see what you find.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Set memory in SFC</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0ac054fcc2/?limit=25#ab00" rel="alternate"/><published>2020-02-27T13:48:34.231000Z</published><updated>2020-02-27T13:48:34.231000Z</updated><author><name>Berben</name><uri>https://forge.codesys.com/u/berben/</uri></author><id>https://forge.codesys.com423705142d6f47207f05d841874c5a3819552d93</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I want to set a global memory in a POU SFC diagram and reset it in a POU Ladder but it won't work.  It works fine when both POUs are Ladder but not when one of them is SFC, why?&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: hiss.jpg" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=1346"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>