Looping a part of sub-routine

ersanjit

Member
Join Date
Sep 2018
Location
Windsor, ON
Posts
14
Hello everyone,

I am new to ladder logic and am currently working on a small project where I might need some help. So I am modifying the sequence of a machine in RsLogix5000. I just some of the rungs to be executed twice so that my machine snaps twice instead of one time only which it is doing right now.

I have two approaches so far:

1) Using a memory bit to latch when all snaps advance and one when all snaps retract and use this bit to execute the rungs used to advance and retract the cylinder again for double snap. However, it is becoming very complicated due to several sensors that check different things during snap. This approach is simple but I have to work and re-structure the whole program for this.

2) I tried using JMP and LBL to execute the rungs sensing jump back to the rung when cylinders advance again. However, the controller is going to infinite loop no matter what i do and therefore faults. I find this approach very simple but I am not sure I can use it.

So, can I use any other approach or how can I make some runs execute twice (basically running a for command in C# one time). Machine's basic functionality is:
Shot pin retracts,
Platen comes down
Snaps advance
Snaps checks and other nut checks
Snaps retract
Platen goes back up
Shot pin (lock for platnen advances)
Cycle Complete
Ofcourse, there are other things like vision inspection and other sensors for part but those do not concern our modification.


Thank you in advance guys!đź‘Ľ
 
Do a search for sequencer or state machine as there should be plenty of discussion and examples. I recommend using an integer to keep track of your state rather than individual bits.

Avoid using jumps in ladder logic for sequencing.
 
Don't make the mistake of equating a rung of ladder logic with a step of your machine sequence.
The rung may control what happens during a particular step of the sequence, but is itself evaluated many times while the machine remains in that step.
Your program may be written with transition conditions which determine when to move on to the next step. You may need to create a new rung with different transition conditions that send the sequence from (for example) Step 5 back to Step 3 instead of from Step 5 to Step 6.
 
The normal case with a PLC is that your code executes in a cycle, start to finish, over and over. This happens naturally as part of the basic PLC execution; as soon as it reaches the end of the code, it starts back at the beginning. Normally, your code executes much faster than the real world it controls (one PLC scan is often less than 50 ms). There is no need to try to double execute logic, what you need to do is control when it activates.

I'll second the post that recommended looking into sequencers and state machines. I also second the posts that recommend against jmp/lbl type instructions.

The easiest way I've found to do it is to have an integer tag (or a DINT, whichever) that marks the current step. At each rung, you start with a condition of which steps it is active in. Then you also have logic controlling transitions between the steps, copying the desired step into a "next step" tag. At the end of your code, you copy a "next step" into your "current step"; this protects you from accidentally jumping multiple steps in one scan.

You can do a similar thing with a bits (often in an array), where if bit 1 is on you're in step 1, bit 2 means step 2, etc. The potential downside here is that it is possible to have multiple steps active at the same time; this can be a pain to recover from if it is accidental.
 
Don't make the mistake of equating a rung of ladder logic with a step of your machine sequence.
The rung may control what happens during a particular step of the sequence, but is itself evaluated many times while the machine remains in that step.
Your program may be written with transition conditions which determine when to move on to the next step. You may need to create a new rung with different transition conditions that send the sequence from (for example) Step 5 back to Step 3 instead of from Step 5 to Step 6.

+1 on that.

Ladder logic executes from 10 times a second to hundreds of times per second.

I would avoid latch and unlatch, just in general. You need to remember to change your unlatch logic every time you change your latch logic ... it's simple but you need to remember to do it and sometimes that does not happen. Plus it gives you only 2 states. Then if you need to add a third, you need to re-write your logic.

Counting up is better. Even if you are only counting 1 and 2, then resetting back to 0. If you add another step, it is a small change.

For example, using counter = 0 to do nothing (a nice, safe state to start with!) .. your logic can do nothing the first time around, just increment the counter to 1.

The logic that should run once can check if counter = 1, and when it is done it can increment the counter to 2

The logic that should run twice can check if counter = 1 or counter = 2.

When the counter is 2 and your last operation is complete, you can reset the counter to 0.

That's likely simple enough to start with. It's always a balance between making it as simple as possible, but flexible enough (complicated enough) to allow for easy changes.
 
Got it

I was able to achieve it using integer bit and MOV,EQU commands. I will launch in production soon. Just one question, everyone has every told me that do not use JMP and LBL and avoid it as much as possible. I am just curious and want to know that when do we use those? Like any example would be nice to understand it. Thank you again guys!
 
Last edited:
I was able to achieve it using integer bit and MOV,EQU commands. I will launch in production soon. Just one question, everyone has every told me that do not use JMP and LBL and avoid it as much as possible. I am just curious and want to know that when do we use those? Like any example would be nice to understand it. Thank you again guys!


Ideally, you just don't. Ever.
If you really, absolutely, one hundred and seventy five percent understand what a program is doing, you might use a pair occasionally to skip passed unnecessary logic, but even then, not a good idea.
Use logic to control your machine state. You must already have some in place, or your JMP loop would never exit. If you already have logic in place to exit the loop, you have the logic in place to not need the loop.
 
...Just one question, everyone has every told me that do not use JMP and LBL and avoid it as much as possible. I am just curious and want to know that when do we use those? Like any example would be nice to understand it. Thank you again guys!

The most typical use in my experience has been to implement do-while and repeat-until loops. This has become less necessary in the Logix 5000 (L5K) environment where similar functionality can be achieved with the L5K-style FOR loop. However there are still times when JMP-LBL looping is useful, such as to implement a loop within an Add-On Instruction (AOI).

Another use I have seen is to force a false scan of transitional instruction in the event they need to be executed on successive scans.
 

Similar Topics

Hi, I am new to ladder logic. I have completed a code in the Xinje PLC XC3-32RT-E for one of the machines I am developing. Currently the program...
Replies
11
Views
158
Hello, I am programming a ladder routine that finds a part on a conveyor that has a given part number. I am having no problem finding the part and...
Replies
1
Views
1,865
I've got several ListBoxes that I want to perform the same function on. From my searches, you can accomplish this in VBA by using a FOR loop, but...
Replies
4
Views
2,798
Hello, This is my very first post here - I'm working on a small brewery project with multiple solenoid valves. The instructions follow a set of...
Replies
2
Views
1,729
Hi all, i'm working with STL code following case. STL will continuously loop to check the condition of an array of boolean (Array[0..99] of...
Replies
17
Views
6,077
Back
Top Bottom