GVL,Persistent & Initial pulse

Ubbe
2013-10-16
2013-10-17
  • Ubbe - 2013-10-16

    Hi,

    First question:

    When I will create variables as VAR_GLOBAL RETAIN, where should I define them?
    I have tested in both GVL (Global Variable List) and in PersistentVar.
    When I compile I get now error for none of the placement, does this mean that I can have this defined in both of them?

    Second question:

    I'm looking for "Initial Pulse" which will be TRUE first scan. In Mitsubishi they have a special memory adress for this and for Siemens we can create this in OB100 which only run first scan.

    As I see it this is nothing that comes with codesys so we have to create this. But which is the best solution?
    I have several TASKs with different times set.
    Do I then have to create a Global variable (for each TASK) with initial value = TRUE and then in the last network for one of the POU:s connected to a specific TASK reset it (=FALSE)

    And then do the same fot the other TASK:s with a new Global Variable.

    Best regards
    Urban

     
  • t.lundahl - 2013-10-17

    Hi,

    Does your controller handle Retain/Persistent? I think all retain/persistent data shall be global.
    Do like this, have the option 'Autodeclare' activated. Create a variable some in POU and when you get the autodeclare window choose both Retain and Persistent options to the right and also choose GVL.

    Example for first scan in function block:
    IF EN AND NOT ENO THEN
    (First scan section)
    iState := 0;
    END_IF;

    IF ENO THEN
    (Your Code)
    END_IF;

    ENO:=EN;

     
  • Ubbe - 2013-10-17

    Thanks fot the answer.

    First of all my question about where to put RETAIN variables. I have read about this and in older version of codesys you don't have the this "PersistentVar" in which you define Persistent varables and then all variables will be defined in GVL.
    In 3.5 we have this "PersistentVar" and therefore you put them there. I noticed this when I put Persistent variables in GVL and compiled and get errors. Thats why I ask about RETAIN because I can define them in both GVL and PersistentVar.

    I tested to autodeclare as you suggested, and then I tested to create a REATAIN variabel just to see where it defines it, and it defines it in GVL so then I guess this is the correct place to define those.

    Best regards
    Urban

     

Log in to post a comment.