Back to tutorials
Beginner

RSLogix Studio 5000 JSR JMP LBL Instruction | Navigating Routines PLC Programming Jump Control

By
Vladimir Romanov
|
September 24, 2019
Table of Contents

Introduction

PLC programs are executed sequentially. In other words, the PLC executes a rung before proceeding to the next one. Within a single rung, the PLC will execute each sub-branch before proceeding to the next one. A PLC programmer may choose to navigate between rungs in a non-sequential order as defined by the routine. In other words, using instructions such as JSR, JMP and LBL allows one to create an order which doesn’t follow the rung labels.

We’ve been using the JSR, or the Jump to Subroutine instruction, in many places of our code. This simple instruction allows the programmer to indicate which routines to execute within a program. As the PLC scans the JSR instruction, it executes the associate subroutine. At the end of the specified subroutine, the PLC returns to the instructions and continues from there.

The JMP and LBL instructions allow one to jump between different rungs within a routine or otherwise. These instructions are simple in nature, but create an environment which may confuse even the most experienced programmers. It’s important to understand them in order to avoid troubleshooting complications in PLC systems.

JSR Instruction in RSLogix Studio 500 and 5000

The JSR Instruction is a fundamental building block of any PLC program. It allows the PLC to execute code within different routines and specifies the sequence of their execution.

From a practical standpoint, the most common use of the JSR Instruction is within the “Main” routine. This routine will point to all the others in order to execute them once per PLC scan. See the example below of this exact setup.

RSLogix Studio 5000 JSR JMP LBL Instruction | Navigating Routines PLC Programming Jump Control

In the image above, the PLC will execute the rung “0” by calling the “_02a_Inputs” routine first. Once the routine completes, the PLC will return to the rung and execute “_03a_Outputs”. The PLC will then jump to rung “1” and execute the next instruction.

By defining the structure of JSR instructions, the programmer will make sure that every piece of code is executed.

Although the premise of the JSR Instruction is simple, it’s important to keep a few things in mind.

  • Calling the same routine twice through a JSR will execute it multiple times within a single PLC scan.
  • The JSR Instruction is capable of passing parameters to the subroutine. This isn’t a common practice as it’s often difficult to trace the passing of such parameters and can be accomplished through other means.
  • A similar effect to the one above can be achieved by calling a JSR Instruction at the end of every routine instead of concentrating them into the “Main” routine. However, this isn’t as obvious.

JMP and LBL Code Navigation in RSLogix 5000 PLC Programming

The JMP and LBL instructions work together. The LBL will specify a point within a routine. By calling this point, the JMP will navigate the PLC execution directly to the location of the LBL. Let’s explore this concept in more detail.

Suppose that a routine has 5 distinct rungs. The routine is executed as expected. In other words, Rung 0, rung 1, 2, etc. We may add a LBL Instruction on Rung 4. The LBL Instruction by itself does not change the execution; the routine operates exactly as it did. Once we add a JMP Instruction with the same name as the LBL, things change. If the JMP isn’t preceeded by a condition, it will always execute just like any other instruction. Suppose that the JMP is placed in Rung 0. Therefore, the PLC will execute Rung 0 & immediately jump to rung 4 which contains the LBL. The rungs between the two instructions will not execute.

RSLogix Studio 5000 JSR JMP LBL Instruction | Navigating Routines PLC Programming Jump Control

As you implement the JMP / LBL pair into your code for the first time, the functionality may seem undewhelming. However, these instructions are highly flexible. As you add a condition before the JMP, you can start controlling at which point you want to execute certain pieces of your code. Furthermore, by combining the JSR routine into the mix, you may choose the execution of certain routines based on conditions of your code.

It’s important to keep in mind that issues may arise with improper or overexcessive use of these instructions. You may create infinite loops, areas which are never executed and simply confusing routines. Troubleshooting code which contains these instructions isn’t always obvious as the PLC will not explicitely tell you what’s being execute and what isn’t.

Use these instructions wisely.

Conclusion

The JSR, JMP and LBL Instructions are highly versatile. They allow the programmer to create sequences of execution which are non-linear. However, there’s a tradeoff which isn’t always obvious. Code which contains these instructions isn’t always simple to troubleshoot and follow. It is highly advised to avoid using these instructions unless you’ve had a lot of experience programming PLC based systems.

Video Tutorial

Back to tutorials

Got a question or comment?

Related Tutorials

Intermediate

PLC Programming Example Project - Batching Tank Ladder Logic PLC and HMI Tutorial

Generally speaking, there are two types of processes in manufacturing: discrete and analog. A discrete process is a manufacturing methodology that will produce separate widgets. In other words, a production line may output one item, two items, three items, etc. An analog production process is where the plant will create a quantity of product that is quantifiable by weight. Examples include the production of beverages, sauces, raw ingredients, etc. Although it is possible to design a flow that will continuously output the product, such production is often managed in batches. It is important to note that although batches are considered to be analog or continuous flow, most of them end up being packaged for consumption which converts them into a discrete manufacturing process.

September 14, 2020
|
By
Vladimir Romanov
PLC Programming Career

PLC Programming Certification - Complete Guide

You may choose to pursue a traditional college degree, learn through online tutorials, or take a course that will issue a plc programming certification upon completion. However, what is the best option, and what are the best PLC programming certifications?

August 6, 2020
|
By
Vladimir Romanov
Beginner

Opto 22 groov RIO Getting Started

The groov RIO module from Opto 22 has been released only a few months ago. The groov RIO is a feature packed piece of hardware that is easy to install, configure and deploy for many different field applications. The module comes pre-loaded with an array of software tools used across the industry and is ready to hit the floor running out of the box. Furthermore, the module is equipped with user configurable input and output nodes that have the capability unlike anything else on the market.

August 2, 2020
|
By
Vladimir Romanov