Order of ladder execution

asynchronous??? Hehe. Better not be. Unless of course it is intentional(interrupt programming). The whole thing better be deterministic by programming and not preemptively interrupted. Yea, with that, you get into semaphore and signal management...makes sense for a PC but not a PLC.
 
Hello there
I am beginner in plc programming and i have a basic question. Suppose we have a programm of 10 rungs and our 5 th rung is currently being executing so what will happen if some other rung becomes active which is above our 5th rung say 2nd rung


[Note: this post summarizes, I hope, what others have already written in this thread]



I just re-read the original post (above), and I think the bold red rung is meant to say bit (or XIO/XIC/contact/etc/) instead.


In that case, i.e. where a bit (flag/1-0/state/etc.) tested on the 2nd rung becomes active, while the 5th rung is being executed, nothing will happen in that 2nd rung until the next [ladder scan] starts executing that 2nd rung, and any 2nd-rung outputs dependent on that bit will not change until that next [ladder scan]**.



The general rule is that each rung evaluates the state of any memory at the time, and only at the time, that each rung is executed.


So, if the bit changes value after the 2nd rung but before the 5th rung executes, and that change of state is picked up by an [I/O scan]*, and the 5th rung also tests that same bit, then the 5th rung would see a different value for that bit than the 2nd rung of the same [ladder scan].


* Some PLCs only execute an [I/O scan] asynchronously in the time between the end of one [ladder scan] and the start of the next [ladder scan] (e.g. MicroLogix 1100); other PLCs (e.g. ControlLogix or PLC-5, as noted by OldChemEng) execute [I/O scans], [ladder scans], and other activities asynchronously. In the latter case, a bit might change value between the 2nd and 5th rung; in the former case that would not happen, at least not because of an I/O scan.


The point is that it is up to the designer and programmer to understand the behavior of the PLC in question to consider such issues and how to deal with them. In the end, programming, regardless of the environment, almost always boils down to bookkeeping i.e. keeping track of the state of all bits used by the program, and writing code that accounts for all possible behaviors.


** This brings up another issue that has been rolling around in the back of my mind since I started getting into ladder diagrams: while looking at a set of ladder rungs as a physical "circuit" is useful both for understanding and for turning maintenance electricians into troubleshooters if not programmers, the ladder-as-circuit analogy has some limitations, because in a physical circuit, all "rungs" would be evaluated simultaneously and continuously, not sequentially. That said, physical relays typically operate on a 100ms timescale; the original specification for PLCs was the same (100ms) and modern watchdog defaults and any periodic tasks run at 20-50ms, so the practical difference is nil.



It does not matter what you expect the PLC to do, it only matters what it will do. So even though the OP may be a beginner, they are making a very insightful query.
 
Yes, a more accurate (and pedantic) expression might be left-to-right-until-an-end-of-[branch-or-rung]-is-reached, then back to the start-of-the-corresponding-[branch-or-rung], and then down to the next start-of-[branch-or-rung].

Yes DR could not get the wording right but you hit it on the head lol.
 
Hi guys,

I haven't read the whole thread but I smell that Lptriyank has a small misconception here.

All he needs to know is that in general a plc will (in every cycle) read all inputs, execute the logic in its memory and then update its outputs

Please don't confuse him

Bye
 
Hello there
I am beginner in plc programming and i have a basic question. Suppose we have a programm of 10 rungs and our 5 th rung is currently being executing so what will happen if some other rung becomes active which is above our 5th rung say 2nd rung


The highlighted text from your post tells me that you clearly do not have the basic understanding of how PLCs work.

All code is scanned sequentially, left to right, and top to bottom.
 
Thank you

Thank you everyone for giving such elaborative answers. It made my understanding of PLC's a little more clear
 
Thank you everyone for giving such elaborative answers. It made my understanding of PLC's a little more clear


