# How to program this logic in Logix5000

## 4 posts in this topic

Hi, folks, how’s going?

Could you give a hand to program this logic: in Logix5000, there are 6 bits “testbit.0”, “testbit.1” ……”testbit.5”.

If any two of them are ON at the same time, the bit “testbit.10” will be ON.

How can we program it? I edited 7 rungs to make it, but it does not look like the best way.

Thanks a lot.

##### Share on other sites

The easiest way would be to use a function block routine with a Boolean And (BAND) instruction. It requires any of two inputs to be on for the output to go true. Put bits 0 through 5 on the input side, bit ten on the output side.

##### Share on other sites

think this is a good one

//scan bit
for fIndex:= 0 to 6 do
if  testbit.[fIndex] then
testResult := testResult + 1;
end_if;
end_for;

//set-reset result and restart
if fIndex > 5 then
if testResult > 1 then
testbit.10 := 1;
else
testbit.10 := 0;
end_if;
fIndex := 0;
testResult:= 0;
end_if;

##### Share on other sites

there are many ways to do this but.... i am not sure you clarified problem. is it EXACTLY two set bits that need to be detected, or AT LEAST two bits set?

Assuming the later, here is one ways that does not require loops:

A = A AND 63 ; optional, just making sure only 6-bits are really evaluated, but mask can be pretty much anything, even with gaps.

B=A AND (-A) ; find least significant bit that is set

Bit10 = (A<>0) AND (A<>B) ; set Bit10 if two or more bits are set

1 person likes this