```pascal FUNCTION "SpeedAdjust" : Real { S7_Optimized_Access := 'FALSE' } AUTHOR : 'Author' FAMILY : 'Function' NAME : 'Name' VERSION : 1.0 VAR_INPUT i_PrdTnkLvl : Real; i_TrgTnkLvl : Real; i_IstLvl : Real; i_SpeedPerc : Real; END_VAR VAR_TEMP m_SpeedPerc : Real; a : Real; // Angolar Coefficient b : Real; // Constant mCalc : Real; END_VAR BEGIN // The following function calculates the percentage speed correction to get Product Tank target Level // the equation used is: y = a * PrdTankLvl + b ; that is a = - SpeedPerc / IstLvl; and b = 1 - TrgTnkLvl * a // the function yelds 1.0 at 50% of level; (1 - SpeedPerc) at 80% level; the maximum is (1 + SpeedPerc) #m_SpeedPerc := #i_SpeedPerc / 100 ; IF #i_IstLvl > 0 THEN #a := -#m_SpeedPerc / #i_IstLvl ; #b := 1 - (#a * #i_TrgTnkLvl) ; #mCalc := #a * #i_PrdTnkLvl + #b ; #SpeedAdjust := LIMIT(MN:=1 - #m_SpeedPerc,IN:= #mCalc ,MX:= 1 + #m_SpeedPerc) ; ELSE (* classic code: #SpeedAdjust := 0.0 ;*) #SpeedAdjust := REAL#0.0 ; END_IF; END_FUNCTION ```