Question on Valid Ladder Logic

M

Thread Starter

M Griffin

I have been writing a soft logic system, and I recently added ladder logic to the existing IL system. In the course of creating some test cases, I came up with a sample rung which I can draw as ladder, but which I don't think is possible as IL (Instruction List).

I will start off with a sample of similar *valid* ladder logic. I have posted a screen shot of this valid rung at the following URL.

Valid Ladder Logic: http://tinypic.com/r/p37g6/3

The IL for this is
NETWORK 1
STR X1
AND X2
STR C1
AND T2
ORSTR
AND CT55
OUT Y99

For anyone not familiar with the above syntax, The equivalent for this in Siemens S7-200 syntax would be:

LD I0.0
A I0.1
LD M0.1
AND T2
OLD
A C55
= Q9.9


Now if I add a contact as shown in the next screen shot, I get something that I think has no direct equivalent in IL (the extra contact was added in manually). The URL for that screen shot is here:

Invalid Ladder Logic?: http://tinypic.com/r/sy6ott/3

Can anyone think of how to write this in IL, or is it fundamentally impossible? I'm not looking for rewritten logic which has the same effect, I am looking for a direct translation. What I am looking for is whether I can safely drop this test case as "logically impossible", or whether I am overlooking something obvious.

What I think I have here is a fundamental rule that a contact may not straddle an ORSTR or ANDSTR (OLD or ALD in Siemens S7-200 terminology). In that case, there would be another case which I haven't shown here (with the ORSTR replaced with an ANDSTR, and the X1, X2 contacts in series with C1, T2).

Opinions?

The project itself is at: http://sourceforge.net/projects/mblogic/
 
J

James Ingraham

Short answer: I think you're right.

Longer answer:
"I came up with a sample rung which I can draw as ladder..."

Hand-draw, maybe. RSLogix 5000 for sure won't let you enter it. I don't think Step 7 will either, but I didn't actually try it.

"...which I don't think is possible as IL (Instruction List)."

I'm no good at IL, so I can't verify this, but I suspect you are correct.

"What I am looking for is whether I can safely drop this test case as "logically impossible", or whether I am overlooking something obvious."

IMHO, you can drop this test case, for whatever that's worth.

"What I think I have here is a fundamental rule that a contact may not straddle an ORSTR or ANDSTR."

I can't logic through this to a proof, but again I think you are right that you can't "jump out" of logic like this. In other words, you have to rejoin the nearest vertical branch before you can go horizontal again.

-James Ingraham
Sage Automation, Inc.
 
The ladder logic editor I wrote considers that an error too, but it is a limitation of the reduction algorithm not because it is logically impossible. I never had any users complain, so I never bothered to improve it. The work around is to simply repeat the C1 contact instead of re-using one. A slightly smarter reduction algorithm would recognize that and do it automatically.
 
W

William Sturm

I thought about trying to come up with some kind of IL equivelent for you, but the bottom line for me is that I would never design a rung that way. You may as well make a few basic rules about how rungs can be built and stick with it.

Bill Sturm
 
B

Bruce Durdle

Michael,

Your "invalid ladder" may be possible in ladder logic, but is the first step towards spaghetti code. Your test as to whether a ladder can be expressed in formal IL may be a good filter for bad code!

Cheers,
Bruce.
 
Thanks to all for their replies. I will assume then that this is not valid ladder logic and not worry about it.

The software that I've written will translate IL to ladder. The "good" example was created that way. The "bad" example was created by taking the output and modifying it by hand. The algorithm that I am using to draw ladder from IL won't work with the "bad" example, so I was wondering if I should be investigating other approaches. I guess I will stick with what I have.

I suspect that this is a fundamental limitation inherent to any IL/ladder implementation because of the way that IL has to execute. It would be possible to create IL that did the same thing, but only by breaking the one-to-one correspondence between IL instructions and ladder symbols. Doing that would add a lot of complications for no real benefit.

Again, thanks to all for their advice.
 
M
Your sample is invalid in <b>most</b> versions of ladder logic, although some editors will allow it to be drawn then fault on compile. Others, like RSLogix, won't even allow something like that to be drawn.

One version where it will be perfectly valid is Modicon 984 ladder logic. For anyone not familiar with 984LL, it uses networks with an 11 column by 7 row array of nodes instead of rungs with branches. Instructions can be one, two or three nodes high. Networks are solved by columns starting at top left, column 1 row 1 and the results of each node are stored during while the network is solved.

The sample can be expressed as the following instruction list. This is just a first draft and doesn't handle vertical connections (shorts) efficiently. SAVE(column,row) saves the output of a node, while READ(column,row) reads the saved output for the next column.

NETWORK 1
STR X1
SAVE(1,1)
STR C1
SAVE(1,2)
READ(1,1)
AND X2
SAVE(2,1)
READ(1,2)
AND T2
SAVE(2,2)
READ(1,3) /* EMPTY NODE HAS DEFAULT VALUE OF 0 */
READ(1,2)
VSHORT /* VERTICAL SHORT IS EQUIVALENT OF OR INSTRUCTION */
AND Tx
SAVE(2,3)
READ(2,1)
READ(2,2)
VSHORT
AND CT55
SAVE(3,1)
READ(2,3)
SAVE(3,3) /* HORIZONTAL SHORT -> NO INSTRUCTION */
READ(3,1)
READ(3,2)
VSHORT
READ(3,3)
VSHORT
OUT Y99

Mike
 
In reply to Mike: That is an interesting solution, but it breaks the one-for-one instruction translation that I was looking for. Instead of 9 instructions, it takes 28. That takes a much more complex algorithm than I'm using.

What is interesting though is that it is using a matrix to hold intermediate results, rather than a more conventional logic stack.

I could do the same on a stack, if I add an instruction to duplicate the top of the stack, and another instruction to copy arbitrary stack levels up to the top of stack. I don't have those instructions in my own IL execution engine, but the Siemens S7-200 does. In S7-200 IL I think this would be:

<pre>
NETWORK 1
LD I1.0 // Start the rung with I1.0.
A I1.1 // AND the second contact.
LD M0.0 // Start the next branch.
LPS // Make a copy of it.
A Tx // AND the copy with Tx.
LRD 1 // Swap the top of stack.
A T2 // And the start of rung with T2.
LRD 2 // Bring the first branch up to the top.
OLD // OR it with the combination of the second branch.
A C55 // AND it with C55.
OLD // OR with the combination of C1 and Tx.
= Q9.9 // Output the result.
</pre>

However, it also breaks the limitation I imposed of direct one-to-one translation because there are now three hidden stack manipulation instructions present which are not shown in the ladder diagram. If I was going to allow that, I could also just do this:

NETWORK 1
STR X1
AND X2
STR C1
AND T2
ORSTR
AND CT55
STR C1
AND Tx
ORSTR
OUT Y99

That only has one hidden instruction, where the C1 address is loaded again.

So, it still seems to be a fundamental rule of IL to ladder translation that you can't straddle an ORSTR or ANDSTR condition. Any method that attempts it does it by adding "hidden" instructions.

I am avoiding "hidden" instructions because I think it makes the IL and ladder more difficult to understand (the user can't easily predict how it will be translated). It probably also makes it harder to implement ladder translation, although I haven't researched that in detail.

Thank you for your solution though. That is an interesting contrast to other ways of doing it,
 
Top