logix 5000 bit counting

Winklehoffen

Member
Join Date
Jun 2009
Location
Auckland
Posts
46
I need to determine how many of 5 bools are on. What I'm after is a nice simple bit of code to return an integer result. The solution i have at the moment is not particularly elegant and I'm sure one of you gurus must have a brilliant way of doing this. A cursory search of this place indicates that a fbc might be the way to go but I've never used one before and I'm not entirely sure how i get the result i want from it. Please.help...
 
Here is a simple way of doing it.
Each scan move a zero into a integer (ex. Reset_Count) at the beginning of the following.
After that a series of branches or rungs.
Then if boolean #1 = true Add 1 to Reset_Count.
Then if boolean #2 = true Add 1 to Reset_Count.
Then if boolean #3 = true Add 1 to Reset_Count.

Reset_Count will then give you the total number of booleans that are on.
 
If you don't have the FB language extension and your bools are not in an array then the method Mark suggested is the best way. The amount of time you've spent on this thread so far is more than the time it would take to program that.

CLR BITCOUNT
XIC BOOL1 ADD 1 BITCOUNT BITCOUNT
XIC BOOL2 ADD 1 BITCOUNT BITCOUNT
XIC BOOL3 ADD 1 BITCOUNT BITCOUNT
XIC BOOL4 ADD 1 BITCOUNT BITCOUNT
XIC BOOL5 ADD 1 BITCOUNT BITCOUNT

Don't be afraid of brute force methods just because they aren't elegant. Bubba doesn't get elegant code, and that means you'll eventually be getting a 3:00 am phone call. And for only five booleans it will execute faster than anything else you could do.
 
Last edited:
Thanks Alaric. I have had to come up with more elaborate methods when I had a bunch of inputs to totalize. I could have used counters and did a simple For/Loop if it was in an array.
I could have did it in structured text.
I agree about the Bubba comment though. Most of our electricians are only allowed the standard package of RS5000. Any thing more and they are liable to hurt themseleves.

Bills method is something I will add to my bag of tricks.
 
I guess this would be considered an elaborate method, it's one rung of logic and it will require moving bit status to intergers.
 
Last edited:
Thanks guys this is all great advice. Bill's method intrigues me and as I'm not letting any bubbas anywhere near this code I've gone with that. I'm on site doing this from my phone so I'll have to check out cwals code later.
 

Similar Topics

Hi, I'm just looking for a simple way to make a button in excel (via VBA I presume) to toggle a bit in RSLogix 5000. I just got FactoyTalkLinx...
Replies
9
Views
545
If any of you wizards can help in this I would be ever more grateful. We have this device that generates 9 second pulses coming into a DI module...
Replies
31
Views
3,598
How can I achieve the same functionality in Studio 5000? Image 001.png for the old RSLogix500 program Image 002.png for conversion to Studio...
Replies
6
Views
2,516
Hello, I'm using Compact Logix L33 in RSLogix 5000. I'm trying to message over modbus register that is 16bit UINT. In Rslogix 5000 do I message...
Replies
3
Views
1,505
Hi there, I am accustomed to working with Logix 500 but have a program modification I need to do on a CompactLogix.... I created a timer...no...
Replies
7
Views
2,442
Back
Top Bottom