24.01.2015 Views

PLC Programming

  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

What is What in CoDeSys<br />

WHILE <br />

<br />

END_WHILE;<br />

The are repeatedly executed as long as the returns TRUE. If<br />

the is already FALSE at the first evaluation, then the are never<br />

executed. If never assumes the value FALSE, then the are<br />

repeated endlessly which causes a relative time delay.<br />

Note:<br />

The programmer must make sure that no endless loop is caused. He does this by changing the<br />

condition in the instruction part of the loop, for example, by counting up or down one counter.<br />

REPEAT loop<br />

Example:<br />

WHILE counter0 DO<br />

Var1 := Var1*2;<br />

Counter := Counter-1;<br />

END_WHILE<br />

The WHILE and REPEAT loops are, in a certain sense, more powerful than the FOR loop since one<br />

doesn't need to know the number of cycles before executing the loop. In some cases one will,<br />

therefore, only be able to work with these two loop types. If, however, the number of the loop cycles is<br />

clear, then a FOR loop is preferable since it allows no endless loops.<br />

The REPEAT loop is different from the WHILE loop because the break-off condition is checked only<br />

after the loop has been executed. This means that the loop will run through at least once, regardless<br />

of the wording of the break-off condition.<br />

Syntax:<br />

REPEAT<br />

<br />

UNTIL <br />

END_REPEAT;<br />

The are carried out until the returns TRUE.<br />

If is produced already at the first TRUE evaluation, then are<br />

executed only once. If never assumes the value TRUE, then the<br />

are repeated endlessly which causes a relative time delay.<br />

Note:<br />

The programmer must make sure that no endless loop is caused. He does this by changing the<br />

condition in the instruction part of the loop, for example by counting up or down one counter.<br />

Example:<br />

REPEAT<br />

Var1 := Var1*2;<br />

Counter := Counter-1;<br />

UNTIL<br />

Counter=0<br />

EXIT instruction<br />

END_REPEAT;<br />

If the EXIT instruction appears in a FOR, WHILE, or REPEAT loop, then the innermost loop is ended,<br />

regardless of the break-off condition.<br />

CoDeSys V2.3 2-15

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

Saved successfully!

Ooh no, something went wrong!