Hi friends, I hope you are very well; today in this tutorial, we will practice conditional jumping for performing some code at the occurrence of some conditions. Like any other programming language, jumping is one of the most common approaches to transfer the execution from its sequential mode to run different processes or instructions marked by a label and bypassing the lines of codes in between the last executed transaction before the jump instruction and the labeled instruction whom the program is going to move to. The good thing about this technique is shortening the scan cycle of the program due to not running the whole program. However, using jumping techniques in coding is very dangerous. It would help if you were careful of missing some open cases before going anywhere in the code. For example, let us say that we started one process. In the middle of the process’s sequence, one jump instruction is used to run some logic under some conditions, so jumping means leaving or skyping for some reason and going running some logic or code. Therefore, we should consider the skipped instructions’ effects and consequences on the whole process and program logic. In addition, because any jump instruction can target any label and many jump instructions can target the same label, you should pay great attention to make sure you name the correct label according to the designed logic to avoid losing the reason you plan your program to do. I know you might take it easy now and can not imagine someone right wrong label by mistake. But, when you will be writing a large-scale project which contains hundreds or even thousands of rungs and has couples of dozens of labels, in that case, you can quickly mistakenly write the wrong label.
JMP and LBL instructions
To perform jumping in the ladder logic program, two instructions are together, as shown in Fig. 1. The first instruction is JMP which tells the PLC you need to jump from where the jump instruction is to where you find the LBL instruction.
Fig. 1: JMP and LBL instructions
Now how to know the label to whom you want the program execution to go or jump? Well, that is an excellent question, and the answer is that you should specify the label name as a parameter of jump instruction and the label instruction. Therefore, you can notice, my friends, if Fig. 2, the JMP and LBL instructions have a question mark denoting you should specify the label name, which is the next station to programme execution.
Fig. 2: Jump and Label instruction showing the label name above of them
Jump instruction ladder logic example
Now friends, let us see how jump and label instructions work together, as shown in fig. Three depicts a straightforward example of ladder logic in which JMP and LBL instruction work together, referring to the same label Q2:0. In this example, if input contact I1/0 is activated, JMP instruction will take the execution where the Q2:0 label “LBL” instruction is. As a result, the rung 001 has been bypassed.
Fig. 3: ladder logic example for jump and label instructions
How about going with a situation where we need to employ JMP and LBL instruction? Yes, in the example shown in fig. 4, You can notice here in this example. There are a couple of motors and for these motors. We need to. Use Siri. The command of the jump. And in combination with the uh label instruction. 2. Let some motors work in one scenario. And in another scenario, we will let some of these motors worworkd the others are not working. So you can imagine if you are working with Couples of pumps and want to run all pumps together in one scenario, so you do not activate the JMP command. But, in another scenario, if you’re running some of these pumps. So what we are going to do here in this example is to activate the JMP command to bypass some of these pumps, which are between the JMP and LBL commands.
Fig. 4: a real example of jump instruction
Figure 5 depicts the execution of the sample program that demonstrates JMP instruction. This case shows what happened in the first scenario example. If we do not activate jump instruction in rung 3, then all motors 1,2,3,4,5,6 and 7 will run based on the status of their firing contacts which are I:0 0 to 7, respectively. And the program execution continues running other motors after the JMP as it is not activated by touch I:0 3.
Fig. 5: test when JMP is not activated
On the other hand, Fig. 6 depicts the second scenario when activating JMP instruction by contact I0:3 at run number 3. By activating the jump command, We can notice only the motor before jump instructions are running based on their command contacts when the pumps in between jumps and label commands are bypassed, and the other engines after label instruction are running. So motors 1,2 and 3 are running, motors 4,5 and 6 have been ignored by activation of jump command instruction, while motor seven is running, which is at label command.
Fig. 6: test when JMP is activated