counting bits

godfrey

Member
Join Date
Apr 2002
Location
Charlotte, NC
Posts
412
I have 4 bits B3:0/0 thru B3:0/3 that each represent a unit being on. I want to count the number of bits set to one and return an integer between 0 and 4 representing the number of units on. Without doing it the long way (16 separate rungs with IF and MOV statements) is there something simpler? I'm using a SLC 5/05.
 
5 lines, 1 rung:

1 - Clear a register (let's say N7:0)
2. - If bit 1 then add 1 to N7:0
3. - If bit 2 then add 1 to N7:0
4. - If bit 3 then add 1 to N7:0
5. - If bit 4 then add 1 to N7:0
 
Maintain a "Unit-ON" count.

Each time you turn one of the units ON, ADD 1 to Vxxx.
Each time you turn one of the units OFF, SUB 1 from Vxxx.

To see current ON-Status, read Vxxx.
 

Similar Topics

Hello! I have an application where I can only have 3 pumps running out of 6. I load the pumpRunning bits into an array. What I need to do is...
Replies
6
Views
3,163
Hello, I am in need of a solution to a problem I've failed to come up with a solution to that doesn't take entirely too long for my needs. I...
Replies
40
Views
15,771
This may be a foolish question, but is their a simple way to count the number of active bits in PLC-5? I can think of some complex ways to do...
Replies
8
Views
5,517
I'm having a mental block this morning. Want to do something very simple. I've got a number of enable bits in a byte and I've got a real which I...
Replies
3
Views
3,179
Happy New Year all! Does anyone have a good method for counting the bits that are 1 (on) in a single word, using Rockwell RSLogix500. I have a...
Replies
8
Views
12,069
Back
Top Bottom