Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
158
Добавлен:
11.10.2020
Размер:
2.81 Mб
Скачать

Appendix D: - The CoDeSys Libaries

10.16.3 Trigger...

R_TRIG

The function block R_TRIG detects a rising edge.

FUNCTION_BLOCK R_TRIG

VAR_INPUT

CLK : BOOL;

END_VAR

VAR_OUTPUT

Q : BOOL;

END_VAR

VAR

M : BOOL := FALSE;

END_VAR

Q := CLK AND NOT M;

M := CLK;

The output Q0 and the help variable M will remain FALSE as long as the input variable CLK is FALSE. As soon as S1 returns TRUE, Q will first return TRUE, then M will be set to TRUE. This means each time the function is called up, Q will return FALSE until CLK has falling edge followed by an rising edge.

Declaration example:

RTRIGInst : R_TRIG ;

Example in IL:

CAL RTRIGInst(CLK := VarBOOL1)

LD RTRIGInst.Q

ST VarBOOL2

Example in FBD:

Example in ST:

RTRIGInst(CLK:= VarBOOL1);

VarBOOL2 := RTRIGInst.Q;

F_TRIG

The function block F_TRIG a falling edge.

FUNCTION_BLOCK F_TRIG

VAR_INPUT

CLK: BOOL;

END_VAR

VAR_OUTPUT

Q: BOOL;

END_VAR

VAR

M: BOOL := FALSE;

END_VAR

Q := NOT CLK AND NOT M;

M := NOT CLK;

10-44

CoDeSys V2.3

Appendix D: - The CoDeSys Libaries

The output Q and the help variable M will remain FALSE as long as the input variable CLK returns TRUE. As soon as CLK returns FALSE, Q will first return TRUE, then M will be set to TRUE. This means each time the function is called up, Q will return FALSE until CLK has a rising followed by a falling edge.

Declaration example:

FTRIGInst : F_TRIG ;

Example in IL:

CAL FTRIGInst(CLK := VarBOOL1)

LD FTRIGInst.Q

ST VarBOOL2

Example in FBD:

Example in ST:

FTRIGInst(CLK:= VarBOOL1);

VarBOOL2 := FTRIGInst.Q;

10.16.4 Counter...

CTU

Function block Incrementer:

The input variables CU and RESET as well as the output variable Q are type BOOL, the input variable PV and the output variable CV are type INT.

The counter variable CV will be initialized with 0 if RESET is TRUE. If CU has a rising edge from FALSE to TRUE, CV will be raised by 1.Q will return TRUE when CV is greater than or equal to the upper limit PV.

Declaration example:

CTUInst : CTU ;

Example in IL:

CAL

CTUInst(CU := VarBOOL1, RESET := VarBOOL2, PV := VarINT1)

LD

CTUInst.Q

ST

VarBOOL3

LD

CTUInst.CV

ST

VarINT2

Example in FBD:

Example in ST:

CTUInst(CU:= VarBOOL1, RESET:=VarBOOL2 , PV:= VarINT1);

VarBOOL3 := CTUInst.Q ;

VarINT2 := CTUInst.CV;

CoDeSys V2.3

10-45

Appendix D: - The CoDeSys Libaries

CTD

Function Block Decrementer:

The input variables CD and LOAD as well as the output variable Q are type BOOL, the input variable PV and the output variable CV are type INT.

