12.05.2014 Views

Automating Manufacturing Systems - Process Control and ...

Automating Manufacturing Systems - Process Control and ...

Automating Manufacturing Systems - Process Control and ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

plc advanced functions - 16.11<br />

program file 2<br />

A<br />

JSR (Jump subroutine)<br />

Program File 3<br />

Input par N7:0<br />

Input par 123<br />

Return par N7:1<br />

A separate ladder logic program is stored in program file 3. This feature<br />

allows users to create their own functions. In this case if A is<br />

true, then the program below will be executed <strong>and</strong> then when done<br />

the ladder scan will continue after the subroutine instruction. The<br />

number of data values passed <strong>and</strong> returned is variable.<br />

SBR (subroutine arguments)<br />

Input par N10:0<br />

Input par N10:1<br />

program file 3<br />

If B is true the subroutine will return <strong>and</strong> the values listed will be<br />

returned to the return par. For this example the value that is in<br />

N10:1 will eventually end up in N7:1<br />

B<br />

RET<br />

Return par N10:1<br />

Figure 16.11<br />

Subroutines<br />

The for-next loop in Figure 16.12 will repeat a section of a ladder logic program 5<br />

times (from 0 to 9 in steps of 2) when A is true. The loop starts at the FOR <strong>and</strong> ends at the<br />

NXT function. In this example there is an ADD function that will add 1 to the value of<br />

N7:1. So when this for-next statement is complete the value of N7:1 will 5 larger. Notice<br />

that the label number is the same in the FOR <strong>and</strong> NXT, this allows them to be matched.<br />

For-next loops can be put inside other for-next loops, this is called nesting. If A was false<br />

the program would skip to the NXT statement. All 5 loops will be completed in a single<br />

program scan, so a control word is not required. If B is true the NXT statement will no<br />

longer return the program scan to the FOR instruction, even if the loop is not complete.<br />

Care must be used for this instruction so that the ladder logic does not get caught in an<br />

infinite, or long loop - if this happens the PLC will experience a fault <strong>and</strong> halt.

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

Saved successfully!

Ooh no, something went wrong!