TConnolly
Lifetime Supporting Member
ganutenator said:Important - if you multiply 16,384 (bit 14 on) by 2 you get 32,768 which is larger than the maximum value allowable in an AB PLC5. The AB uses bit 15 as the sign bit. I don't have a PLC handy right now to test this to see how it reacts. I know that it will set the overflow bit, but I don't know what the bit pattern would look like after 16,384 X 2. Anybody have any thoughts on this?
You may be better off using the Bit Shift Left instruction.
When you roll over from 32767 to 32768 in 2's compliment binary numbers you move from 0111111111111111 to 100000000000000. You are correct that the high order bit is the sign bit. The value 100000000000000 is -32768. 1000000000000001 is -32767. 111111111111111 is -1. Add 1 more to it and it rolls over again you loose the highest order bit as it shifts out, leaving you with 00000000000000, or -1 + 1 = 0.
ptine said:If you choose you can rest the counter but I don't believe you have to because the overflow will be set when ACC>Preset but it doesn't affect the function of your pushbutton. The ACC value will just wrap around.
You are correct, it will roll around and preserve the binary sequence perfectly.
Last edited: