Sign in to follow this  
Followers 0
machinemaker

LBL JMP

17 posts in this topic

Would someone mind telling me how the JMP and LBL work? The compiler took my JMP as Q4.0 but when I did LBL Q4.0 it says I was missing something at the end of the rung. What though? The book has no examples. For some insane reason, AB does not like to put examples. Pictures are worth a thousand words. Who said that? What I am trying to do is have when SS is in position 1, go to label 1 and run those rungs. If SS is in position 2 goto label 2. Well not those labels, but you get the idea. My question is after it finishes those rungs where will the program go from there? If label 1 and all it rungs are above label 2 and all its rungs, what will the program do next? After it finishes all the rungs after label 1, will the program process the rungs in label 2? I need structure. :)

Share this post


Link to post
Share on other sites
1. Can you post your code and error exactly? Pictures? 2. A JMP to a LBL just says 'go to this lable and continue from there.' 3. So let's say you have two sections of code whose execution is dependent on a switch followed by code that will be the same in both instances Code - Code - Code If Switch is ON JMP to 'B' Here start the 'A' code - if the switch wasn't on the execution continues to here Code - Code - Code JMP 'C' LBL 'B' Here is the 'B' code - if the switch was ON the execution is here Code - code - code LBL 'C' - this has no meaning for the execution falling through from executing the 'B' code Code - code - code - code which is executed in either case. Edited by b_carlton

Share this post


Link to post
Share on other sites
Which processor? The LBL instruction can only be inserted at the start of a rung, and must be followed be a terminating instruction (i.e., OTE, MOV, MUL, PID, etc.). I usually put the LBL at the front of the first rung of code that will execute when the JMP happens. The JMP and LBL pair is not a subroutine. For that you'll create another ladder and use the JSR (and the RET on some platforms), and when the subroutine is executed, the scan will return to the call point and continue scanning. A JMP is an unconditional move from one point of code to another point. The LBL is a pointer, and indicates where the JMP will land. The LBL is ignored except when it is referred to by a JMP instruction. As a test, put in an LBL instruction without a JMP instruction. The code will execute as if the LBL isn't there. So, to answer your question specifically, when you use a JMP, the scan will move to the LBL (either skipping forward or backward in the code), and continue executing, do not pass go do not collect 200 dollars. In a situation like yours, I would either use a true subroutine (if there are lots of rungs) or just one or two big rungs with the SS inputs as conditionals. I usually only use the JMP and LBL to create a loop, usually with an index, to do the same thing multiple times each scan. For example, if I had a lot of analog inputs, I could use arrays and a single scaling block with a loop to do all my scaling, rather than program everything out. I use this method only in extreme circumstances, because it's difficult to troubleshoot, runs the risk of endless loops and PLC faults, and usually doesn't decrease scan time. Plus, I've learned some tricks to creating a lot of duplicate rungs very quickly using Excel, so it's not any faster to program.
1 person likes this

Share this post


Link to post
Share on other sites
It is a Micrologix 1400. I had __________________jmp Q4:0 code code code LBL Q4:0________________________ code code It said I had to put something on the rung I did not know what to put. But someone is saying just put my code on the LBL rung. I wanted to try the Jmp because it is redundant to keep typing I:0.0/2 etc on rung after rung vs I could just jump to my section of rungs and run code without typing the same elements over and over again. I miss the stage programming in AD.

Share this post


Link to post
Share on other sites
You need some output instruction on the lbl rung. In some processors I've seen the NOP Instruction used, but 1400 doesn't have a NOP instruction. If you ahve memory and time to kill I've also seen the ACI Instruction on the ladder rung. In other words LBL Q4:0 ACI ST20:0 N17:0 . And then fill ST20:0 with a comment about label 2. It makes for neat backdoor documentation if the program is ever lost, but takes a ton of time to setup and use.

Share this post


