Here's a simple implementation of a latch in ladder logic:
|-----[ ]-----+-----------------( )--------|
| input | output |
| | |
|-----[ ]-----' |
output
and here's one where you can reset the output:
|-----[ ]-------------+---------( )--------|
| input | output |
| | |
|-----[ ]-----[/]-----' |
output reset
These form the fundamental building blocks for memory in ladder logic. I'm not sure but is this what you're looking for?
Usually a language implementing ladder logic will have higher level elements that implement memory such as D and T flip-flops. Read the documentation of your ladder logic implementation to see if they're available.
OK, from your comments it looks like what you want is:
// Pseudocode:
// a = sensor 1
// b = sensor 2
if (a) {
a_triggered = true;
}
if (b) {
if (!a_triggered) {
REVERSE_DETECTED();
}
else {
a_triggered = false;
}
}
This assumes the sensors are close together such that the transition is 10->11->01 such that you can't detect the travel direction while the item is triggering both sensors. Writing this declaratively:
a_triggered = (a || a_triggered) && !(b_triggered && !b);
b_triggered = (b || b_triggered) && a_triggered;
reverse_detected = b && !a_triggered;
Which translates to:
|-----[ ]---------+-----[/]--------( )--------|
| a | c a_triggered |
| | |
|-----[ ]---------' |
| a_triggered |
| |
|-----[ ]---------+-----[ ]--------( )--------|
| b | a_triggered b_triggered |
| | |
|-----[ ]---------' |
| b_triggered |
| |
|-----[ ]----------[/]-------------( )--------|
| b_triggered b c |
| |
|-----[ ]----------[/]-------------( )--------|
| b a_triggered reverse_detected |
Now you can use the reverse detected signal to do what you want. If your ladder language has latches you can do this cleaner:
| _________ |
|-----[ ]--------------------|set latch|------|
| a | | |
|-----[ ]--------------------|clear | |
| c |_________| |
| a_triggered |
| _________ |
|-----[ ]--------------------|set latch|------|
| b | | |
|-----[/]--------------------|clear | |
| a_triggered |_________| |
| b_triggered |
| |
|-----[ ]----------[/]-------------( )--------|
| b_triggered b c |
| |
|-----[ ]----------[/]-------------( )--------|
| b a_triggered reverse_detected |