Board sorting line

Dear PLC Community,

I am setting up a board sorting line and facing a challenge with programming the sorting logic. Here is the setup:

  • The conveyor often has multiple boards moving simultaneously.
  • I use an encoder to track the position of each board, which I’ve already converted into millimeters.
  • To prevent large numbers from causing issues, the encoder resets to 0 every 500 mm. Each reset increments a tact counter by 1.
  • The first ejection point is 5000 mm (50 tacts) from the entry, the second is 6000 mm (60 tacts), the third is 7000 mm (70 tacts), the fourth is 9000 mm (90 tacts), and the fifth is 10,000 mm (100 tacts).
My controller is an S7-1500, and I am looking for guidance on how to program this system effectively. Specifically:

  1. How can I track multiple boards on the conveyor using the encoder and tacts?
  2. What’s the best approach to implement the sorting logic for the different ejection points?
  3. Any recommendations on managing the reset logic for the encoder to keep track of the board positions accurately?
Thank you in advance for any advice or code examples you can provide!

Best regards
 
Shift register. Create an array that represents the resolution/precision you need. If it's 1 tact, then a 100 element array. Load the shift register with your board length, ID, or whatever is needed to identify the board, then every 500mm shift the data. When the data shows up at the 50th position, it's at the 1st reject and so on.
 
you could use a word shift register & put some kind of board type reference & use a pulse off the tact counter drive.
Think of it like the conveyor as a giant shift register as X taccts tacts long, for example
A conveyor 100 tacts in length, each register in the array is one tact.
So at entry, when a board is detected, a value or ident is entered into the shift register, every tact pulse it is moved along the register, when it reaches **** position 50 tacts it checks against a known id & if same diverts it & the same on all other divert stations, I have done this on a sortation system that had 17 divert stations.
@robertmee You just beat me
 
Is this a lumber sorter? If so, then each boards has at least a grade, length, width and thickness and maybe a species.
I am assuming a tact is the same as what we called a lug. A lug holds one board. How many lugs or boards are there in the system? How many bins? There must be a trimmer and a place where the dimensions are measured. We called these places stations. I would not shift this data if the number of tacts or lugs is large. I for each board I would store a store a station number and encoder count number. Each scan I would compare the encoder with the encoder count stored for each board. If the encoder count reaches or exceed the store encoder count then use the station number to execute the code for that station. Then add the number of encoder counts to the next station. When a board is diverted to the bin then delete the dimensions you know this is an empty tact or lug.

There are fancier ways of doing this. One is to make a separate queue for each event so only the next item in the queue needs to be check.
 
The previous answers are all correct. This is my TL;DR response that expands on those:

Thank you in advance for any advice or code examples you can provide!
All computer programs, including PLC programs, are a model of some subset of the Real World. The primary design decision is the level of fidelity:
  • we care about
    • when a new board is graded (measured?) at the grading station
    • where the measured boards are on the conveyor, or, more specifically
      • when a board arrives at its ejection station
        • PLC programming is primarily about time, and the scan cycle is the clock,
          • when something happens is more important thatn what happens.
  • We don't care about
    • boards that are not yet on the conveyor
    • boards that have been ejected from the conveyor
    • the color of the operator's socks;
    • etc.
All other design decisions follow from that primary design decision (level of fidelity).

1 tact is equivalent either to 500mm:
  • To prevent large numbers from causing issues, the encoder resets to 0 every 500 mm. Each reset increments a tact counter by 1.
or to 100mm:
  • ... 5000 mm (50 tacts) ... 6000 mm (60 tacts), ... 7000 mm (70 tacts), ... 9000 mm (90 tacts) ... 10,000 mm (100 tacts).
I assume one of those is correct and one is a typographical error; it does not matter which as long as it is one or the other.

If we assume that 1 tact is a sufficient level of fidelity, then our model can use units of tacts i.e. the model will keep track of the position of each board on the conveyor to the nearest 1 tact.
  1. How can I track multiple boards on the conveyor using the encoder and tacts?

If we assume that the positions of the ejection stations are at fixed offsets from the measuring (grading?) station, and those offsets have been measured, then the offsets of each ejection station are known as a fixed number of tacts.

