24.01.2015 Views

PLC Programming

  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix D: CoDeSys Libraries<br />

Declaration example:<br />

TOFInst : TOF ;<br />

Example in IL:<br />

CAL<br />

LD<br />

ST<br />

TOFInst(IN := VarBOOL1, PT := T#5s)<br />

TOFInst.Q<br />

VarBOOL2<br />

Example in FBD:<br />

Example in ST:<br />

TOFInst(IN := VarBOOL1, PT:= T#5s);<br />

VarBOOL2 :=TOFInst.Q;<br />

RTC<br />

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

RTC(EN, PDT, Q, CDT) means:<br />

EN and PDT are input variables type TIME. Q and CDT are output variables type BOOL respectively<br />

DATE_AND_TIME. When EN is FALSE, the output variables Q und CDT are FALSE respectively<br />

DT#1970-01-01-00:00:00.<br />

As soon as EN becomes TRUE, the time of PDT is set, is counted up in seconds and returned in CDT<br />

as long as EN is TRUE (see example in the picture above). As soon as EN is reset to FALSE, CDT is<br />

reset to the initial value DT#1970-01-01-00:00:00. Please note that the time in PDT is only set by a<br />

rising edge.<br />

10.17 The Util.lib library<br />

This library contains an additional collection of various blocks which can be used for BCD conversion,<br />

bit/byte functions, mathematical auxiliary functions, as controller, signal generators, function<br />

manipulators and for analogue value processing.<br />

As some of the functions and function blocks contain REAL variables, an accessory library named<br />

UTIL_NO_REAL exists in which these POUs are excluded.<br />

10.17.1 BCD Conversion<br />

A byte in the BCD format contains integers between 0 and 99. Four bits are used for each decimal<br />

place. The ten decimal place is stored in the bits 4-7. Thus the BCD format is similar to the<br />

hexadecimal presentation, with the simple difference that only values between 0 and 99 can be stored<br />

in a BCD byte, whereas a hexadecimal byte reaches from 0 to FF.<br />

An example: The integer 51 should be converted to BCD format. 5 in binary is 0101, 1 in binary is<br />

0001, which makes the BCD byte 01010001, which corresponds to the value $51=81.<br />

CoDeSys V2.3 10-51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!