Now I wonder about the elevators...
It looks like you need a 32 bit encoder counter. It is easy enough to make a 32 bit counter if your PLC supports 32 bit numbers. The key is to calculate the difference in counts during the last scan.
Code:
nDifCounts = nHWCounter - nOldHWCounter ;; THIS IS KEY!!!!!
nOldHWCounter = nHWCounter;
The only limitation is that the difference between counts CAN NOT exceed half of the total number of counts. In other words, one must make sure that a 16 bit counter never gets more than + or - 32767 counts in one scan. If you do then how do you know which direction you went? ( Actually you can tell with tricky programming )
Now add the SIGN EXTENDED 16 value to the 32 bit software counter. AB PLCs will automatically sign extend 16 bit values to 32 bit values IF the PLC supports 32 bit ints.
Code:
lSWcounter = lSWCounter + nDifCounts
HOWEVER, the SLC is crippled and doesn’t support 32 bit math easily. Therefore I will cheat and use floats. In this case the equation above becomes
Code:
fSWCounter = fSWCounter + nDifCounts
fSWCounter is now a floating point value that will accurately count to + or – 16,277,200 before losing precision. ( We covered this 2 or 3 weeks ago )
NOW, you can use the nDifCounts to create multiple floating point counters.
When you need to reset the counts because you are starting a new board you should just clear the floating point counter. NEVER reset the hardware counter as this may interfere with the multiple floating point counters. ALWAYS use the difference in hardware counts to increment software counters.
Actually, I would modify the equation above my doing some scaling too so I can deal in inches or meters. You may suffer
Code:
fSWCounter = fSWCounter + nDifCounts ; The PLC will convert the integer to a float
Only the floating point counts ( software counters ) should be reset or modified.
BTW, I use the first letter to indicate the type if the variable
n for 16 bit signed integer
l for 32 bit signed integer
f for floats
About the NEVER. I NEVER reset the counter because the hardware I use doesn’t require that I do. When an input comes in to start an event my hardware LATCHES the current count. That way I can tell where the input occurred relative to the previous hardware count and the current hardware count. The lack of a input latch on PLCs make them unsuitable for many registration tasks.