Likewise, in PLC memory, the positions of each elements in an array of integers is at a fixed offet from the start of the array i.e. if we say the first element is at offset 0, then the second element is at offset 1, and the tenth element is at offset 9.

Since the boards (and spaces between boards) on the conveyor are similar in this way to the elements of the INT array, we can use values at the positions of the INT array elements to model the state of the boards and spaces at fixed positions along the conveyor, where each offset position in the array models a corresponding offset in tacts, along the conveyor, from the grading station.

So an INT array of 101 elements would have offsets of 0 through 100, and
  • the 1. (first) element at offset 0 of the array could "model" location the grading station that is offset 0tact from the grading station
  • the 51. (fifty-first) element at offset 50 could model the ejection station that is offset 50tact (5000mm) from the grading station.
  • the 61. element at offset 60 could model the ejection station that is offset 60tact (6000mm) from the grading station
  • 71. element at offset 70 models ejection station offset 70tact from grading station
  • 91. element at offset 90 models ejection station offset 90tact from grading station
  • 101. element at offset 100 models ejection station offset 100tact from grading station
  • all of the other elements in the array model positions between stations
    • we never need to look at them, but we do need them to keep track of the boards that are between stations
So the secondary concept of this model is that for every board at some position between the grading station and the last ejections, there will be a non-zero*
integer value at the corresponding position in the model array.

* or non-negative, or more generally non-null i.e. non-(no board present)

The primary concept of this model is this model allows us to separates the modeled movement of the conveyor from model events when boards are graded. This is consistent with the actual system where the
  • encoder reset events that increment the tact count, are
  • asynchronous with, and independent of, the grading events of the boards leaving the grading station.
So consider what happens when each of those asynchronous, independent events occurs in the real system:
  • Encoder reset event
    • Shift all values one position up in the array i.e.
      • last value in the array element at offset 100 is discarded
      • value in the element at offset 99 is moved to the element at offset 100
      • value at offset 98 is moved to offset 99
      • ...
      • value at offset 0 is moved to offset 1
    • Write a 0 (or null) value to the array element at offset 0
  • Grading event
    • Write the value of the grading event to array element at offset 0
That is all it takes to model the positions and grades of all boards on the conveyor between the grading station and the last ejection station.

Sidebar: it might make sense to model the grading station at array offset 100 and the ejection stations at 50tact, 60tact, 70tact, 90tact, and 100tact with array offsets 50, 40, 30, 10, and 0, respectively. That way the code can use the MOVE_BLK_VARIANT to shift all the elements' values down by one position in the array with a single instruction.

2. What’s the best approach to implement the sorting logic for the different ejection points?

The logic for the ejection station that is offset X tacts from the grading station only needs to look, during the time of each scan cycle, at the value of the element at offset X in the array, and if that value corresponds to the grading for that ejection station, then activate the ejection device at that station.

If you search this forum for terms like "array, shift, FIFO, conveyor, eject, and reject," you should find code examples.

3. Any recommendations on managing the reset logic for the encoder to keep track of the board positions accurately?
  • To prevent large numbers from causing issues, the encoder resets to 0 every 500 mm. Each reset increments a tact counter by 1.
This probably provides adequate fidelity for the model.

My only concern is that, while the reset will occur any time the encoder count exceeds 499 (99), depending how the encoder is implemented that reset may not happen when the encoder count is exactly 500 (100), i.e. it could happen at a count of 501 (101) or more. So rather than reset the count to 0, I think it makes more sense to subtract 500 (100) from the count. There may still be a possibility of occasionally missing a count but it is small (1mm, <= 0.01tact) and rare, and should be an insignificant error compared to the gross resolution of tacts; also, because the array size is finite, such errors will not accumulate over time indefinitely, but will rather accumulate only over the residence time of a board between the grading station and the last ejection station.

Another way to do this would be to never reset the encoder but instead use the rising edge either of bit 5 or 6 (64mm per tact or 128mm/tact) of the encoder count, or of bit 8 (512mm per tact) of the encoder count, as the tact trigger. This assumes that the encoder counter register is a binary value that rolls over at some power of 2 e.g. 32767(=215-1) to -32768(=215).
 
The previous answers are all correct. This is my TL;DR response that expands on those:


