TL140
Lifetime Supporting Member
when your pointer gets indexed, if your previous reference is true, and your current reference is true before getting indexed, will the instruction being addressed see a true to false to true transition?
| B3:0/[N7:0] B3:1/0 B3:1/2
|--------| |---------[ONS]------( )-|
That's probably the easiest way. In Logix 5000 there is a "DTR" instruction (Data TRansition) which is designed to do exactly this, but (a) I don't think it's available for RSLogix 500, and (b) I've never used it because in my opinion it's no simpler than a NEQ-MOV pair anyway.Would I have to make a compare statement comparing previous int vs new int or is there an easier way?
Also, is there an easy way to tell a total of how many bits are on in a B3 word? Right now I'm having a 1ms pulse on a counter indexing through that word connected to a counter
...on the HMI there's a horse "check in" bit word.
There's Counting bits set bits Brian Kernighan's way. You'll have to convert C into ladder and it's a bit more obscure but it is capable of operating faster than the straight counting methods.Also, is there an easy way to tell a total of how many bits are on in a B3 word?
There's Counting bits set bits Brian Kernighan's way. You'll have to convert C into ladder and it's a bit more obscure but it is capable of operating faster than the straight counting methods.
...which is basically by the sounds of it, more or less what the OP is currently doing (although one scan at a time, with a 1ms pulse, instead of all in one scan).
Here's what Brian's method looks like in Logix 500 ladder. It might be "simpler" in terms of less instructions than other options, but it is as Doug says a little more obscure. And I'm going to disagree with Doug in that I would bet a carton of Australia's finest Pale Ale that a brute force solution would execute faster than any of the other solutions we've thrown up so far
I came up with a different interpretation. Paste this code into Logix 500 to see what it looks like - it's a bit tall to comfortably fit on one screenful. Note that the code for the third rung extends past the window boundary.Here's what Brian's method looks like in Logix 500 ladder.
GRT N7:0 0 ONS B3:0/4 BST CLR N7:1 NXB OTL B3:0/1 BND
MOV N7:1 N7:1
LBL 1 XIC B3:0/1 BST ADD N7:1 1 N7:1 NXB BST SUB N7:0 1 N7:2 NXB AND N7:0 N7:2 N7:0 NXB XIO S:0/2 JMP 1 BND BND
OTU B3:0/1
My error. I was trying save those interested having to sift through the site to find that one item and didn't test the link before posting. For future reference, here's the link to the main page of Bit Twiddling hacks. Something nags at me that it was Peter Nachtwey who first mentioned it here.Side note: I couldn't get your link to work either, so I just googled the guy's name and looked at his theory on stack exchange.
Agreed. But, where available it does save a few clock cycles.The processor math zero flag is a neat trick, but seems like a very processor-specific solution.