Vai al contenuto

Problem with RETAIN variables

Home Forum Controllori SlimLine e Netsyst (LogicLab) Problem with RETAIN variables

Stai visualizzando 3 post - dal 1 a 3 (di 3 totali)
  • Autore
    Post
  • #35191
    Bart
    Partecipante

    In a program, I use the RETAIN variables to store some counters, but when I switch off the system and switch it on again, all the RETAIN the variables are all set to 0.

    Here an abstract of my program in which is detailed what I do (Project download).

    #37189
    Sergio Bertana
    Amministratore del forum

    In the PR_Almaclean program, it’s used your own FB (Count_marche) to manage the RETAIN variable Alma_M_Count and this it isn’t correct.

    The Count_marche FB, copies its internal value of Count to the variable Count_marche. So when you start the program the value of Count is 0 and this value is copied to the Count_marche variable, this resets its retained value.

    When a FB has to manage RETAIN variables, a pointer must be used, so the FB can directly manage the variable value. In this way when the system is powered, all the RETAIN variables are set to their stored values, and when the FB has to manage them it manages their real values. Here your program modified by using the pointer in a FB (Download program).

    #37190
    Sergio Bertana
    Amministratore del forum

    Now some suggestions for your program.

    In the Count_marche FB you use the R_TRIG FB, but is easiest to detect the raising edge of Start input, directly in the FB by using a memo variable. Here the code:

    IF (Start <> Pulse) THEN
      Pulse:=Start; (* Pulse on trigger *)
      IF (Start) THEN @Var:=@Var+1; END_IF;
    END_IF;

    In the ladder program you can use the Almaclean input as a normal contact, the -]P[- contact must be used if the FB doesn’t control the raising edge.

    If the FB that have at least an output, you can avoid the EN/ENO junctions by deselecting the EN/ENO icon in the FBD toolbar.

    In the ADR function to avoid the EN/ENO junctions, you can put the function in the ladder and then by using the right button of the mouse select the Properties menu, and deselect the EN/ENO tick.

    Don’t use Network label to comment the ladder rung. There is the Comment icon (*-*) to insert comments in the ladder. The Network label must be used to reach ladder rung in Jump instructions.

    You can download a source program modified.

Stai visualizzando 3 post - dal 1 a 3 (di 3 totali)
  • Devi essere connesso per rispondere a questo topic.