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

Initialize PID in Structured Text

Dr. No
2021-04-27
2021-04-27
  • Dr. No

    Dr. No - 2021-04-27

    In B&R Automation Studio, the initialization would be something like:

    PROGRAM _INIT
    (* PID parameters *)
        PID_FrwBack.PIDParameters.Gain := 0.5;
        PID_FrwBack.PIDParameters.IntegrationTime := 0.7;
        PID_FrwBack.PIDParameters.DerivativeTime := 0.3;
        PID_FrwBack.PIDParameters.FilterTime := 0.03;
    END_PROGRAM
    
    PROGRAM _CYCLIC
        // -------------------------------------------------
        // PID_FrwBack - Forwart/Backwart PID Controller 
        // -------------------------------------------------
        PID_FrwBack.SetValue := iSetVal;
        PID_FrwBack.ActValue := iActVal; // Actual Value
    
        (* call function block *)
        PID_FrwBack();
    
        // Controller Output
        iDrive := PID_FrwBack.Out;
        // -------------------------------------------------
    

    How can I do this in Codesys? Is there also some kind of Program _Init section?

     

    Last edit: Dr. No 2021-04-27
  • Dr. No

    Dr. No - 2021-04-27

    OK, it's actually quite easy. If I'm not mistaken one has to do the initialization in the "Var" Section, like

    VAR
        PID_FrwBack: Ctrl.Controller_PID := (lrKP := 10);
    END_VAR
    
     

Log in to post a comment.