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/sbr.html

Subroutine Instruction (SBR)


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

The subroutine (SBR) instruction, is the destination or target for the JSR
instruction. The SBR instruction must be the first instruction on the first rung in
the program files that contain the subroutine.

The symbol for the subroutine command is illustrated above. The SBR command
is placed on the
first rung of the subroutine file. A subroutine is used to store recurring sections of program logic that must
be executed from several points within the main program logic. When the rung is TRUE, the JSR
instruction jumps to a designated subroutine file stored in the program files folder.

To enter a parameter into the JSR command, highlight the command and type a number between (3 - 255).
Use the following prodedure to create a subroutine folder:
1.
2.
3.
4.
5.

In the left split screen, left mouse click the program files folder to highlight.
Right mouse click on the file folder to open menu box.
Select new.
Type the same number that was entered into the JMP command.
Optional, name the subroutine folder in space provided.

Use the tab on the bottom of the ladder logic program to switch between the main logic program and the
SUBROUTINE program.
The subroutine folder should have a subroutine(SBR) instruction and a return from subroutine (RET)
instruction. The SBR instruction must be the first instruction on the first rung in the program files that
contain the subroutine. The RET 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
resumes' execution of that program.
Use the tab on the bottom of the ladder logic program to flip between the main logic program to the
subroutine program.

02-07-2013 16:09

PLC Programming Command Guide Reference Web Site

2 of 3

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

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 main program to continue to scan the main
program rungs 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, it
unlatches the contacts holding the JSR command in the TRUE state by using a rung in the subroutine file.
If the JSR instruction 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.

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.

02-07-2013 16:09

PLC Programming Command Guide Reference Web Site

3 of 3

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

[Back] [Next Command]

02-07-2013 16:09

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