All computer programs, including PLC programs, are a model of some subset of the Real World. The primary design decision is the level of fidelity:
  • we care about
    • when a new board is graded (measured?) at the grading station
    • where the measured boards are on the conveyor, or, more specifically
      • when a board arrives at its ejection station
        • PLC programming is primarily about time, and the scan cycle is the clock,
          • when something happens is more important thatn what happens.
  • We don't care about
    • boards that are not yet on the conveyor
    • boards that have been ejected from the conveyor
    • the color of the operator's socks;
    • etc.
All other design decisions follow from that primary design decision (level of fidelity).

1 tact is equivalent either to 500mm:

or to 100mm:

I assume one of those is correct and one is a typographical error; it does not matter which as long as it is one or the other.

If we assume that 1 tact is a sufficient level of fidelity, then our model can use units of tacts i.e. the model will keep track of the position of each board on the conveyor to the nearest 1 tact.


If we assume that the positions of the ejection stations are at fixed offsets from the measuring (grading?) station, and those offsets have been measured, then the offsets of each ejection station are known as a fixed number of tacts.

Likewise, in PLC memory, the positions of each elements in an array of integers is at a fixed offet from the start of the array i.e. if we say the first element is at offset 0, then the second element is at offset 1, and the tenth element is at offset 9.

Since the boards (and spaces between boards) on the conveyor are similar in this way to the elements of the INT array, we can use values at the positions of the INT array elements to model the state of the boards and spaces at fixed positions along the conveyor, where each offset position in the array models a corresponding offset in tacts, along the conveyor, from the grading station.

So an INT array of 101 elements would have offsets of 0 through 100, and
  • the 1. (first) element at offset 0 of the array could "model" location the grading station that is offset 0tact from the grading station
  • the 51. (fifty-first) element at offset 50 could model the ejection station that is offset 50tact (5000mm) from the grading station.
  • the 61. element at offset 60 could model the ejection station that is offset 60tact (6000mm) from the grading station
  • 71. element at offset 70 models ejection station offset 70tact from grading station
  • 91. element at offset 90 models ejection station offset 90tact from grading station
  • 101. element at offset 100 models ejection station offset 100tact from grading station
  • all of the other elements in the array model positions between stations
    • we never need to look at them, but we do need them to keep track of the boards that are between stations
So the secondary concept of this model is that for every board at some position between the grading station and the last ejections, there will be a non-zero*
integer value at the corresponding position in the model array.

* or non-negative, or more generally non-null i.e. non-(no board present)

The primary concept of this model is this model allows us to separates the modeled movement of the conveyor from model events when boards are graded. This is consistent with the actual system where the
  • encoder reset events that increment the tact count, are
  • asynchronous with, and independent of, the grading events of the boards leaving the grading station.
So consider what happens when each of those asynchronous, independent events occurs in the real system:
  • Encoder reset event
    • Shift all values one position up in the array i.e.
      • last value in the array element at offset 100 is discarded
      • value in the element at offset 99 is moved to the element at offset 100
      • value at offset 98 is moved to offset 99
      • ...
      • value at offset 0 is moved to offset 1
    • Write a 0 (or null) value to the array element at offset 0
  • Grading event
    • Write the value of the grading event to array element at offset 0
That is all it takes to model the positions and grades of all boards on the conveyor between the grading station and the last ejection station.

Sidebar: it might make sense to model the grading station at array offset 100 and the ejection stations at 50tact, 60tact, 70tact, 90tact, and 100tact with array offsets 50, 40, 30, 10, and 0, respectively. That way the code can use the MOVE_BLK_VARIANT to shift all the elements' values down by one position in the array with a single instruction.



The logic for the ejection station that is offset X tacts from the grading station only needs to look, during the time of each scan cycle, at the value of the element at offset X in the array, and if that value corresponds to the grading for that ejection station, then activate the ejection device at that station.

If you search this forum for terms like "array, shift, FIFO, conveyor, eject, and reject," you should find code examples.



This probably provides adequate fidelity for the model.

