Simplify boolean logic with lots of bit values

toont

Member
Join Date
Sep 2014
Location
Den Bosch
Posts
56
Hi all,

I have the following problem: from a long list of boolean values (about 100) I should program each possible combination with the following conditions:

In order for bool_1 to be true the following must be true:

bool_2 = false
bool_3 = false
bool_4 = false
bool_... = false
bool_100 = false

In order for bool_2 to be true the following must be true:

bool_1 = false
bool_3 = false
bool_4 = false
bool_... = false
bool_100 = false

Etcetera.

The values are scattered in different databases, so not in one array.
Is there an easy way to program this, instead of just copying the long list and removing the one bool that should be true? Perhaps first copy the values states to an array and perform logic on the array? Am working in Step 7 Ladder, but FBD/SCL/STL can also be used.
 
I hope this helps you. I don't have much experience, but, figure this might work.

Count your number of bits from bool_1 to bool_100 as an integer.

Using this count suppose that if bool_n is true and the count is 1 then bool_n is true and all others are false.
 
Something isn't right. What if no bits are set? If all 100 bools are false which one is set? It would seem to me that if all are false the first bool would be always set and then others must be false because the first bool is set.
What if 2 bits are set? Then what?
What are you really trying to do?
 
You'll need a conditioned bool_x, see 'Actual_bool_x' below.


if bool_1 AND sum_of_bools = 1 then
Actual_bool_1 :=1;
end_if;
if bool_2 AND sum_of_bools = 1 then
Actual_bool_1=2 :=1;
end_if;
.
.
...and so on


This could be simplified if your bools were in an array.. and you used a FOR loop.
 
Thanks all for your answers!
There was a mistake in my original post, Peter is right in saying it didn't make sense. "Bool_1" is not set if all others are false, but another bool "SelectionPossible_1". "Bool_1" should have been "SelectionActive_1". Furthermore, in some cases more than one selection can be active.

So:

In order for SelectionPossible_1 to be true the following must be true:

SelectionActive_1 can be true or false
SelectionActive_2 = false
SelectionActive_3 = false
SelectionActivel_4 = false
SelectionActive_... = false
SelectionActive_100 = false

In order for SelectionPossible_2 to be true the following must be true:

SelectionActive_1 = false
SelectionActive_2 can be true or false
SelectionActive_3 = false
SelectionActive_4 = false
SelectionActive_... = false

SelectionActive_89 can be true or false
SelectionActive_90 can be true or false

SelectionActive_91 = false
SelectionActive_... = false
SelectionActive_100 = false

Keeping it in Ladder logic is prefered. For now I could reduce the number of conditions quite a bit by grouping values and by using the midline output # in Step 7 to avoid repeating conditions, resulting in one big network with ifs and ands, but much smaller subsequent networks. Because of the exceptions where more than one selection can be active this seems to be the easiest solution for now.

Excerpt from the big network:
dqgg89.png
 
Last edited:
Maybe array of UDTs where is all possible bits listed for setting bit on. (selection possible)

Then on SCL compare current bits to bit codes listed on arrays. Pretty much arrays and comparing bits :unsure:
 
if you add them and the result > 1 something wrong.
i would sure use a array for this, as the result is a simple loop program.
(btw) i live near you)
 

Similar Topics

I'm using productivity 1000 plc for this. The process is simple i have a wheel with yarn wrapped around it made out of aluminum with evenly spaced...
Replies
9
Views
1,310
Hello everyone I'm trying to simplify this ladder in order to make it more accesible to modifications, just trying to use indirect addressing...
Replies
2
Views
1,948
Very often I have to reverse engineer something from an iFix parameter inside an array to a bit in iFix. It's a pain to do as I've yet to really...
Replies
2
Views
1,897
I'm working with Studio 5000 & FactoryTalk View Studio ME. I have a UDT that contains data for a part as it passes through a system, Timestamps...
Replies
0
Views
1,923
Hi everyone! Is there a way to simplify these 3 rungs into just one? I don't see how... Thanks in advance! Charles
Replies
13
Views
3,721
Back
Top Bottom