One thing that is worth your consideration, and hopefully aids your understanding, is that during the scan of the user's code, instruction by instruction, the only thing that "links" the instructions together is the current state of the rung, true or false. In Allen-Bradley speak, that is called "Rung Logic Continuity". The left-hand "power rail" of Ladder representation of code starts each rung of code with RLC set to True.

No instruction ever knows what preceded it, or what follows it, they are just handed the current Rung Logic Continuity (RLC), and the instruction either maintains the "True" state if the instruction evaluates as true, or sets the RLC to "False" if it evaluates as false. The RLC is then handed to the next instruction, and so on.
Only "input" type instructions (called "Conditional" instructions) can change the RLC state. "Output" type instructions (unconditional), simply pass the RLC through unaffected.

EDIT : One thing I forgot to state is that a "conditional" (input type) instruction, having been given the RLC as "False", cannot ever turn the RLC to "True" again, and must pass it as "False".

All of the above means, at least for the Logix5000 series of controllers, it is permissible to have multiple "output" type instructions in series, and anywhere on the rung. It is also possible to have "mid-rung" outputs.

Look at the two rungs pictured. They both do exactly the same thing, but the first rung uses 7 "instructions" (branch start and end are instructions in the code), and the second rung uses only 4. That is a huge saving, in memory used, and execution time.

2020-10-01_094425.jpg
 
Last edited:
Hi guys,

All he needs to know is that in general a plc will (in every cycle) read all inputs, execute the logic in its memory and then update its outputs


That is only true sometimes. Even in PLC's that actually do have a synchronous Input - Program scan - Output cycle, there are instructions to immediately read a physical input, or immediately update a physical output.


More and more though the IO scan is completely asynchronous to the program scan.


You need to know how the particular processor you are applying works. In General.
 
Modicon, perhaps others, is quite a bit different than others. It will mess people up.

Thank you for that. It got me closer to understandingwhat seemed like a strange behavior testing an M241.
So, it is top to bottom, left to right in "columns", right?

Thanks again.
 
Thank you for that. It got me closer to understandingwhat seemed like a strange behavior testing an M241.
So, it is top to bottom, left to right in "columns", right?
Thanks again.


Yes one network at a time (Modicons and SCADAPacks I have worked on 20 years ago had 11 columns 7 rung networks) then move to the next network. ( just to add more confusion)

See pdf
 
Last edited:
One exception I have seen is that siemens will, incorrectly in my mind, re-execute a timing instruction from a previous rung if that timing instruction's data are referenced e.g. Timer.ET (or is it .PV?).

It updates the timer values. It does not specifically re-executes instructions on any rungs previous or not.
You can see that executes the time instruction real time to provide the most up to date information, specifically .Q and. ET (elapsed time)

Compared to a CPU that I am current testing and still figuring out how it works, it seems that is far superior. It looks like Modicon M241 executes the timer instruction and anything related to it at the end of the block. I see that as quite problematic and honestly I don't see what the value of the timer is if its values are influenced by scan time. I hope I'm wrong on my understanding.
 
Thank you for that. It got me closer to understandingwhat seemed like a strange behavior testing an M241.
So, it is top to bottom, left to right in "columns", right?

Thanks again.

Be carefull now.
For normal modicons yes (m340,premium,micros, quantums,m580)
M241 is codesys plc. Not sure how codesys scans but not necessarily the same as above mentioned
 

Similar Topics

Does anybody have a good document that explains the Execution Order of "Nested Branches"? Thanks
Replies
16
Views
4,605
Can anyone help Using Gx works 2 or Codesys Software Want to arrange values in ascending order from ex 1...10 to d1...d10 register after...
Replies
8
Views
3,839
Afternoon all, I'm working on setting up a large excel recipe table for porting updates through the Linx Gateway RTD/DDE function into my recipe...
Replies
2
Views
110
We are trying to poll data coming from a PLC for remote monitoring we have the IP address of the PLC and the default port number and the path is...
Replies
25
Views
572
Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,359
Back
Top Bottom