My only concern is that, while the reset will occur any time the encoder count exceeds 499 (99), depending how the encoder is implemented that reset may not happen when the encoder count is exactly 500 (100), i.e. it could happen at a count of 501 (101) or more. So rather than reset the count to 0, I think it makes more sense to subtract 500 (100) from the count. There may still be a possibility of occasionally missing a count but it is small (1mm, <= 0.01tact) and rare, and should be an insignificant error compared to the gross resolution of tacts; also, because the array size is finite, such errors will not accumulate over time indefinitely, but will rather accumulate only over the residence time of a board between the grading station and the last ejection station.

Another way to do this would be to never reset the encoder but instead use the rising edge either of bit 5 or 6 (64mm per tact or 128mm/tact) of the encoder count, or of bit 8 (512mm per tact) of the encoder count, as the tact trigger. This assumes that the encoder counter register is a binary value that rolls over at some power of 2 e.g. 32767(=215-1) to -32768(=215).
Fixed ejection points are positioned at 5000 mm (10 tacts), 6000 mm (12 tacts), 7000 mm (14 tacts), 9000 mm (18 tacts), and 10,000 mm (20 tacts). At the entry point, each board is assigned an ejection destination based on its properties (e.g., board length).

The Issue:​

Due to irregular board spacing, a new board may enter the conveyor at a critical moment during a tact increment. For example, if the encoder position is at 200 mm and 300 mm remain before the next tact increment, the new board could travel 300 mm instead of the expected 500 mm before the tact count increases. This discrepancy could lead to incorrect ejection timing.

Key Points:​

  1. All sorting decisions are made at the entry point based on the board’s properties (e.g., destination ejector).
  2. Only the assigned ejection point number (1 to n) is tracked along the conveyor, not detailed board data like width or length.
 
Dear PLC Community,

I am setting up a board sorting line and facing a challenge with programming the sorting logic. Here is the setup:

  • The conveyor often has multiple boards moving simultaneously.
  • I use an encoder to track the position of each board, which I’ve already converted into millimeters.
  • To prevent large numbers from causing issues, the encoder resets to 0 every 500 mm. Each reset increments a tact counter by 1.
  • The first ejection point is 5000 mm (50 tacts) from the entry, the second is 6000 mm (60 tacts), the third is 7000 mm (70 tacts), the fourth is 9000 mm (90 tacts), and the fifth is 10,000 mm (100 tacts).
My controller is an S7-1500, and I am looking for guidance on how to program this system effectively. Specifically:

  1. How can I track multiple boards on the conveyor using the encoder and tacts?
  2. What’s the best approach to implement the sorting logic for the different ejection points?
  3. Any recommendations on managing the reset logic for the encoder to keep track of the board positions accurately?
Thank you in advance for any advice or code examples you can provide!

Best regards

Don't reset the counter. Let it free-run.
My guess is that you don't need more than 1 mm resolution. If you have 1 count per mm you get 65535 mm on a 16 bit counter.

When a board enters the conveyor you save the free running counter value. Say it's 42376 counts.
If you want to know tha boards current position you just take current counter value - saved counter value.
So if the counter now is 55342 the position is 55342-42376=12966 count or mm.
If the result is negative , for example the counter now is 1002 and 1992-42376=-40384. Then you add 65536 do the result.
So -40384+65536=25152 counts or mm.

---

I would do fake photosensors to detect products.
Say that you decide to have a sensor at 10000 mm. If a boards position is between 10000 mm and whatever the lengths of the board is then the sensor is on.

If you do it like this the rest is simple.

---

Also to keep track of the boards, you need to be able to know the position of every board for up to as many boards as the conveyer can fit.
That's all there is to it. When one board leaves the conveyor that "slot" becomes empty. When a new boards enter an empty "slot" now has a board.
 

The Issue:​

Due to irregular board spacing, a new board may enter the conveyor at a critical moment during a tact increment. For example, if the encoder position is at 200 mm and 300 mm remain before the next tact increment, the new board could travel 300 mm instead of the expected 500 mm before the tact count increases. This discrepancy could lead to incorrect ejection timing.
That is a modeling/design problem: a 500mm tact provides insufficient fidelity to model the system adequately; the solution is to use a smaller tact.

TL;DR

The conversion from encoder counts (mm) to tacts is an arbitrary design choice.

As noted by @Pete.S., assuming the boards move less than half a mm per PLC scan cycle, you could have an array of 10000 elements where each tact is 1mm.

