Order of ladder execution

Ltpriyank

Member
Join Date
Sep 2020
Location
Pune
Posts
24
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
 
My understanding is that it depends on the processor. For example, I believe older Allen-Bradley processors (PLC5, SLC etc) executed synchronously (top to bottom), whereas the newer Logix (Control/CompactLogix) execute asynchronously. Can't speak to other manufacturer's PLCs.
 
Generally the rule is left to right and to to bottom. Regarding your question, rung 2 will never interrupt rung 5, and in fact rung 2 should should not execute after rung 5 completed until rungs 6, 7, 8, 9, 10, and 1 have also completed.

The issue regarding controllogix in the other post probably refers to input and output scans operating asynchronously, so an input bit's value (state) may change at any time, even between the time one scan starts rung 1 and completes the last rung.

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?).

Another exception is that some ladders (contiguous sets of rungs) can be set to run as timed interrupts (TI), and will interrupt the main, free-running, ladder when the TI ladder's interrupt happens at fixed time intervals.
 
Last edited:
Top to bottom, right to left is industry standard, I agree with drbitboy.

Where it gets tricky could be something with branches:

Tag1 Tag3
--||-------()
|
Tag2 |
--||--|


Whether Tag1 or Tag2 gets evaluated first could depend on which specific PLC platform you are using, but both will be checked before Tag 3.


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?).

For the .EV or .Q, yeah. It's not a bug, it's a feature! :rolleyes:
 
Newer PLCs are really fast so below might not matter.
Older PLCs are probably 10x slower at least and below could matter.

Rung order only matters if your scan time is close to the time difference from the PLC scanning the inputs to the outputs turning on.

This calculation would be an addition of input reaction time + IO card reaction time + scan time + Ouput card reaction time + Output device. Then if you have devices on a network then you have to take this into consideration.
 
PLC Scan

remember the basic concept: PLC scans I/O writes them to an image table then solves the logic of your program based upon the image table for that scan, then writes outputs again based upon image table and your program, then it does some house keeping stuff, comms etc. Then repeats that scan again, so if rung two changed during the scan it would not be seen until next scan. Other tricky thing people miss if the input was on for a very short time like less than scan time that input will not be seen, that is why we have High speed counter cards. Also interrupts can be be called and change the order, so an interrupt might be called and then acted upon immediately not waiting for complete scan.
Hope this helps.
 
That’s a simple question but the answer is not quite as simple but it is important to understand it.

The older SLC and PLC’s scan differently than the newer Logix processors
This is my understanding from information from Rockwell
With the older processors they scan the base program (2) is always scanned and by default top left to bottom right.
They update the Input data table from the real inputs, then the program 2. Program 2 may call other programs from within it using jump sub function when the called program has ended the program execution will continue on the next rung below the jump. At the end of program 2 the processor updates the outputs from the output table then it checks the communication ports and handles them as needed. The remote I/O as its own module and processor with its own I/O data table that updated from the module. The program processor updated the module I/O table and the module reads and from and wrights to the remote devices as it can.
The programs themselves are scanned / evaluated
As for the rung branches the program evaluates the top left to bottom right. Each branch is evaluated until it evaluates a false statement then it falls back to the next branch if no branch evaluates true then rung scan is terminated if the output is an OTE or other function then because the rung is false the output is set false and the scan goes on to the next rung if the output us a LATCH or UNLATCH they will remain unchanged . Only the first branch that all element evaluate to true is evaluated as true branch and the evaluation goes on to the next element in the rung, all the lower branches are not evaluated at all. Output branches are executed top to bottom

