SlideShare a Scribd company logo
Chapter 08 – Program Control
Instructions
Sections 8-3-3 to 8-3-5
Subroutines
 Subroutine(s) is a group of program code that performs a
specific task. The subroutine(s) are part of a program (in our
case, the MainProgram) and are not part of the MainRoutine.
 A subroutine can be invoked, (called), from anyplace in the
MainRoutine or from another subroutine. When a subroutine
is called from within another subroutine it is referred to as
nesting subroutines.
 Most, if not all, computer programs and PLC/PAC programs
contain subroutines.
 Subroutines are used to make what would be an enormous
program more manageable by breaking up the code into
smaller tasks. Specific functions within a task should be
placed in subroutines.
 Organizing a program by using subroutines makes the code
easier to read, understand and maintain.
 Subroutines can also be reused in other programs that require
the same task be performed.
Subroutines
 The ControlLogix uses separate routines
to store and execute subroutines. The
number of routines is limited to 32 per
program.
 The MainRoutine is the main ladder and is
the one that has been used for all previous
labs.
 Scan starts at rung 0 in the MainRoutine
and ends at the End statement in the
MainRoutine.
Creating a Subroutine
 Step 01
 In the Controller Organizer, right click on
MainProgram and select New Routine… from
the context specific menu.
Creating a Subroutine
 Step 02
 When the New Routine dialog box opens, enter the name
of the subroutine into the Name field, enter any description
(opetional) and click the down arrow of the Type drop
down box and select Ladder Diagram. If you want the new
routine to open upon creation, place a check mark in the
Open Routine check box.
Routines other than Ladder
Diagram can be created.
The Type Drop Down
shows that, Sequential
Function Chart, Function
Block Diagram and
Structure Text routines can
also be created. This
course will only use Ladder
Diagram.
Creating a Subroutine
 Step 03
 The subroutine will
appear listed under
the program that it
was created in.
Double click the
subroutine to open it
in the ladder editor.
Program Control
Instructions
Instruction Instruction
JMP – Jump to Label UID – User Interrupt Disable
LBL – Label UIE – User Interrupt Enable
JXR – Jump to External Routine SFR – Reset Sequential Chart
JSR – Jump to Subroutine SFP – Pause Sequential Chart
RET – Return from Subroutine EVENT – Trigger Event Task
SBR – Subroutine Label EOT – End of Transition
TND – Temporary End AFI – Always False
MCR – Master Control Reset NOP – No Operation
This course will cover the instructions shown in Red.
The instructions shown in Green can be used, but will not be discussed in class.
Program Control
Instructions
 JSR – Jump to Subroutine
 The JSR is an output instruction that is used to “call” a
subroutine.
 The instruction can be conditional or unconditional.
 JSR instructions can have several parameters.
Subroutine name to
be “called”
(required).
Parameter to pass to
the subroutine
(optional).
Parameter to accept
a value returned from
the subroutine
(optional).
Program Control
Instructions
 Entering JSR parameters:
 Routine Name (Required) –
Double click this parameter
field, click the drop down
arrow and select the
subroutine name from the
drop down list. The subroutine
name will only be in the list if
the subroutine has been
created.
 Input Par and Return Par
(Optional) – These
parameters will not be used in
this course. When a
parameter is not used it must
be removed. Right click on the
parameter field and select
Remove Instruction
Parameter from the context
specific menu. Do this for
each parameter that is not
required.
Program Control
Instructions
 JSR operation
 When the rung containing the JSR instruction is
true, the processor scan jumps to the subroutine
referenced in the Routine Name parameter and
begins program execution at the first rung in that
subroutine.
 A jump cannot be made into the middle of a
subroutine. Executions will always start at the first
instruction on the first rung in that ladder routine.
This rung will unconditionally jump to the subroutine named: HeatControlFurnace01
Program Control
Instructions
 SBR – Subroutine Label (optional, but recommended)
 The SBR is an input instruction that is always true and
marks the beginning of a subroutine. It must be the
first instruction on the first rung of the subroutine.
 The input parameter field(s) is used to reference tags
