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.

Controlling a Traffic Signal Unit...<br />

"WAIT" declaration<br />

Now let us turn to the POU WAIT. This POU is supposed to become a timer with which we can<br />

determine the length of the time period of each TRAFFICSIGNAL phase. Our POU receives as input<br />

variable a variable TIME of the type TIME, and as output it produces a Boolean value which we want<br />

to call OK and which should be TRUE when the desired time period is finished. We set this value with<br />

FALSE by inserting at the end of the declaration (before the semicolon, however) " := FALSE ".<br />

For our purposes we need the POU TP, a clock generator. This has two inputs (IN, PT) and two<br />

outputs (Q, ET). TP does the following:<br />

As long as IN is FALSE, ET is 0 and Q is FALSE. As soon as IN provides the value TRUE, the time is<br />

calculated at the output ET in milliseconds. When ET reaches the value PT, then ET is no longer<br />

counted. Meanwhile Q produces TRUE as long as ET is smaller than PT. As soon as the value PT<br />

has been reached, then Q produces FALSE again. See the chapter on the standard library for short<br />

descriptions of all POUs.<br />

In order to use the POU TP in the POU WAIT we must create a local instance from TP. For this we<br />

declare a local variable ZAB (for elapsed time) of the type TP (between the keywords VAR,<br />

END_VAR).<br />

The declaration part of WAIT thus looks like this:<br />

Function Block WAIT, Declaration Part<br />

"WAIT" body<br />

In order to create the desired timer, the body of the POU must be programmed as follows:<br />

Function Block WAIT, Instruction Part<br />

3-4 CoDeSys V2.3

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

Saved successfully!

Ooh no, something went wrong!