Beginner ladder logic question

Needz

Member
Join Date
Sep 2014
Location
Pennsylvania
Posts
2
How would I go about writing ladder logic that would turn on an output when one of five inputs is on, any more or less and it would be off? This is using just basic XIC XIO OTE OTL and OTU instructions
 
Hi and welcome to the Forum!

In the interest of you learning, what do you think yourself? Any ideas? Have you attempted anything yet? Even if it's just a sketch?

CLUE: If only one input can turn on the output at a time (XIC), and no more, then for each input, what must each of the other four inputs be doing when that one input is on?

There will most likely be very clever ways thought up how to do this using "half a rung" or the like, by the very clever people on this Forum, but as this is a fundamental type programming question, I would hope, for the moment, you can try to figure out the most straight forward way of doing this, rather than the cleverest.

Regards,
George
 
Would it work to have 1 input on and the other 4 inputs off on one rung with 4 OR's with all the remaining combinations of the other inputs? If so your clue helped immensely, thanks!
 
Last edited:
It is simplified to the extent that 3 of the input instructions appear 3 times (17 contacts), and 2 appear 4 times (as opposed to 5 x 5 = 25 instructions).

No one cares (or knows how) to do contact reduction when you have unlimited PLC contact availability. Back in the old electro-mechanical relay-only days, it was important to reduce the contact count, or you would find you did not have enough relay contacts to do the job. Because all contacts had to be hard-wired, reducing the contacts reduced the amount of wiring.

If you were using relays, you would bring each of the Inputs into a relay coil. With my version, you could use three DPDT relays, and two 3PDT relays (possible to build). Using 5 contacts for each input would be almost impossible to do as there were very few (expensive) 5-pole relays.

5 SWITCHES 1 OUTPUT R1.JPG
 
Last edited:
Conjunctive Normal Form

Here is an alternate implementation for boolean enthusiasts...

Y = (x0|x1|x2|x3|x4)
& (!x0|!x1) & (!x0|!x2) & (!x0|!x3) & (!x0|!x4)
& (!x1|!x2) & (!x1|!x3) & (!x1|!x4)
& (!x2|!x3) & (!x2|!x4)
& (!x3|!x4)

       0            0            0            0            0            1            1            1            2            2            3          LAMP
------[ ]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]---------( )---
| | | | | | | | | | | | | | | | | | | | | |
| 1 | | 1 | | 2 | | 3 | | 4 | | 2 | | 3 | | 4 | | 3 | | 4 | | 4 |
|---[ ]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´
| |
| 2 |
|---[ ]---´
| |
| 3 |
|---[ ]---´
| |
| 4 |
`---[ ]---´



-Trevor
 
Since the OP indicated he was on the right track, Osmanmon's implementation would be the best approach. It's quick to code, less prone to coding error and easier to understand. Plus it's quicker for the PLC to execute the instruction, except Trevor's instruction would execute a bit faster if all the bits were off, but it would take longer to execute if any of the bits were on.
 
Needz said:
Would it work to have 1 input on and the other 4 inputs off on one rung with 4 OR's with all the remaining combinations of the other inputs? If so your clue helped immensely, thanks!

Steve Bailey said:
It sounds like you got it.

+1

Well done! (y)

Tark said:
...Osmanmon's implementation would be the best approach. It's quick to code, less prone to coding error and easier to understand...

Yes, Osmanmom's version, although not written in RSLogix 500 or 5000, is the most direct or straight forward way to program it using XIC, XIO and OTE instructions.

Lancie1 said:
George, I don't want you to be disappointed that no one tried to simplify the rung.

L,

I'd agree that I don't think it simplifies the "look" of the code, but well done on reducing the number of instructions used from 25 to 17. Your rung comment gives you the gist of what it's doing anyway.

I have another way using 19 instructions, but it looks a bit clearer, I think?

1_OF_5_OUTPUT.jpg
 
Here is an alternate implementation for boolean enthusiasts...

Y = (x0|x1|x2|x3|x4)
& (!x0|!x1) & (!x0|!x2) & (!x0|!x3) & (!x0|!x4)
& (!x1|!x2) & (!x1|!x3) & (!x1|!x4)
& (!x2|!x3) & (!x2|!x4)
& (!x3|!x4)

       0            0            0            0            0            1            1            1            2            2            3          LAMP
------[ ]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]----------[/]---------( )---
| | | | | | | | | | | | | | | | | | | | | |
| 1 | | 1 | | 2 | | 3 | | 4 | | 2 | | 3 | | 4 | | 3 | | 4 | | 4 |
|---[ ]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´ `---[/]---´
| |
| 2 |
|---[ ]---´
| |
| 3 |
|---[ ]---´
| |
| 4 |
`---[ ]---´



-Trevor

I just learned something new. Very cool!
 

Everyone's mind works differently but to me osmanmom's example clearly displays the intent of his logic more clearly than the people who tried to simplify the problem by using fewer contacts.

I refer to these "simplified" programming examples as as "Name That Tune" programming. While using less steps or memory it is not always clearer. That's probably why I am not a professional programmer.

Just my 2 cents worth.
 
Everyone's mind works differently but to me osmanmom's example clearly displays the intent of his logic more clearly than the people who tried to simplify the problem by using fewer contacts.
You mis-understand. Most of us (having done this type of problem a thousand times) saw the simple 5-branch solution right away. The only challenge in the problem was to find other not-so-obvious ways.

What would we use in a real program? Probably the 5-branch obvious solution, unless the SLC is limited in memory, such as the SLC 5/00 that I am working with right now, with only 1K of program memory. The program that I am modifying already uses 1014 words (out of the available 1024). In that case, every extra instruction takes 1 or 1.5 words of precious memory. That is when you must find ways to use the least number of instructions on each rung.

I am going to have to review every rung in the program to find the type of reduction as in this problem, where my solution used XICs and XIOs(17 X 1) + ORs(4 x 1.5) + OTE 0.75 = 23.75 words, and the simple-to-understand solution used (25 x 1) + (4 x 1.5) + 0.75 = 31.75 words.
 
Last edited:
dogleg43 said:
Everyone's mind works differently but to me osmanmom's example clearly displays the intent of his logic more clearly than the people who tried to simplify the problem by using fewer contacts.

I refer to these "simplified" programming examples as as "Name That Tune" programming. While using less steps or memory it is not always clearer. That's probably why I am not a professional programmer.

Just my 2 cents worth.

How dare you tar me with the same brush as Lancie1! :eek:
I am deeply offended!(Joke :p)

Don't forget though that while we attempted to simplify it, we did so after making sure the OP learned that simplest method you refer to. That was important to me. You are right, clever coding is not always the simplest, clearest or prettiest!

However, just because we attempted the above, does not mean that's how we try to program everything. It was a fun challenge, that's all. As Lancie1 pointed out, extra contacts are aplenty in a PLC, so why complicate it unnecessarily.

Another thing to note, while you say you are not a professional programmer, is that the above was restricted to only using boolean operands. There are other methods beyond the XIC, XIO instructions that can accomplish the set goal, such as using all five inputs within the same input word. Then using the word value to determine whether only one is on at a time.

Happy coding!

Regards,
George
 

Similar Topics

Hi I have just started using Siemens S7 PLC for a mechatronics degree. I have used Matushita PLCs before but I am having difficulty with Siemens...
Replies
4
Views
3,656
a/ Input – X0 -> turns Output – y0, y5 Input X1 –turns OFF y5, but y0 stays ON b/ Input X0 -> turns Internal Bit M10 and Output Y0 M10 ->...
Replies
14
Views
3,305
Hi, I am a complete beginner with PLCs - so please forgive my ignorance. System: Siemens S7-313C Programming: Step 7 Ladder Diagram 1. How to you...
Replies
4
Views
8,725
Hi all, Writng a FB in ST on Beckhoff TC for a pulser which turns on and off on a cycle, is paused by turning bControlInput to FALSE, but resumes...
Replies
4
Views
109
So to start off: I have no experience with PLC's, but I'm good at figuring stuff out, but I need some help to know if my PLC is just dead in the...
Replies
2
Views
99
Back
Top Bottom