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.