When LOAD_ is TRUE, the counter variable CV will be initialized with the upper limit PV. If CD has a rising edge from FALSE to TRUE, CV will be lowered by 1 provided CV is greater than 0 (i.e., it doesn't cause the value to fall below 0).

Q returns TRUE when CVis equal 0. Declaration example:

CTDInst : CTD ;

Example in IL:

CAL

CTDInst(CD := VarBOOL1, LOAD := VarBOOL2, PV := VarINT1)

LD

CTDInst.Q

ST

VarBOOL3

LD

CTDInst.CV

ST

VarINT2

Example in FBD:

Example in ST:

CTDInst(CD:= VarBOOL1, LOAD:=VarBOOL2 , PV:= VarINT1);

VarBOOL3 := CTDInst.Q ;

VarINT2 := CTDInst.CV;

CTUD

Function Block Incrementer/Decrementer

The input variables CU, CD, RESET, LOAD as well as the output variables QU and QD are type BOOL, PV and CV are type INT.

If RESET is valid, the counter variable CV will be initialized with 0. If LOAD is valid, CV will be initialized with PV.

If CU has a rising edge from FALSE to TRUE, CV will be raised by 1. If CD has a rising edge from FALSE to TRUE, CV will be lowered by 1 provided this does not cause the value to fall below 0.

QU returns TRUE when CV has become greater than or equal to PV. QD returns TRUE when CV has become equal to 0.

Declaration example:

CTUDInst : CUTD ;

Example in IL:

CAL

CTUDInst(CU:=VarBOOL2, RESET:=VarBOOL3, LOAD:=VarBOOL4, PV:=VarINT1)

LD

CTUDInst.Q

ST

VarBOOL5

LD

CTUDInst.QD

ST

VarBOOL5

LD

CTUInst.CV

ST

VarINT2

10-46

CoDeSys V2.3

Appendix D: - The CoDeSys Libaries

Example in FBD:

Example in ST:

CTUDInst(CU := VarBOOL1, CU:= VarBOOL2, RESET := VarBOOL3, LOAD:=VarBOOL4 , PV:=

VarINT1);

VarBOOL5 := CTUDInst.QU ;

VarBOOL6 := CTUDInst.QD ;

VarINT2 := CTUDInst.CV;

10.16.5 Timer...

TP

The function block Timer is a trigger. TP(IN, PT, Q, ET) means:

IN and PT are input variables of the BOOL and TIME types respectively. Q and ET are output variables of the BOOL and TIME types respectively. If IN is FALSE, Q is FALSE and ET is 0.

As soon as IN becomes TRUE, the time will begin to be counted in milliseconds in ET until its value is equal to PT. It will then remain constant.

Q is TRUE if IN is TRUE and ET is less than or equal to PT. Otherwise it is FALSE. Q returns a signal for the time period given in PT.

Graphic Display of the TP Time Sequence

Declaration example:

TPInst : TP ;

Example in IL:

CAL TPInst(IN := VarBOOL1, PT := T#5s)

LD TPInst.Q

ST VarBOOL2

Example in FBD:

CoDeSys V2.3

10-47

Appendix D: - The CoDeSys Libaries

Example in ST:

TPInst(IN := VarBOOL1, PT:= T#5s);

VarBOOL2 :=TPInst.Q;

TON

The function block Timer On Delay implements a turn-on delay.. TON(IN, PT, Q, ET) means:

IN and PT are input variables of the BOOL and TIME types respectively. Q and ET are output variables of the BOOL and TIME types respectively. If IN is FALSE, Q is FALSE and ET is 0.

As soon as IN becomes TRUE, the time will begin to be counted in milliseconds in ET until its value is equal to PT. It will then remain constant.

Q is TRUE when IN is TRUE and ET is equal to PT. Otherwise it is FALSE.

Thus, Q has a rising edge when the time indicated in PT in milliseconds has run out. Graphic display of TON behaviour over time:

Declaration example:

TONInst : TON ;

Example in IL:

CAL TONInst(IN := VarBOOL1, PT := T#5s)

LD TONInst.Q

ST VarBOOL2

Example in FBD:

Example in ST:

TONInst(IN := VarBOOL1, PT:= T#5s);

TOF

The function block TOF implements a turn-off delay..

TOF(IN, PT, Q, ET) means:

10-48

CoDeSys V2.3

Appendix D: - The CoDeSys Libaries

IN and PT are input variables type BOOL respectively TIME. Q and E are output variables type BOOL respectively TIME. If IN is TRUE, the outputs are TRU respectively 0.

As soon as IN becomes FALSE, in ET the time will begin to be counted in milliseconds in ET until its value is equal to PT. It will then remain constant.

Q is FALSE when IN is FALSE und ET equal PT. Otherwise it is TRUE.

Thus, Q has a falling edge when the time indicated in PT in milliseconds has run out. Graphic display of TOF behaviour over time:

Declaration example:

TOFInst : TOF ;

Example in IL:

CAL TOFInst(IN := VarBOOL1, PT := T#5s)

LD TOFInst.Q

ST VarBOOL2

Example in FBD:

Example in ST:

TOFInst(IN := VarBOOL1, PT:= T#5s);

VarBOOL2 :=TOFInst.Q;

RTC

The function block Runtime Clock returns, starting at a given time, the current date and time.

RTC(EN, PDT, Q, CDT) means:

EN and PDT are input variables type TIME. Q and CDT are output variables type BOOL respectively DATE_AND_TIME. When EN is FALSE, the output variables Q und CDT are FALSE respectively DT#1970-01-01-00:00:00.

As soon as EN becomes TRUE, the time of PDT is set, is counted up in seconds and returned in CDT as long as EN is TRUE (see example in the picture above). As soon as EN is reset to FALSE, CDT is

CoDeSys V2.3

10-49

Соседние файлы в папке 759-333