On the newer Logix processors they handle things a bit differently
First understand the they have multiple CPU’s in them the one I inquired about some years back had 4 intel P4s just for the processor. The communication is has it own processor to handle it’s job and of course each communication modules had their own processors all of these work together to provide very fast scan and communication times. The newer processors I would assume have even more CPU’s to handle their greater capabilities.
They can scan and simultaneously execute multiple ladder programs at a time or the ladder programs can be executed on their own time base ( set in the program setup) or they can be called from any other program using the jump sub function the same as the older processors.
They have a separate processor that handle the updates to the I/O it reads the real inputs and updates the input data table and it reads the output data table and wrights to the real outputs all outside of any program execution scans
All ladders programs are scanned top to bottom and left to right
Rung branches are handled the same as the older plc’s top left to bottom right
The big difference is that in the Logix processors you can execute output in series rung with condition tags between them so output branches are not necessary
Then it comes to Jump to Labels and Jump to Sub Functions
These can quickly get you in trouble I have seen this a few times. They can cause the program to run in a never ending loop within the program without actually executing the main program.
 
With any tag based PLC, make it read synchronously by doing the following:

Make your very first rungs of ladder logic read all inputs from the PLC and write them to a tag.
Next, do your logic using the TAG and NOT the I/O address.
Make your last set of ladder logic using the TAGS to write to the output.

The PLC will (should) read the input data into a tag which won't change for the logic below it until the next scan. Trying to troubleshoot logic with asynchronous inputs is a nightmare IMO.
 
With any tag based PLC, make it read synchronously by doing the following:

Make your very first rungs of ladder logic read all inputs from the PLC and write them to a tag.
Next, do your logic using the TAG and NOT the I/O address.
Make your last set of ladder logic using the TAGS to write to the output.

The PLC will (should) read the input data into a tag which won't change for the logic below it until the next scan. Trying to troubleshoot logic with asynchronous inputs is a nightmare IMO.


In logix maybe, but I wouldn't stretch that to ANY tag based PLC. At the least, not necessary in S71200/1500 from Siemens.


It IS true for PLCs with that do an async IO scan like the AB Logix family, but that is independent of whether it is tag based.
 
The A-B PLC-5 IO & Program Scan are synchronous but there is one situation where a PLC-5 could behave like a ControLogix regarding asynchronous IO & program scan. A PLC-5 has 5 Microprocessors (Local IO / Program Scan, Remote IO Scan, Block Transfer, PID & Comms). If a PLC-5 with an RIO channel in Scanner Mode is getting data from another PLC-5 with an RIO channel in Adapter Mode and the total amount of data is greater than 8 16 bit words. Then the data over 8 words must be transferred via Block Transfer (max 64 words per Block Transfer w/2 words of Status for PLC-5 to PLC-5). Block Transfers (IFE, OFE, HSC, PLC-5 to PLC-5) are executed in the order entered in the Block Transfer Queue and are not Synchronous with the IO and Program Scan so the data in the Block Transfer Data Block can change in the middle of Program Scan. Also, if more than 62 words of Data are Block Transferred PLC-5 to PLC-5 via Remote IO then there is more than one 62 word block which are transferred in series resulting in more data transfer delays.
 
This is all very informative and relevent, but given that the original post was a beginner, I think he may be quivering in a corner somewhere scared witless. :ROFLMAO::ROFLMAO::ROFLMAO::ROFLMAO:


Steve
 
I agree, think of a ladder rung where you have 2 contacts in series and 1 contact in parallel with those going to an output instruction, if you look at it in statement list it is (depending on the platform)
1. AND BIT 1
2. AND BIT 2
3. OR BIT 3
4. OUT BIT 4
so it processes them in the order above
So it is not truly left to right, top to bottom, it evaluates left to right on the first two, then the OR then the output but each rung is separate so in a ladder rung it evaluates the logic in the order above, so for normal purposes it could be considered left to right top to bottom per ladder.
Interrupts or jumps are another thing, in simple terms an interrupt will stop processing the current instruction and store a pointer to where it left off, jump to the logic coded in the interrupt and return to where it left off.
 
...So it is not truly left to right, top to bottom,...

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].
 

Similar Topics

Does anybody have a good document that explains the Execution Order of "Nested Branches"? Thanks
Replies
16
Views
4,576
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,829
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
96
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
551
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,341
Back
Top Bottom