CONT_S (FB42) Step control

: 2009-10-15

: komatic

: PIDcontrol

ICONT CONT_S (FB42) .

, . STL - .

:
english - download .pdf 0.3
- .pdf 0.3

CONT_S

FUNCTION_BLOCK FB42
TITLE =" PID step controller"
AUTHOR : SIMATIC
FAMILY : ICONT
NAME : CONT_S
VERSION : " 1.5"
// reversed by komatic
VAR_INPUT
COM_RST : BOOL ; //
LMNR_HS : BOOL ; //high limit signal of repeated manipulated value
LMNR_LS : BOOL ; //low limit signal of repeated manipulated value
LMNS_ON : BOOL ; //manipulated signals on
LMNUP : BOOL ; //manipulated signal up
LMNDN : BOOL ; //manipulated signal down
PVPER_ON : BOOL ; //
CYCLE : TIME := T#1S; //
SP_INT : REAL ; //
PV_IN : REAL ; //
PV_PER : WORD ; // ,
GAIN : REAL := 2.000000e+000; //
TI : TIME := T#20S; //
DEADB_W : REAL := 1.000000e+000; //dead band width
PV_FAC : REAL := 1.000000e+000; //
PV_OFF : REAL ; //
PULSE_TM : TIME := T#3S; //minimum pulse time
BREAK_TM : TIME := T#3S; //minimum break time
MTR_TM : TIME := T#30S; //motor manipulated value
DISV : REAL ; //
END_VAR
VAR_OUTPUT
QLMNUP : BOOL ; //manipulated signal up
QLMNDN : BOOL ; //manipulated signal down
PV : REAL ; //process variable
ER : REAL ; //error signal
END_VAR
VAR
LMNRS_ON : BOOL ;
LMNRSVAL : REAL ;
LMNR_SIM : REAL ;
sFbPVal : REAL ;
sThrOn : REAL ;
siImpAus : INT ;
stImpDauer : TIME ;
stPausDauer : TIME ;
END_VAR
VAR_TEMP
Hvar : REAL ; //
rCycle : REAL ; //Abtastzeit in real
Istwert : REAL ; //Istwert
ErKp : REAL ; //
rTi : REAL ; // real
AdapIn1 : REAL ; //Eingang 1 der Adaption der Ansprechschwelle
AdapIn2 : REAL ; //Eingang 2 der Adaption der Ansprechschwelle
iImpEin : INT ; //Eingang des Impulsformers
rMtrTm : REAL ; //Motorstellzeit in real
rThrOff : REAL ; //Abschaltschwelle
dInteg : REAL ; //Eingang des Integrierers in der Rckfhrung
dThrStIn : REAL ; //three-step element input
LmnrSim : REAL ; //simulierte Stellungsrckmeldung
END_VAR
BEGIN
IF COM_RST //
THEN
LMNR_SIM:=LMNRSVAL;
QLMNUP:=0;
QLMNDN:=0;
PV:=0.0;
ER:=0.0;
LMNRS_ON:=0;
LMNRSVAL:=0.0;
LMNR_SIM:=0.0;
sFbPVal:=0.0;
sThrOn:=0.0;
siImpAus:=0;
stImpDauer:=T#0MS;
stPausDauer:=T#0MS;
ELSE
Istwert:=INT_TO_REAL(WORD_TO_INT(PV_PER))*3.616898e-003;
Istwert:=Istwert*PV_FAC+PV_OFF;
IF NOT PVPER_ON THEN Istwert:=PV_IN; END_IF;
PV:=Istwert;
ErKp:=SP_INT-PV;
IF ErKp < (-DEADB_W) THEN ER:=ErKp+DEADB_W;
ELSIF ErKp>DEADB_W THEN ER:=ErKp-DEADB_W;
ELSE ER:=0.0; END_IF;
ErKp:=ER*GAIN;
rCycle:=DINT_TO_REAL(TIME_TO_DINT(CYCLE))/1000.0;
rTi:=DINT_TO_REAL(TIME_TO_DINT(TI))/1000.0;
IF rTi<rCycle*0.5 THEN rTi:=rCycle*0.5; END_IF;
rMtrTm:=DINT_TO_REAL(TIME_TO_DINT(MTR_TM))/1000.0;
Hvar:=rTi-ABS(0.01*ErKp*rMtrTm);
IF Hvar<(rTi*0.1)THEN rTi:=rTi*0.1; ELSE rTi:=Hvar; END_IF;
IF LMNS_ON
THEN
sFbPVal:=0.0;
ELSE
IF siImpAus<>0
THEN
dInteg:=DINT_TO_REAL(INT_TO_DINT(siImpAus))*rCycle/rMtrTm;
ELSE
IF (ErKp>0.0 AND LMNR_HS) OR (ErKp<0.0 AND LMNR_LS) OR (TI=T#0MS)
THEN
dInteg:=0.0;
ELSE
dInteg := (-ErKp)*rCycle/rTi;
END_IF;
END_IF;
sFbPVal:=sFbPVal+dInteg;
IF TI=T#0MS
THEN
IF sFbPVal>100.0 THEN sFbPVal:=100.0;
ELSIF sFbPVal<0.0 THEN sFbPVal:=0.0;
END_IF;
END_IF;
END_IF;
dThrStIn:=ErKp-sFbPVal+DISV;
AdapIn1:=ErKp;
AdapIn2:=sFbPVal;
rThrOff:=55.0/rMtrTm*rCycle;
IF PULSE_TM>CYCLE
THEN
Hvar:=DINT_TO_REAL(TIME_TO_DINT(PULSE_TM))/1000.0;
ELSE
Hvar:=rCycle;
END_IF;
Hvar:=100.0*Hvar/rMtrTm;
IF NOT(LMNR_HS OR LMNR_LS)
THEN
IF NOT (QLMNUP OR QLMNDN)
THEN
IF TI<>T#0MS
THEN
IF ABS(AdapIn1)<ABS(AdapIn2)
THEN
sThrOn:=AdapIn1;
ELSE
sThrOn:=AdapIn2;
END_IF;
ELSE
IF Istwert=0.0
THEN
sThrOn:=Hvar;
ELSE
sThrOn:=ABS(ErKp)*0.5;
END_IF;
END_IF;
IF sThrOn>10.0 THEN sThrOn:=10.0; END_IF;
IF sThrOn<Hvar THEN sThrOn:=Hvar; END_IF;
END_IF;
ELSE
sThrOn:=Hvar;
END_IF;
IF (siImpAus=100 AND dThrStIn>rThrOff) OR (dThrStIn>=sThrOn) THEN iImpEin:=100;
ELSIF (siImpAus=-100 AND dThrStIn<(-rThrOff)) OR (dThrStIn<=(-sThrOn)) THEN iImpEin:=-100;
ELSE iImpEin:=0;
END_IF;
IF LMNS_ON
THEN
IF LMNUP XOR LMNDN
THEN
IF LMNUP
THEN
iImpEin:=100;
ELSE
iImpEin:=-100;
END_IF;
ELSE
iImpEin:=0;
END_IF;
END_IF;
IF (iImpEin=100 AND LMNR_HS) OR (iImpEin=-100 AND LMNR_LS) THEN iImpEin:=0; END_IF;
IF (siImpAus=-100 AND iImpEin=100) OR (siImpAus=100 AND iImpEin=-100)THEN iImpEin:=0; END_IF;
IF siImpAus<>iImpEin
THEN
IF iImpEin=0
THEN
IF stImpDauer<=T#0MS
THEN
siImpAus:=0;
stPausDauer:=BREAK_TM;
END_IF;
ELSE
siImpAus:=iImpEin;
stImpDauer:=PULSE_TM;
END_IF;
END_IF;
IF stImpDauer>T#0MS
THEN
stImpDauer:=stImpDauer-CYCLE;
ELSE
stImpDauer:=T#0MS;
END_IF;
IF stPausDauer>T#0MS
THEN
stPausDauer:=stPausDauer-CYCLE;
ELSE
stPausDauer:=T#0MS;
END_IF;
IF ((siImpAus=100) AND LMNR_HS) OR ((siImpAus=-100) AND LMNR_LS)
THEN
siImpAus:=0;
stImpDauer:=T#0MS;
END_IF;
IF NOT LMNRS_ON
THEN
LmnrSim:=LMNRSVAL;
ELSE
LmnrSim:=DINT_TO_REAL(INT_TO_DINT(siImpAus))*rCycle/rMtrTm+LMNR_SIM;
IF LmnrSim>=100.0
THEN
LmnrSim:=100.0;
ELSIF LmnrSim<=0.0
THEN
LmnrSim:=0.0;
END_IF;
END_IF;
LMNR_SIM:=LmnrSim;
IF siImpAus=0
THEN
QLMNUP:=0;
QLMNDN:=0;
ELSIF siImpAus=100
THEN
QLMNUP:=1;
QLMNDN:=0;
ELSE
QLMNUP:=0;
QLMNDN:=1;
END_IF;
END_IF;
END_FUNCTION_BLOCK





: 16078

:     : 2012-01-16

FB42?

: komatic    : 2012-01-16

, ?

:     : 2012-07-12

, :

rMtrTm:=DINT_TO_REAL(TIME_TO_DINT(MTR_TM));

1000 , FB42 ( ):

rMtrTm:=DINT_TO_REAL(TIME_TO_DINT(MTR_TM))/1000.0;

: komatic    : 2012-07-12

, , , .

: Denis    : 2012-11-28

, BREAK_TM ? stPausDauer . stPausDauer .

: canada    : 2014-03-05

S7-1200 6- , .

: XHunter    : 2015-02-11

, , ? MTR_TM,

: mansun    : 2017-01-27

MTR_TM,TI GAIN ( ), stImpDauer stPausDauer. DO , . , , ? , -

Hvar:=rTi-ABS(0.01*ErKp*rMtrTm);
. , .

: mansun    : 2017-01-29

, , - STEP7 CODESYS, S300 STEP7 - .
- ((, (**))

IF (**)((**)(siImpAus=100 AND dThrStIn>rThrOff) OR (dThrStIn>=sThrOn)(**)) AND stPausDauer<=T#0MS (**) THEN iImpEin:=100;
ELSIF (**)((**)(siImpAus=-100 AND dThrStIn<(-rThrOff)) OR (dThrStIn<=(-sThrOn)) (**)) AND stPausDauer<=T#0MS (**) THEN iImpEin:=-100;
ELSE iImpEin:=0;

CODESYS . . , . , ?

: glu    : 2017-09-06

( COM_RST = TRUE):
LMNR_SIM:=LMNRSVAL;
, 6 :
LMNR_SIM:=0.0;

:

(4000 max):

: