Is there a better way?

PhilipD

Member
Join Date
Nov 2009
Location
Humboldt, TN
Posts
117
Hi all,

Here is a problem I had and have a solution for but I'm wondering is there is a more "eloquent" way.

I have 5 two position, maintained switches marked "ON" and "OFF". I need to know when any one (and only one) of the switches is on. Each switch is wired to its own input labeled Bypass Switch 1 through Bypass Switch 5.

I used this code to determine when only one switch is on.

Bypass.jpg
Bypass.jpg


Any suggestions?
Thanks.
 
Last edited:
count := 0
if SW1 then count:=count+1;
if SW2 then count:=count+1;
if SW3 then count:=count+1;
if SW4 then count:=count+1;
if SW5 then count:=count+1;
if count = 1 then OTE=ON;
 
Hi all,

Here is a problem I had and have a solution for but I'm wondering is there is a more "eloquent" way.

I have 5 two position, maintained switches marked "ON" and "OFF". I need to know when any one (and only one) of the switches is on. Each switch is wired to its own input labeled Bypass Switch 1 through Bypass Switch 5.

I used this code to determine when only one switch is on.

Bypass.jpg
Bypass.jpg


Any suggestions?
Thanks.

You say switches 'ON', but your rung logic infers these are N/C switches, is that correct ?

If they are, that is an unusual configuration - consider the case you are running with NO bypass switches turned to the 'ON' position, and a wire comes loose off one of them. The logic would pick this up as the bypass switch being turned 'ON'.

Anyway, you asked if there was a "better way". Better for who/what - the processor, or the maintenance guy who has to debug it at some ungodly hour.....

The way you have it, the logic construct is simple, easy to understand, and is so much more "visual", when viewing the ladder, than the counting method proposed by L D[AR2,P#0.0]
 
For arbitrary five bits, your's is good there is (that i know, for five, i would not count it). One can shave six xic's from it but that does not really matter.

But if bit count to check get's high, just count them like ld.

If all bits to check are in same word, then you can check if its in power of two (if looking for trues).
 
Last edited:
Not a better way just a different way

binary to decimal
11110 - 30
11101 - 29
11011 - 27
10111 - 23
01111 - 15

Then use the switch address, to an EQUals to, the decimal number, to set the output
 
Last edited:
PhilipD,

So, is your goal to see if any of the Bypass Switches are on and which one is it? If that is your goal, then something like this would work.


X001 X002 X003 X004 X005 C4
|-[ ]----[/]----[/]----[/]----[/]------(OUT)-| Bypass 1 on

X001 X002 X003 X004 X005 C5
|-[/]----[ ]----[/]----[/]----[/]------(OUT)-| Bypass 2 on

X001 X002 X003 X004 X005 C6
|-[ ]----[/]----[ ]----[/]----[/]------(OUT)-| Bypass 3 on

X001 X002 X003 X004 X005 C7
|-[ ]----[/]----[/]----[ ]----[/]------(OUT)-| Bypass 4 on

X001 X002 X003 X004 X005 C8
|-[ ]----[/]----[/]----[/]----[/]------(OUT)-| Bypass 5 on


Any changes in the states of the Bypass Switches would indicate which Bypass Switch was turned on or off.

BTW, are you using the Click PLC? I have this software installed on my laptop and if you need more help you can send it to me.
 
Last edited:
BTW, are you using the Click PLC? I have this software installed on my laptop and if you need more help you can send it to me.

Why, yes I am using a Click PLC. I installed it this morning. Thank you for your offer to help with the program but it appears to be working OK. Just a small program to control 5 air solenoids and 5 conveyors. I used the drum instruction to cycle from one to the other. Each conveyor has a bypass switch and that is the reason for the above code.
 
Another not better just different way

Not a better way just a different way

binary to decimal
11110 - 30
11101 - 29
11011 - 27
10111 - 23
01111 - 15

Then use the switch address, to an EQUals to, the decimal number, to set the output

As to the meaning of better, this is really for me. Just want to see other methods.

The value in DS1 will change with each conveyor in bypass. Of course the logic must be placed in the ladder before you need to use it. The only time this would be better than your method would be if you needed to know the number of conveyors in bypass.

zeroeachscan.jpg
 
count := 0
if SW1 then count:=count+1;
if SW2 then count:=count+1;
if SW3 then count:=count+1;
if SW4 then count:=count+1;
if SW5 then count:=count+1;
if count = 1 then OTE=ON;

Interesting, LD [AR2, P#0.0] gave a much more efficient method but it seems to have been dismissed. It seems very logical to seasoned S5/S7 programmers, Is it so difficult to do in AB products?

Nick
 
Interesting, LD [AR2, P#0.0] gave a much more efficient method but it seems to have been dismissed. It seems very logical to seasoned S5/S7 programmers, Is it so difficult to do in AB products?

Nick

Not dismissed at all. I am studying all the posted examples and I am sure I will have the chance to use each of them at some point in the future.

This particular program was written for a Click PLC -- an Automation Direct product. Both AB and AD PLCs could implement this logic without to much difficulty.

I wish I had titled this thread "Is there another way?" The nuances of language can be misleading but that is being discussed in a different thread.
 
Last edited:
Interesting, LD [AR2, P#0.0] gave a much more efficient method but it seems to have been dismissed. It seems very logical to seasoned S5/S7 programmers, Is it so difficult to do in AB products?

Nick

Nick, I didn't dismiss it either, but I'm not convinced that method is "more efficient" in any platform. Certainly in A-B it would not be, the simple bit instructions XICs and XIOs would execute way faster.

And of course, it is more "visible", because you can see the state of the inputs on each and every rung.

Mixing simple logic and math instructions may be just too much for the typical maint. tech, who may have to debug this when he's not 100% awake.

PS. No, not difficult,it is very easy to do the same in A-B products.
 
Last edited:
Nick, I didn't dismiss it either, but I'm not convinced that method is "more efficient" in any platform. Certainly in A-B it would not be, the simple bit instructions XICs and XIOs would execute way faster.

And of course, it is more "visible", because you can see the state of the inputs on each and every rung.

Mixing simple logic and math instructions may be just too much for the typical maint. tech, who may have to debug this when he's not 100% awake.

PS. No, not difficult,it is very easy to do the same in A-B products.
I agree with this post 100%.

Not just the typical maint. tech, but everybody else that has to work on his system. That's why I believe the KISS method, which means less programming. That's why I shown my method in my post the way I did and is the same as Philip's thinking.
 

Similar Topics

Good Afternoon , It seems like we always have problems with using Type J Thermocouples with our slip rings . Would using a RTD at 10...
Replies
6
Views
1,643
I am beginner in B&R Automation Studio and TIA Portal. Have an experience in electrical part of PLC cabinets. Now its time to get a new skills...
Replies
8
Views
1,674
Bla Bla Bla, why doesn't it work, l need help and l don't understand PLC's. Or better they understand everything, but can't understand +1 -1 = 6...
Replies
22
Views
6,008
I rarely need to add a network card to the drives we install... very rarely. But my sales-guy said he needs to quote a network-connected ACH580...
Replies
6
Views
2,595
I'm currently on a research project where I can send tag read & write requests to both SLC as well as CLX controllers. Presently, there's no...
Replies
8
Views
2,413
Back
Top Bottom