Sign in to follow this  
Followers 0
homer874

Loss for words

16 posts in this topic

I'm looking for design ideas on a PLC program. Here's the problem: I have signals from nine UV amps that indicate flame status: 1 = flame OK, 0 = flame out. I need to set a bit when ANY THREE (or more) of the nine bits go to 0. The bits are stored in adjacent bits of a 16-bit memory word; the extra bits are not used. Simply put, I need to count the zero bits in a word and set a bit when there are three or more. Unfortunately I have never run across a "bit counter" instruction. I have a solution, but I don't like it -- it's long and unwieldy.

Share this post


Link to post
Share on other sites
You didn't mention what processor you are using. Here is some code I use with RsLogix5000. I absolutely hate it but it is a single instruction. Let me know if you come up with something better. Burners is a DINT but I am only looking at the first 9. You could look at you inputs directly using this code. Then just look for it to be greater than 3 CPT BurnersOut "(Burners AND 1)+((Burners AND 2)/2)+((Burners AND 4)/4)+((Burners AND 8)/8)+((Burners AND 16)/16)+((Burners AND 32)/32)+((Burners AND 64)/64)+((Burners AND 128)/128)+((Burners AND 256)/256)" Edited by TWControls

Share this post


Link to post
Share on other sites
In an application, I compare all the word and enable a bit. Maybe this logic can work for you: You only need an inverse logic. Regards!

Share this post


Link to post
Share on other sites
It is a RXLogix5000, and I think that this will work. Thanks for the info! I was looking at compare options, like reply 2, but it is lengthy when you are looking at 9 bits. I will try it in my simulator. Once again thanks.

Share this post


Link to post
Share on other sites
No don't stop looking. I hate that code and want something new Only kidding - Glad to help but PLEASE let me know if you find a better way

Share this post


Link to post
Share on other sites
I am sure this will work, but I have a good friend at Rockwell Automation, programmer, and I left him a message. When he calls me back, hopefully he will have other ideas too. If he does, I will pass them on to you. Again, thanks!

Share this post


Link to post
Share on other sites
I might use a FOR loop containing a BSR or indirect address and compare a bit each reiteration using a counter, then after your loop was executed nine times you could see if the value is GEQ 3 and update your status. Like Alaric's example Edited by Wordman

Share this post


Link to post
Share on other sites
In ST BIT_COUNT := 0; FOR BIT_POINTER := 0 to 8 DO IF BURNERS.BIT_POINTER = 0 THEN BIT_COUNT := BIT_COUNT +1; END_IF; END_FOR; IF BIT_COUNT >=3 THEN BURNER_ALARM := 1 Or you could do it quick and dirty in Ladder like this - its longer (11 rungs), but any maintenance tech can understand it (no looping or fancy instructions) and with Bubba simplicity is more desirable than clever code. Put it in its own SBR. CLR BIT_COUNT XIO BURNERS.0 ADD 1 BIT_COUNT BIT_COUNT XIO BURNERS.1 ADD 1 BIT_COUNT BIT_COUNT XIO BURNERS.2 ADD 1 BIT_COUNT BIT_COUNT . . XIO BURNERS.8 ADD 1 BIT_COUNT BIT_COUNT GEQ BIT_COUNT 3 OTE BURNER_ALARM Another way to do it is to increment a counter if the right most bit is 0, then clear the bit if set and divide by 2, (dividing by 2 shifts the bits one to the right) and repeat. But that one will also fly right over Bubba's head. (edit - first go around was counting set bits, I guess I didnt read the OP very well becasue he was after clear bits. - anyways, I corrected the logic to count cleared bits.) Edited by Alaric

Share this post


Link to post
Share on other sites
I like Alaric's method: if I'm doing a flame monitoring logic, I want simplicity above all else. Put it into a subroutine and you don't even have to look at it. And in RSLogix 5000 v16, go ahead and make it your own instruction ! Edited by Ken Roach

Share this post


Link to post
Share on other sites
I agree with alaric, it is cleaner, easier to trouble shoot later on. probably not as messy as my first thoughts.

Share this post


Link to post
Share on other sites
I like Alarics way too but they are both still messy. Or the for method is messy in the ladder programming. You have to have a routine for each for statement wouldn't you? What we need is a swap bits instruction similar to the swap bytes instruction Ken - Whats this make your own instruction going to be capable of? Will it be in Ladder, Structure, and Flow? You know any details?

Share this post


Link to post
Share on other sites
maybe this is simple enough?

Share this post


Link to post
Share on other sites
Seems like a tailor-made problem for FBC Reference is all 1's If 3 or more 0's found then Result length >=3 and set alarm. P3of9.ACD

Share this post


Link to post
Share on other sites
Thanks Gerry. I had never noticed the FBC instruction before. I knew that it should have one. Now my next question is why did Rockwell shove this instruction into the special section of the Instruction Toolbar instead of putting it in the Compare, File/Misc, or some other section that has similar instructions.

Share this post


Link to post
Share on other sites
Sweet instruction, never had looked at that before. Thanks Gerry!

Share this post


Link to post
Share on other sites
Something told me to check back on my question and I read about your fbc instruction. I like it. thanks for the info. DDT instruction seems like it could be useful for another application i am working on. Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0