Bob...
The easiest way to do this is with an "INDEX". The basic scheme is as follows:
1. Create a normal FIFO Register
You expect to have only 8-lids in the area so make your register 10-words long.
For example, Begin at V101, Size = 10-words
Register = V101 through V110
2. Dedicate one V-mem location for holding the Index Value.
V100, for example. Set the initial value in V100 to "10".
In some situations, you might want to clear the system and restart. In that case, you will need to reset V100 to "10".
3. The register is loaded by using the COPY, MOVE-WORD or whatever function you have that allows the use of an "INDEX". V100 is the base address (even though it is outside of the register). Loading is performed relative to the base address. After loading an evaluation, decrement the Index value (V100).
4. Unload the register by simply turning ON the shift-bit for one-scan. After shifting the register, increment the Index value (V100).
Let's say that your evaluation is GOOD = "0" and NO-GOOD = "1".
When an evaluation occurs, Do Load Routine...
Begin Load Routine:
If the evaluation = "0" then skip to Label-1,
Else,... evaluation = "1", so, do next line.
Write the evaluation to V100 with INDEX=V100. (Move on to DEC Instruction).
(Label-1)
DEC V100 or V100 = V100 - 1 (SUB)
End Load Routine:
.
If the evaluation is "0", then the routine skips to Label-1 and the Index value (V100) is decremented. End of routine.
If the evaluation is a "1", then the routine copies the evaluation to the current location, identified as V100 with the Index specified in V100 (If V100="10", then destination is V110). The routine then executes the DEC Instruction (or SUB Instruction).
Done with Load Routine.
When a lid arrives at the Ejection Station (PE just ON), Do Unload Routine...
Begin Unload Routine:
If V110 = "0", then skip to Label-2,
Else,... V110 = "1", so, do next line.
Initiate Eject Routine (Set or Latch a bit to exercise the Eject Routine).
(Label-2)
Shift the Register (turn ON "Shift-Reg" bit for one scan).
INC V100 or V100 = V100 + 1 (ADD)
End Unload Routine:
.
If V110 has a "0", then the lid is GOOD, do not eject! Skip to Label-2 and INC the Index value AND Shift the Register.
If V110 has a "1", then the lid is NO-GOOD, eject! Initiate the Eject Routine and then go to the next line. Shift the Register and INC the Index value.
Done with Unload Routine.
If at any time you find that the Index Value is "2", you probably have a jam of some kind. You can use that info to stop the line, set an alarm... whatever.
Happy Sailing!