Link to post
Share on other sites
You need some output instruction on the lbl rung. In some processors I've seen the NOP Instruction used, but 1400 doesn't have a NOP instruction. If you ahve memory and time to kill I've also seen the ACI Instruction on the ladder rung. In other words LBL Q4:0 ACI ST20:0 N17:0 . And then fill ST20:0 with a comment about label 2. It makes for neat backdoor documentation if the program is ever lost, but takes a ton of time to setup and use.

Share this post


Link to post
Share on other sites
Don't take this the wrong way, but I think you are holding on to the "AD" way, I've never seen the Jump and Label used like you plan, I have always used it for looping. I'm not sure what happens to the logic you will skip over. If a rung was true last scan, and is skipped this scan, will the ladder hold it's last state? Not sure. If you could share more details, maybe someone could bring a different solution to the table for you to examine. For example: How many positions does your switch have? How complex is the code for each position, 10 rungs, 100 rungs, 1000 rungs? Will the same outputs need to be switched in more than one switch position? Ken

Share this post


Link to post
Share on other sites
here's a little lesson program (attached) that should help you understand how the JMP and LBL instructions CAN be used ... basically it demonstrates how a rung (or even a series of rungs) may be "skipped over" and simply IGNORED by the processor ... and to answer a couple of specific questions: (1) if a JMP is used to "skip" over a rung which has an OTE instruction on it, the OTE will NOT be executed - so its bit will be left in its last state ... (2) the LBL is simply placed AT THE BEGINNING of the rung where you want "normal" execution to begin again ... in other words, the LBL instruction will always just pass TRUE logic ... more specifically, the LBL is just a "target" for the JMP to jump to - and therefore the LBL instruction will NOT affect the TRUE/FALSE conditions of its own rung ... (3) the "extra" number in the address (2 in my example) gives the number of the Ladder File that you are currently in ... note that a JMP can NOT be used to jump from one ladder file to another ... tip: a JSR is a "big" jump ... the JMP is a "baby" jump ... (4) the "Q" is just an arbitrary designator which allows you to tie an "instruction" comment to the JMP and LBL instructions ... specifically, you couldn't document the number "4" - but you COULD document "Q2:4" ... tip: using JMP and LBL instructions to selectively either execute - or to NOT execute - various sections of ladder logic for SEQUENCING-type operations, is "generally" not the best way to structure a program ... JMP_LBL.pdf Edited by Ron Beaufort

Share this post


Link to post
Share on other sites
Ron is being very polite. I would go so far as to say that JMP and LBL should be banned from your repertoire. Don't use them. With the exception of looping, I have never seen a case, in which they were really needed. Even using them for a loop operation can be risky, but can be acceptable...not for machine control, but for sorting data or repeating the same math functions on an array of values. Edited by OkiePC

Share this post


Link to post
Share on other sites
The only reason I would consider using JMP/LBL is to lessen the CPU burden and improve scantimes when the controller has been "undersized" at development time. Every now and then I might temporarily loop the logic for troubleshooting/debugging purposes, however promptly eliminating them when done. Edited by dmargineau

Share this post


Link to post
Share on other sites
I would argue that creating separate ladders and only scanning them when needed would be a better way to lessen the CPU burden. JMPs can be extremely difficult to troubleshoot.

Share this post


Link to post
Share on other sites
When a lower tier CPU is running a huge project and/or part of the application file is very seldom "active", short of replacing the controller, JMP/LBL could help improving the overall performance...I've thought I have made myself clear when highlighting "Only" within my previous post... Troubleshooting JMP/LBL is similar to conditional JSRs...Nothing but a pain...

Share this post


Link to post
Share on other sites
You were clear, I'm just picking nits. My point is that in a well structured program, it's easier to understand (and therefore troubleshoot) a conditional JSR. Of course, the key is "well structured", and my definition may well be different from yours. Yes, JSR can be very annoying to troubleshoot, especially on RSLogix500. Fortunately RSLogix5000 makes it easier by allowing you to cross-reference routines. The reverse is true too, I suppose. If laid out well and not overused, JMP-LBL isn't too bad to follow. But again, ONLY to be used if necessary. I did have an application on a Mitsubishi PLC where I used their equivalent instructions to decrease load. It was controlling an automated watering boom in a greenhouse, and I was doing a huge amount of calculation in the recipe pages, so I offloaded that to a subroutine that only ran if I was actively working with the recipes. I can't remember my scan times, but when I was on the recipe pages, my scan was high enough that I had to increase the length of the watch dog timer from the default 50ms!