whose data is to be used (passed) to the subroutine.
(This course will not be using these parameters).
 SBR instruction can have several parameters.
Parameter that
passes data to the
subroutine (optional)
Program Control
Instructions
 For this course the
Input Par parameter
will need to be
removed from the
SBR instruction. To
remove the
parameter, right-
click on the
parameter and
select Remove
Instruction
Parameter from the
context specific
menu.
Program Control
Instructions
 RET – Return from Subroutine
 The RET instruction is an output instruction that is used to
stop executing the subroutine and return to the ladder file that
originally “called” the subroutine.
 The instruction can be conditional or unconditional and can
contain several parameters. (This course will not use these
parameters).
 The RET instruction is not always required. If the entire
subroutine file is to be scanned, the End statement will also
function as the RET.
Parameter that
passes data back to
the ladder file that
originally “called” the
subroutine (optional)
Program Control
Instructions
 For this course the
Input Par parameter
will need to be
removed from the
RET instruction. To
remove the
parameter, right-
click on the
parameter and
select Remove
Instruction
Parameter from the
context specific
menu.
Program Control
Instructions
 Several conditional RET instruction can be present in
a subroutine. As an example:
 If an RET instruction becomes true that is on rung-6 in a
subroutine containing 45-rungs, the program scan will
return to the ladder file that originally called the subroutine
and rung 7 through 45 will not execute.
 If the RET instruction on rung-6 becomes false and
another RET instruction at rung-10 becomes true, the
program scan will return to the ladder file that originally
called the subroutine and rungs 11 through 45 will not
execute.
 If the entire subroutine ladder file is to be always
scanned, placing a RET instruction on the last rung of
the program is optional. If an RET instruction is not
found in the subroutine ladder file, the End statement
performs the return.
Program Execution -
Subroutines
Program Control
Instructions - Siemens
 Siemens processors do not use
subroutines per say.
 Siemens uses:
 Organizational Blocks
 Function Blocks
 Functions
 Data Blocks
 These will not be covered in this course.
Program Control
Instruction - CCW
 The AB CCW does not have
program control
instructions. Subroutines
can be created and will
always execute in the order
they appear in the project
organizer window.
 The order of the routines
can be moved by dragging
them to a new location.
 In the picture shown, the
order of execution is: Prog4
then Prog2 then Prog3 and
finally Prog1. When Prog1
has finished executing the
scan returns to Prog4 and
repeats.

More Related Content

PPTX
03 chapter03 01_introduction_fa16
PPTX
07 chapter03 05_siemens_tags_memory_structure_fa14
PPTX
Microprocessors-based systems (under graduate course) Lecture 9 of 9
PDF
Basics of plc_programming1
PDF
Siemens s7 300 programming
PDF
Plc timers
PDF
Embedded systems ppt ii
03 chapter03 01_introduction_fa16
07 chapter03 05_siemens_tags_memory_structure_fa14
Microprocessors-based systems (under graduate course) Lecture 9 of 9
Basics of plc_programming1
Siemens s7 300 programming
Plc timers
Embedded systems ppt ii

What's hot (20)

PPTX
Register transfer and micro-operation
PPT
Em s7 plc
PPTX
Basic PLC Symbols and Addresses in LogixPro
PPTX
Arm programmer's model
PPT
Chapter 2 ladder
PPT
8259 A P R O G R A M M A B L E I N T E R R U P T C O N T R O L L E R2
PPT
Ladder Intro Tutorial
PDF
PLC Programming Languages
PDF
Intel 8080 8085 assembly language programming 1977 intel
PPTX
B sc e5.2 mp unit 3 interfacing
PPS
Timing and-control-unit
PPT
Interrupt11
PPT
PLC Basics
PDF
PLC: Principios básicos del controlador lógico programable mediante el softwa...
PDF
Introduction to Microcontrollers
PPT
subroutines and interrupts
DOCX
c++
PPTX
Run time, frequently, non-frequently reconfigurable system &
PPT
Plc introduction
PDF
Register transfer and micro-operation
Em s7 plc
Basic PLC Symbols and Addresses in LogixPro
Arm programmer's model
Chapter 2 ladder
8259 A P R O G R A M M A B L E I N T E R R U P T C O N T R O L L E R2
Ladder Intro Tutorial
PLC Programming Languages
Intel 8080 8085 assembly language programming 1977 intel
B sc e5.2 mp unit 3 interfacing
Timing and-control-unit
Interrupt11
PLC Basics
PLC: Principios básicos del controlador lógico programable mediante el softwa...
Introduction to Microcontrollers
subroutines and interrupts
c++
Run time, frequently, non-frequently reconfigurable system &
Plc introduction
Ad

