
sCarey (Customer) asked a question.
How do I perform boolean math on a range of inputs?
I'm using a P2-622 processor and I want to copy the 16 bit inputs from the I/O table to an internal register so I can perform boolean math on them. Example: DI1.1.4.1 inputs 1-16 > Reg-A, then AND that with Reg-B and put that result in Reg-C. How do I do this using 16 bit registers so that I can use the resulting data for determining machine state/status?
I would use the Pack Bits instruction. Make a 16 bit Integer tag first and then put that in to the Pack Bits instruction output. Then map all your inputs to the 16 input bits.
Other ways to use the bit manipulations:
Thank you for your help, if I want to de-reference the output word into consecutive bits so I can assign individual tags and use that in bit-wise logic, how would you recommend doing that (I'm very familiar with AB, GE and Koyo PLCs so this line of PLC programming is new to me but I'm confident the instruction set will do what I need in building a state-machine.
Productivity abstracts a lot of the underlying addressing and layers to make things more user friendly and "easier", so I don't know if it is really possible to load up the word that corresponds to a set of output bits. At least I know of no way to specifically do that. Instead, you have to go a bit of a roundabout way and make your own tag for the output word (for example "Outputs1-16") and then use an UnPack Bits instruction with the input being the tag you created and the output being the specific DO-0.1.x.y output bit tags (or whatever you renamed the output tags to). Then the integer tag you created can be manipulated like it was your output word and the specific bits will map to the actual output.
Here is an example of how I used the instruction:
My input tag is one that comes from a set of packed bit that is driven from a selection of boolean bits on an HMI. Depending on which specific pistons are selected to be used it maps to the output bits with this instruction in my program.
Thanks again for getting back to me, I appreciate your suggestions. Maybe a call to tech support to have a conversation about my design and solution would be the way to go.
-Carey
Id love some screenshots of the ways you used them in your program with whatever you end upo going with. More examples available on these forums is always a good thing.
I just map the bits of the int directly. Example of your question:
Isn't this the same as Pack Bits instruction though, just with each part of the instruction broken out into its own rung?
Yes, just slightly more flexible and will display the bit detail comment if OP desires.
ok, just wasnt sure if I was missing some difference between the two.