Share this post


Link to post
Share on other sites
Hey Guru, I originally typed this out but my loop is working I just didn't understand that I prob wouldnt see the Index move because I think it only updates it at the end of each scan...and Index is always going to be 3 at the end of each scan. Am I right!?!? Judging from the lights on the HMI, I am I'm trying to jump back just to loop through a piece of code. I can not get it to work. First I couldn't get it to count. Now it counted but the value I was using to index is stuck at it's high point. I am moving a 1 into that index tag before my lbl instruction so the next time it scans through, it should write a one in there. Could you show me just a snippet of a loop you have that is working? Also, mind sharing the excel secret??? tisha.lane317@gmail.com mov(1->Index) LBL...code code code Add(1 to Index->Index) LEQ(Index, 3) JMP Edited by ControlsGirl

Share this post


Link to post
Share on other sites
JMP and LBL aren't used very often anymore. They're a holdover from the days when memory was expensive and processors weren't as powerful. They're included for legacy purposes, but the instances in which you'd actually NEED them are rare.

Share this post


Link to post
Share on other sites
I still use them quite regularly. Although not for skipping sections of code, for creating loops to search for things, or load recipes, etc etc. ControlsGirl, check out this thread, JRoss' post (about 4th one down) has a few excel tricks in it that were new to me. Maybe he has some more up his sleeve? http://forums.mrplc.com/index.php?showtopic=27406&hl= As far as your index being "stuck" at the high level, you're right, it will appear to be so because it writes the 1 into the index and then probably 2ms later it's cycled through your logic and reached the high point again. And then gone off to execute the rest of the code. Your update rate will never be quick enough to show it halfway through the cycle Here's one of my loops in action. I have an array of AOI's that monitor line conditions, and shut down the line after a preset time if the condition is within an alarm range, or immediately if it's within a stop range. Each AOI has a countdown value so you can see how long before that particular condition will stop the line. The first line of this logic writes 99999 to my Time Left to Line Stop value, and resets my index pointer. Then the next rung scrolls through all the AOI's, and if one is in the alarm range, and the countdown time it displays is less than the current Time Left to Line Stop value, it overwrites the Time Left to Line Stop value. Repeat until the end of the array is reached, and now the Time Left to Line Stop has the lowest value of any AOI. So if three line conditions are in alarm, and one will stop the line in 5 minutes, one in 15 and one in 60, this value will show 5 and I can display "5 minutes to line shutdown" on the SCADA. If the 5 minute condition is corrected, it will immediately jump to saying "15 minutes to line shutdown". The only other thing you can see in there which is useful is that I'm not just comparing my search pointer to a fixed value, I'm comparing it to a tag "ArraySearch_Size". Earlier on I set this tag using a SIZE instruction and checking the size of my AOI array. Just means that if in 5 years time when I've forgotten about all these loops, I go and add another element to the array to monitor another condition, I don't have to go trawling through and re-sizing all my search loops to prevent my PLC from crashing. It'll find the new size automatically. Hope that helps! Edited by ASForrest

Share this post


Link to post
Share on other sites
I avoid loops like the plague. There's usually no reason for them. The PLC has more important things to do than sit there cycling, slowing down everything else. Not to pick on ASForrest, but the picture above is a perfect example of what I'd avoid. In the code above, if you remove the JMP and LBL, it would work exactly the same. A few small modifications are needed (Copy the two instructions in the first row to the place of the JMP instruction. Delete the first row. Change the LES instruction before the JMP to a GEQ. That's all). After that, the only functional difference is that it would only increment once every scan, rather than go through the whole cycle every scan. Except in certain circumstances, that's perfectly acceptable, and more efficient in the processor. There are circumstances that call for different needs, but, overall, I try to avoid loops if possible. Edited by MrAutomation

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0