Viewers also liked (20)

PPTX
00 introduction
PPTX
02 chapter02 p&ids_and_symbols_split_animations
PPTX
01 chapter01 process_flow_diagram
PPTX
Creativity
PPTX
Program residen dan non residen(rev.1)
PPTX
Proyecto empresa familiar
PPTX
Power proyecto.pptx (1)
PPTX
Analisis dengan piecewise
DOCX
Neil Beard Updated CV warburton
PPTX
Presentacin1 160922181044
PDF
Turismo invierno 2016 AMSAFE PROVINCIAL
PDF
p288-radu
PPT
Interupsi
PDF
Participants list, SIGMA Public procurement review bodies conference, Ohrid 9...
PPTX
Instantly prom
PPTX
DIRECTIONAL DRILLING PROBLEM SOLVING
PPTX
MetroCluster in Clustered Data Ontap
DOC
Resume of Vaishnav Mithun_New
PPT
ANILOX ROLLER ( using analog plc module )
00 introduction
02 chapter02 p&ids_and_symbols_split_animations
01 chapter01 process_flow_diagram
Creativity
Program residen dan non residen(rev.1)
Proyecto empresa familiar
Power proyecto.pptx (1)
Analisis dengan piecewise
Neil Beard Updated CV warburton
Presentacin1 160922181044
Turismo invierno 2016 AMSAFE PROVINCIAL
p288-radu
Interupsi
Participants list, SIGMA Public procurement review bodies conference, Ohrid 9...
Instantly prom
DIRECTIONAL DRILLING PROBLEM SOLVING
MetroCluster in Clustered Data Ontap
Resume of Vaishnav Mithun_New
ANILOX ROLLER ( using analog plc module )
Ad

Similar to Subroutines rev01 fa16 (20)

PDF
PPTX
Elements of Industrial Automation 20me43p
PDF
data handling fuctions for programmable logic controller
PDF
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...
PPTX
Stacks & subroutines 1
DOCX
PLC unit 4 lab Brett Bloomberg-1
PPT
Chapter 9
PPTX
LECTURE_5 Program Control Instructions.pptx
PDF
Stack and subroutine
PPTX
Microprocessor and Assembly Language - 8.pptx
PDF
Instructions
PPTX
ARM Architecture Subroutine and Flags
PPT
Data manipulation for Mechatronics System
PPT
Chapter6-mikroprocessor
PDF
8085 branching instruction
PPTX
PPTX
PDF
Microcontroladores: introducción a la programación en lenguaje ensamblador AVR
PDF
3 jump, loop and call instructions
DOC
Chapter 5 notes
Elements of Industrial Automation 20me43p
data handling fuctions for programmable logic controller
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...
Stacks & subroutines 1
PLC unit 4 lab Brett Bloomberg-1
Chapter 9
LECTURE_5 Program Control Instructions.pptx
Stack and subroutine
Microprocessor and Assembly Language - 8.pptx
Instructions
ARM Architecture Subroutine and Flags
Data manipulation for Mechatronics System
Chapter6-mikroprocessor
8085 branching instruction
Microcontroladores: introducción a la programación en lenguaje ensamblador AVR
3 jump, loop and call instructions
Chapter 5 notes

More from John Todora (20)

