Hello
@Melkske/Geert, I don't see any attached pictures.
I would think it would be similar to a quadrature encoding system, where detecting which sensor input has
transitioned from 0 to 1 on the first scan cycle when when both sensors are 1 will be the "downstream" sensor. This assumes the object length in either direction of motion is greater than the distance between sensors.
So the key word is "transitioned." PLC programming is primarily about time:
when something happens is more important than
what happens. A PLC program's logic is repeatedly evaluated in a series of discrete events in
time called
scan cycles.
Consider all possible combinations inputs states from the two sensors (call them LEFT and RIGHT) on any singe scan cycle:
- LEFT is 0; RIGHT is 0
- There is no object in front of either sensor, there is nothing to detect
- LEFT is 1; RIGHT is 0
- There is an object in front of the left sensor, but it is not in front of the right sensor; this could be one of two cases
- the object is moving left-to-right and will block the right sensor shortly
- OR
- the object is moving right-to-left and has just stopped blocking the right sensor
- We cannot tell which case it is from the sensor states alone
- LEFT is 0; RIGHT is 1
- This is the mirror of the previous (LEFT=1; RIGHT=0) combination; the results are the same but mirrored
- LEFT is 1; RIGHT is 1
- There is an object in front of both sensor; this could also be one of two cases
- the object is moving left-to-right and has just started blocking the right sensor, and will stop blocking the left sensor next
- OR
- the object is moving right-to-left and has just started blocking the left sensor, and will stop blocking the right sensor next
The point I am making is that the information on any one scan cycle
alone is not enough to determine the direction of motion. What you will find in LOGO!Soft is that there is an AND-EDGE block, that detects a rising edge transition; that is, on any one current scan cycle
when all of connected inputs of the AND-EDGE are 1 (even if there is only one connection), and on the
previous scan cycle at least one of its connected inputs was 0, then the output of the AND-EDGE becomes 1 until the next scan cycle and it is evaluated again, when it returns to 0. Note, on the next scan cycle, even if all of the connected inputs are still 1, then the logic described will change the output back to 0 because the "previous" scan cycle for that
next scan cycle is the
current scan cycle when the output became 1, and in that "previous" scan cycle at least 1 of the inputs was not 0.
That function is called by many names: edge detector; one-shot.
So for example, if you connected each of the following to it's own AND-EDGE block
- the left sensor alone
- the right sensor alone
- both left and right sensors
then,
when (i.e. on the scan cycle that) the both-sensors' AND-EDGE output becomes 1, only one of the other two AND-EDGE outputs will also be 1 on that same scan cycle (i.e. at the same
time). If the left-only AND-EDGE output is 1, then the object is moving to the left; if the right-only AND-EDGE output is 1, then the object is moving to the right.
Note that there is an assumption the scan cycle time is always short enough that both proximity sensor inputs never transition from 0 to 1 on the same scan cycle i.e. never at the same
time.