Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Set memory in SFC

Berben
2015-10-09
2015-10-09
  • Berben - 2015-10-09

    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?

    IMG: hiss.jpg

     
  • Anonymous - 2015-10-09

    Originally created by: scott_cunningham

    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.

     
  • Berben - 2015-10-09

    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?

     
  • TimvH

    TimvH - 2015-10-09

    First of all I agree with you that this is not what you would expect, but ...

    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).
    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.

    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.
    Maybe others have better suggestions...

     
  • Anonymous - 2015-10-09

    Originally created by: scott_cunningham

    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:

    PROGRAM HissNer
    VAR_INPUT
    Β  Β  SfcInStep0 : BOOL := FALSE;
    Β  Β  LdVaning : BOOL := FALSE;
    END_VAR
    VAR_OUTPUT
    Β  Β  xTrue : BOOL := FALSE;
    END_VAR
    xTrue := SfcInStep0 AND NOT(LdVaning);
    

    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.

     

Log in to post a comment.