PPTX
04 scaling analog_datal_sp17
PPTX
03 analog control_sp17
PPTX
01 control logix_arrays_sp17
PPTX
Comparison instructions, AB, Siemens and AB CCW
PPTX
Lab02 review
PPTX
Move mask moves_rev01_fa16
PPTX
Math cl ccw_siemens_rev01_fa16
PPTX
ControlLogix Counters FA16
PPTX
Lab02 lead in
PPTX
ControlLogix Timers FA16
PPTX
02 chapter02 fa16
PPTX
01 introduction to_plc-pac_rev01_fa16
PPTX
07 chapter07 loop_diagrams
PPTX
06 chapter06 binary_logic_systems_Rev02
PPTX
04 chapter04 specification_forms
PPTX
03 chapter03 lists_indexes_databases
PPTX
EMEC130 P&ID Symbol Primer
PPTX
02 copy file_fill_sp16
PPTX
Control Systems Basics
PPTX
01 overview of_industrial_automation_sp15
04 scaling analog_datal_sp17
03 analog control_sp17
01 control logix_arrays_sp17
Comparison instructions, AB, Siemens and AB CCW
Lab02 review
Move mask moves_rev01_fa16
Math cl ccw_siemens_rev01_fa16
ControlLogix Counters FA16
Lab02 lead in
ControlLogix Timers FA16
02 chapter02 fa16
01 introduction to_plc-pac_rev01_fa16
07 chapter07 loop_diagrams
06 chapter06 binary_logic_systems_Rev02
04 chapter04 specification_forms
03 chapter03 lists_indexes_databases
EMEC130 P&ID Symbol Primer
02 copy file_fill_sp16
Control Systems Basics
01 overview of_industrial_automation_sp15

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
GDM (1) (1).pptx small presentation for students
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Institutional Correction lecture only . . .
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
VCE English Exam - Section C Student Revision Booklet
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Final Presentation General Medicine 03-08-2024.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial disease of the cardiovascular and lymphatic systems
GDM (1) (1).pptx small presentation for students
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
Sports Quiz easy sports quiz sports quiz
Institutional Correction lecture only . . .
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Renaissance Architecture: A Journey from Faith to Humanism

