CTUDΒΆ

Provided by Standard Library.

Function block working as incrementer and decrementer.

Inputs:

CU : BOOL; With each rising edge at this input the counter value (CV) is incremented by 1. When CV reaches or exceeds PV, QU will be set to TRUE.

CD : BOOL; With each rising edge at this input the counter value (CV) is decremented by 1 until 0 is reached.

RESET : BOOL; If TRUE, CV will be set to 0.

LOAD : BOOL; if TRUE, CV will be set to PV.

PV : WORD; upper limit and accordingly start value for incrementing or decrementing CV.

Attention

Datatype WORD, which is used for PV in CODESYS, does not match the IEC standard, which for PV defines datatype INT.

Outputs:

QU : BOOL; returns TRUE when CV has been incremented to >= PV.

QD : BOOL; returns TRUE when CV has been decremented to 0.

CV : WORD; Contains the value to be incremented or decremented; will be initialized with 0 if RESET is TRUE; will be raised by 1 always when CU gets a rising edge from FALSE to TRUE; will be lowered by 1 always when CD gets a falling edge from TRUE to FALSE, provided this does not cause the value to fall below 0.

Declaration example:\ \ \ \

CTUDInst : CUTD ;

Example in IL:\ \ \ \

../_images/20bdc2f91e8f796ec0a8640e01947982

Example in FBD:

../_images/4d53c8661e8f78bfc0a8640e01947982

Example in ST:\ \ \ \

CTUDInst(CU := VarBOOL1, CD:= VarBOOL2, RESET := VarBOOL3, LOAD:=VarBOOL4 , PV:= VarWORD1);

VarBOOL5 := CTUDInst.QU ;
VarBOOL6 := CTUDInst.QD ;
VarWORD2 := CTUDInst.CV;