PLCs are discrete, digital devices controlling an analog world. The original PLCs were primarily intended to replace (emulate) relays; the original PLC design specified a maximum PLC scan cycle of 100ms, because that is approximately how long it took a relay to close, i.e. the PLC needed to react within 100ms when conditions warranted a relay to change state in order to adequately emulate the physical relays that the PLC was replacing.

In this case, the problem is not with the PLC or the PLC program; the problem is with the system design where the measurement unit of tact is too large to adequately model the real-world system. Fixing the problem of tact size, rather than coding around the problem; once the tact size is fixed, the approaches as as described by any of the responses to this thread will work.
 

Key Points:​

  1. All sorting decisions are made at the entry point based on the board’s properties (e.g., destination ejector).
  2. Only the assigned ejection point number (1 to n) is tracked along the conveyor, not detailed board data like width or length.

Key point #3: the measurement of board position, in tacts, and the scan cycle of the PLC, must have adequate resolution to trigger any of the ejection station within some ±Xmm of the distance from the grading (sorting) station to properly eject each board at its sorting destination. The proposed approaches as described here work with items that move much faster and have tighter tolerances (e.g. soda cans running at hundreds of cans per minute).
 
If this is a proper lumber sorter then there are lugs that stick up from the chain that push the board along. The boards go over a skid plate such the board stays until the lug starts to push it. The boards are then evenly spaced. There only needs to be an array that has as many entries as there could be boards in the system. Each entry has the count till the next station or event.

Doesn't the S7 have 32 bit integers? Big numbers shouldn't be a problem.

My first job out of the Navy was working for a subdivision of USNR that was an OEM for sorter controls.
 
That is a modeling/design problem: a 500mm tact provides insufficient fidelity to model the system adequately; the solution is to use a smaller tact.

TL;DR

The conversion from encoder counts (mm) to tacts is an arbitrary design choice.

As noted by @Pete.S., assuming the boards move less than half a mm per PLC scan cycle, you could have an array of 10000 elements where each tact is 1mm.

PLCs are discrete, digital devices controlling an analog world. The original PLCs were primarily intended to replace (emulate) relays; the original PLC design specified a maximum PLC scan cycle of 100ms, because that is approximately how long it took a relay to close, i.e. the PLC needed to react within 100ms when conditions warranted a relay to change state in order to adequately emulate the physical relays that the PLC was replacing.

In this case, the problem is not with the PLC or the PLC program; the problem is with the system design where the measurement unit of tact is too large to adequately model the real-world system. Fixing the problem of tact size, rather than coding around the problem; once the tact size is fixed, the approaches as as described by any of the responses to this thread will work.

My approach above doesn't use any tracts. It keep track of each board instead and it's current position every scan cycle.

With that approach you could use floating point or whatever for any resolution you want. Or just integers if millimeter is fine.

You can also attach different properties to the boards as they pass different points along the way. For instance if you measure height at one position and then later, at another position, you can decide if you want to push it out or not.

I believe it's better solution in this case. But it depends on the needs of the system and if the programmer is experienced enough to implement it. The PLC itself (S7-1500) can do it without any problem whatsoever.
 