Subroutines rev01 fa16

  • 1. Chapter 08 – Program Control Instructions Sections 8-3-3 to 8-3-5
  • 2. Subroutines  Subroutine(s) is a group of program code that performs a specific task. The subroutine(s) are part of a program (in our case, the MainProgram) and are not part of the MainRoutine.  A subroutine can be invoked, (called), from anyplace in the MainRoutine or from another subroutine. When a subroutine is called from within another subroutine it is referred to as nesting subroutines.  Most, if not all, computer programs and PLC/PAC programs contain subroutines.  Subroutines are used to make what would be an enormous program more manageable by breaking up the code into smaller tasks. Specific functions within a task should be placed in subroutines.  Organizing a program by using subroutines makes the code easier to read, understand and maintain.  Subroutines can also be reused in other programs that require the same task be performed.
  • 3. Subroutines  The ControlLogix uses separate routines to store and execute subroutines. The number of routines is limited to 32 per program.  The MainRoutine is the main ladder and is the one that has been used for all previous labs.  Scan starts at rung 0 in the MainRoutine and ends at the End statement in the MainRoutine.
  • 4. Creating a Subroutine  Step 01  In the Controller Organizer, right click on MainProgram and select New Routine… from the context specific menu.
  • 5. Creating a Subroutine  Step 02  When the New Routine dialog box opens, enter the name of the subroutine into the Name field, enter any description (opetional) and click the down arrow of the Type drop down box and select Ladder Diagram. If you want the new routine to open upon creation, place a check mark in the Open Routine check box. Routines other than Ladder Diagram can be created. The Type Drop Down shows that, Sequential Function Chart, Function Block Diagram and Structure Text routines can also be created. This course will only use Ladder Diagram.
  • 6. Creating a Subroutine  Step 03  The subroutine will appear listed under the program that it was created in. Double click the subroutine to open it in the ladder editor.
  • 7. Program Control Instructions Instruction Instruction JMP – Jump to Label UID – User Interrupt Disable LBL – Label UIE – User Interrupt Enable JXR – Jump to External Routine SFR – Reset Sequential Chart JSR – Jump to Subroutine SFP – Pause Sequential Chart RET – Return from Subroutine EVENT – Trigger Event Task SBR – Subroutine Label EOT – End of Transition TND – Temporary End AFI – Always False MCR – Master Control Reset NOP – No Operation This course will cover the instructions shown in Red. The instructions shown in Green can be used, but will not be discussed in class.
  • 8. Program Control Instructions  JSR – Jump to Subroutine  The JSR is an output instruction that is used to “call” a subroutine.  The instruction can be conditional or unconditional.  JSR instructions can have several parameters. Subroutine name to be “called” (required). Parameter to pass to the subroutine (optional). Parameter to accept a value returned from the subroutine (optional).
  • 9. Program Control Instructions  Entering JSR parameters:  Routine Name (Required) – Double click this parameter field, click the drop down arrow and select the subroutine name from the drop down list. The subroutine name will only be in the list if the subroutine has been created.  Input Par and Return Par (Optional) – These parameters will not be used in this course. When a parameter is not used it must be removed. Right click on the parameter field and select Remove Instruction Parameter from the context specific menu. Do this for each parameter that is not required.
  • 10. Program Control Instructions  JSR operation  When the rung containing the JSR instruction is true, the processor scan jumps to the subroutine referenced in the Routine Name parameter and begins program execution at the first rung in that subroutine.  A jump cannot be made into the middle of a subroutine. Executions will always start at the first instruction on the first rung in that ladder routine. This rung will unconditionally jump to the subroutine named: HeatControlFurnace01
  • 11. Program Control Instructions  SBR – Subroutine Label (optional, but recommended)  The SBR is an input instruction that is always true and marks the beginning of a subroutine. It must be the first instruction on the first rung of the subroutine.  The input parameter field(s) is used to reference tags whose data is to be used (passed) to the subroutine. (This course will not be using these parameters).  SBR instruction can have several parameters. Parameter that passes data to the subroutine (optional)
  • 12. Program Control Instructions  For this course the Input Par parameter will need to be removed from the SBR instruction. To remove the parameter, right- click on the parameter and select Remove Instruction Parameter from the context specific menu.
  • 13. Program Control Instructions  RET – Return from Subroutine  The RET instruction is an output instruction that is used to stop executing the subroutine and return to the ladder file that originally “called” the subroutine.  The instruction can be conditional or unconditional and can contain several parameters. (This course will not use these parameters).  The RET instruction is not always required. If the entire subroutine file is to be scanned, the End statement will also function as the RET. Parameter that passes data back to the ladder file that originally “called” the subroutine (optional)
  • 14. Program Control Instructions  For this course the Input Par parameter will need to be removed from the RET instruction. To remove the parameter, right- click on the parameter and select Remove Instruction Parameter from the context specific menu.
  • 15. Program Control Instructions  Several conditional RET instruction can be present in a subroutine. As an example:  If an RET instruction becomes true that is on rung-6 in a subroutine containing 45-rungs, the program scan will return to the ladder file that originally called the subroutine and rung 7 through 45 will not execute.  If the RET instruction on rung-6 becomes false and another RET instruction at rung-10 becomes true, the program scan will return to the ladder file that originally called the subroutine and rungs 11 through 45 will not execute.  If the entire subroutine ladder file is to be always scanned, placing a RET instruction on the last rung of the program is optional. If an RET instruction is not found in the subroutine ladder file, the End statement performs the return.
  • 17. Program Control Instructions - Siemens  Siemens processors do not use subroutines per say.  Siemens uses:  Organizational Blocks  Function Blocks  Functions  Data Blocks  These will not be covered in this course.
  • 18. Program Control Instruction - CCW  The AB CCW does not have program control instructions. Subroutines can be created and will always execute in the order they appear in the project organizer window.  The order of the routines can be moved by dragging them to a new location.  In the picture shown, the order of execution is: Prog4 then Prog2 then Prog3 and finally Prog1. When Prog1 has finished executing the scan returns to Prog4 and repeats.