Sunteți pe pagina 1din 4

Menu

1 of 1

http://plcguide.mrplc.com/menu.shtml

Menu
Command Index
Basic Instructions
Timer & Counter
Compare
Data
Math
Register and Sequencer
Program Control
Communication
Programming References
Example Programs
PLC GuestBook
Links
Down Loads

Send Comments

2001-2006
All Rights Reserved
Your IP Address is: 117.222.1.67

02-07-2013 16:09

PLC Programming Command Guide Reference Web Site

1 of 3

http://plcguide.mrplc.com/prgcon/ret.html

Return From Subroutine Instruction (RET)


[Introduction Page] [Command Index] [Programming References]

The RET command is used in conjunction with the jump to subroutine (JSR), and subroutine (SBR)
commands. The instructions are used to direct the controller to execute a separate subroutine file within
the ladder logic program and return to the previous program at the rung following the JSR instruction.
The return from subroutine (RET) instructions marks the end of the subroutine
execution or the end of the subroutine file. It causes the controller to return to
the program where the JSR command instruction was placed and resume
execution of that program, following the JSR instruction.

The symbol for the Return to Subroutine command is illustrated above. The RET command
or
commands can be placed within or at the end of the subroutine file. The RET instruction may be
conditional if the rung conditional logic is true. This way the controller omits the balance of a subroutine
only if the rung conditional logic is true.
Use the tab on the bottom of the ladder logic program to flip between the main logic program to any
subroutine programs.
In the following figure 1-1, is a basic subroutine ladder logic program.

Figure 1-1 subroutine program.

In the following figure 1-2, is a basic subroutine ladder logic program with multiply returns. This allows
the program to return from a subroutine quicker, if certain conditions are met skipping the remainder of
the subroutine.

02-07-2013 16:09

PLC Programming Command Guide Reference Web Site

2 of 3

http://plcguide.mrplc.com/prgcon/ret.html

Figure 1-2 multi-return subroutine program.


After the JSR is activated the scanning order for the PLC ladder includes: The PLC jumps to the labeled
subroutine, scans the subroutine program, and returns to the program where the JSR was placed in order
to continue to scan that program. The scanning continues from the rung after the JSR command. If a timer
is located within the SBR, the JSR must have a latched input in order for the timer to reach the preset
time. Once the timer has completed the timer cycle, within this file unlatch the contacts switch within the
subroutine.
If the JSR instruction rung is false, the subroutine is skipped.

Example Problem

Use a subroutine command to count the number of parts passing through a system. When the counter
reaches ten, have the controller turn off an output.

02-07-2013 16:09

PLC Programming Command Guide Reference Web Site

3 of 3

http://plcguide.mrplc.com/prgcon/ret.html

In this example the subroutine contains a counter. Each time the JSR inputs are activated in the main
program by either the I:1/0 or I:1/5 the counter counts up by one in the subroutine program. This example
allows parts to be countered at two different places. When the counter reaches ten O:2/9 is disabled.
[Back] [Next Command]

02-07-2013 16:09

S-ar putea să vă placă și