Motorized potentiometer in CoDeSys

razmis
2015-11-16
2015-11-30
  • razmis - 2015-11-16

    Is there a library that contains a function for motorized potentiometer?

     
  • Anonymous - 2015-11-30

    Originally created by: scott_cunningham

    Here is a FB you can use where the input priority is (reset, inc, dec) (I only lightly tested it - so double check it):

    FUNCTION_BLOCK MotorPot
    VAR_INPUT
       Inc   : BOOL := FALSE;
       Dec   : BOOL := FALSE;
       Reset : BOOL := FALSE;
       Rate  : REAL := 0.1;
    END_VAR
    VAR_OUTPUT
       Cmd : REAL;
    END_VAR
    VAR CONSTANT
       MIN_CMD : REAL := -100.0;
       MAX_CMD : REAL := 100.0;
    END_VAR
    IF Reset THEN
       Cmd := 0.0;
    ELSIF Inc THEN
       Cmd := MIN(Cmd + Rate, MAX_CMD);
    ELSIF Dec THEN
       Cmd := MAX(Cmd - Rate, MIN_CMD);
    END_IF
    
     

Log in to post a comment.