3
\$\begingroup\$

I was reading a book about PLCs (Programmable Logic Controllers). I found this paragraph: "A ladder diagram is read from left to right and from top to bottom... The top rung is read from left to right. Then the second rung down is read from left to right and so on....
Each rung must start with an input or inputs and must end with at least one output.".

In another source i found that a rung is a single line...

I am not sure if i understand well... A rung can consist of multiple lines, right? For example is this a rung?

   A      B                  X
--| |----| |--+-------------( )-
              |
   C          |
--| |---------+

Let's say both A and B are 0 and C is 1.

In this case, how it is evaluated? From left to right and from top to bottom:

It can not be: 1. Evaluate (A AND B) 2. Set output X 3. Evaluate C - can't go back?

I think it should be: 1. Evaluate ( A AND B ) OR C 2. Set output X

\$\endgroup\$
1
  • \$\begingroup\$ At last! A PLC question. \$\endgroup\$
    – Transistor
    Jan 31, 2016 at 10:04

4 Answers 4

4
\$\begingroup\$

You are correct in your execution sequence and your statement that a rung can be several lines.

Ladder vs text

In the old days many of the PLCs programmers could switch between ladder and text or 'op-codes' (I can't remember the correct terminology). Mitsubishi still support this. Allen-Bradley does in that you can edit a rung of ladder with a text editor and I've used this function to create ladder logic in Excel (incrementing inputs and outputs by formula) and pasting the results back into the ladder editor. The text version gives a better clue as to the execution. Your code, for example, becomes:

   A      B                  X
--| |----| |--+-------------( )-
              |
   C          |
--| |---------+

OP            VAL    ACC    Comment
ST    A       0      0      ! Store A in ACCumulator
AND   B       0      0      ! Logical AND of B with ACCumulator
OR    C       1      1      ! Logical OR of C with ACCumulator
OUT   X       1             ! Copy ACCumulator to X

Tricky branches require BST (branch start) and BND (branch end) or equivalent which allow intermediate results to be pushed onto a stack.

A quick web search threw up this site which isn't brilliant but may be of some use.


NOT contacts

For anyone else new to this, 'not' contacts are represented by a '/'. See X1 and NOT X2 in the example below. (Many PLCs use 'X' for input and 'Y' for output.)

   X1     X2                 Y0
--| |----|/|--+-------------( )-
              |
   X3         |
--| |---------+

The OP is correct in a sense that it might give more of a visual clue to the order of execution if the ladder was drawn as follows:

   X1     X2   
--| |----|/|--+
              |
   X3         |              Y0
--| |---------+-------------( )-

The brainwave of ladder logic, however, was that it presented logic in the form of an electrical schematic that electricians were familiar with. An electrician would 'know' that current could flow 'up' the or branch to the coil. One of the common problems in electrician training was to get across the concept that, while the ladder listing looks as though everything operates simultaneously, in fact it is being executed sequentially.

Taking advantage of sequential scan

The home-made one-shot example below shows an example of using sequential logic which might not work with real relay logic.

! C0 fires for one scan when X1 turns on
! provided the one-shot memory is off.
   X1     C1                 C0
--| |----|/|----------------( )-

! C1 'remembers' that X1 was on.
   X1                        C1
--| |-----------------------( )-

! Y0 fires for one program scan.
   C0                        Y0
--| |-----------------------( )-

The logic should be fairly clear. Trying to do this with relays would create a race condition (although there would be other solutions in that case).


Program execution order

Typically PLCs task execution order runs as follows:

  • Read the inputs.
  • Execute the logic.
  • Write the outputs.
  • Handle other tasks, etc.

Each 'scan' on newer processors takes < 1 ms which has come down a lot from the early days where 20 - 50 ms would have been common for larger programs.


Online status monitoring

For those new to the subject: the ladder diagram is also very useful for online debugging. The status of the contacts or 'power flow' is indicated by changing colour or wire representation.

   X1     X2                 Y0
--| |--==|/|==+=============( )-
              |
   X3         |
==| |=========+

In the example above we can see that we have an open contact in the first branch (indicating that X1 is off) whereas the lower branch has a complete circuit through X3 to Y0 which turns on. This gives an easy to understand visualisation of the program logic.

\$\endgroup\$
1
\$\begingroup\$

Yes, all the branches leading to the output must be evaluated before the output can be set. Actual evaluation, if you're familiar with reverse Polish and stacks, is more like

push A

push B

and

push C

or

pop (output)

\$\endgroup\$
0
\$\begingroup\$

Within a rung you can have branches, that either converge on an action, or split out into several actions. There are a few limitations and differences between PLC manufactures but generally branches will be evaluated from left to right and then top to bottom.

So taking your example it equates to the following logic: X = (A AND B) OR C

The easiest way to think about the conditions within a rung is that conditions in series are the logical equivalent to AND, while conditions in parallel are the logical equivalent to OR.

A few examples:

-A---B---(Y) |-C-|

X = A AND (B OR C)

Or two outputs

-A---B--(X) |-C--(Y)

X = A AND B Y = A AND C

\$\endgroup\$
0
\$\begingroup\$

basically the part about order means that decisions made in the upper rungs will have immediate effect in the rungs below them, but decisions from the lower rungs will have to wait for the next round of the evaluator before they take effect in rows above them.

yeah, the A,B, and C count as one rung

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.