Peters idea is sound as he posted, if it has lugs (or perhaps some extra bolts on the drive do not have to be too fine perhaps the equivelent of 10-50mm) so treat the positioning & comparing the required size with that put into the shift register.
Regardless how you do it, I'm not that used to RSL but I wonder if it is possible to use hardware interrupt to count perhaps more than one running & in 32 bit.
That way you have positioning & size (put into shift register) running on two different counters.
also no real need to worry about positioning if you fit sensors on each divert placed so when the front edge of board is sensed this becomes the divert position (assuming gaps can be detected between boards). Then it would not matter if the shift register location is as you could compare perhaps 3 or 4 of them & if sensor and one of those registers matched the correct size then move board down that line.
Did one in the late 90's it was an existing sorting conveyor with 6 divert points, originally there were 6 people who checked the box on the conveyor & pushed the correct one down the leg, this was automated a bar code scanner fitted & RATs fitted to the divert points & a proximity & toothed wheel fitted to the drive.
It worked well on most of the diverts however, there were two where due to the lower resolution of the conveyor sensor it was a little out (original design tje diverts were a bit random distances) the divert was only wide enough for the boxes tried thing like delay timers etc. but still problems so fitted sensors (we actually did this on all diverts, then did as above using a range of 3 register positions.
 
My approach above doesn't use any tracts. It keep track of each board instead and it's current position every scan cycle.
Well, 1tact is 1 encoder count in that case, so it is advocating higher resolution of the boards' position models, but I get your point.

TL;DR

I would implement this system like this: when a board comes in at encoder value X(mm) and the grader selects the ejection station at offset Ymm, then the code could store the value [X+Y] as the "value" for that board, and when the encoder next has a value of [X+Y] ± some small offset, activate the eject at that station. The comparison for an [X+Y] value near 65535 (or whatever the rollover is for the encoder) will be a bit fiddly, but it can be done.

This makes the comparison step simpler, but would require keeping two pieces of information per board, [X+Y] and the ejection station at offset Y. The original approach also requires keeping two pieces of information per active board , X and the target ejection station, but also requires the addition step for each check.

Both approaches also require a third piece of information: since there will be multiple boards between the grader station and the last ejection station, the X, Y, and any grade information will need to be stored in arrays. Those arrays will need to have enough elements (slots) to represent the maximum number of active board that may be in the system, so the third piece of information will indicate whether or not the elements in the array represent an active board or not. This extra piece of information will also be used to find an array element when a new board is graded. The third piece of information could be encoded into the X and Y values without creating a third array e.g. if both X and Y elements are 0 for a slot, then that slot is available to model a new board.

I have implemented something similar: the system used timers to model positions because the parts were small, tightly packed, and moving quickly compared to the time it took the (r)ejection device to move, so the delay to activate the device was dependent on line speed. The program had 114 timers. Fortunately there was only one (r)ejection station. Using an array of timers was not possible in that particular environment, so the logic to keep track of whether each timer was in use or available for a new part was ... interesting, although fortunately repetitive.

My point is that, while this approach will certainly work, because of the edge cases (encoder rollover) and other infrastructure required to model multiple active boards, the code will be more extensive than that for a shift register.

That said, being more extensive doesn't disqualify it because that doesn't mean it is more complex. The complexities, like comparisons that consider encoder rollover, could be shunted away to user FBs, and the overall code might be easier to read, understand and debug when diagnosing a problem.
 
Don't worry about rollover. Use 32 bit numbers. Have a 32-bit global encoder count that gets incremented by the physical encoder. Now you don't need to worry about rollover. Think about it. At each station store the current global encoder + the encoder offset till the next station and a code for what that station is. every scan compares the global encoder with the stored encoder for each board to see if the global encoder is greater. If so, then execute the function determined by the function code.
Don't make it difficult.
 
Don't worry about rollover. Use 32 bit numbers. Have a 32-bit global encoder count that gets incremented by the physical encoder. Now you don't need to worry about rollover. Think about it. At each station store the current global encoder + the encoder offset till the next station and a code for what that station is. every scan compares the global encoder with the stored encoder for each board to see if the global encoder is greater. If so, then execute the function determined by the function code.
Don't make it difficult.
pfft. what if the stored value* is 232-1? the 32-bit global encoder cannot be greater than that. and what if a second board shows up destined for an ejection station while a previous board is still in the system?

I am not the one making it difficult, OP's process description is what makes it "difficult:"
  1. How can I track multiple boards on the conveyor using the encoder ...

* unsigned 32-bit integers; 231-1 if signed
 

Similar Topics

We have some Z-312J board PLCs, there is a project to integrate Cobots, and the PLC program needs to be modified, How can we get the software for...
0
Replies
100
Views
This is WinCC V17, no I don't know if it is "flexible" "comfort" "professional" "Advanced" or any other snappy marketting word. Attached is a...
10
Replies
299
Views
I have a Siemens s1214. I made the mistake of hot swapping an RS485 board, one mounted at the front. At first the plc would flash lights randomly...
0
Replies
134
Views
There is a pad batch machine and 10 Lenze 9300 servo inverters are used. One of them is the master and they communicate via CN-bus. Additionally...
3
Replies
322
Views
Hi folks, Working on a Power Flex 755 drive that uses a 20-750-UFB-1 Universal Feedback Board to read an analog sin/cos encoder. Experiencing...
0
Replies
436
Views
Top