Steve,
This code has been installed and running on an S7 for the past several months. It works EXACTLY as shown.
As I said, this code doesn't work on all PLC's.
Look at the rung as if it is a Function... where ALL paths are examined and executed. Left-to-Right and Top-to-Bottom.
Initial Conditions:
- PB is OFF
- Was (as in Was-PB) is OFF
- Flip is OFF
OK, so, assuming the Light is OFF and no PB activity...
SCAN X :
Starting at the top-left...
The PB is OFF. This means that any outputs on the rung will fall to their "default" conditions... if they have one.
Since WAS is the only output that has a "default" condition, WAS is turned OFF.
So, a few scans later, the PB is pushed...
SCAN X + 1000 :
Starting again at the top-left...
The PB contact is TRUE. This means that the entire rung will be examined and manipulated as required.
Since this is the first scan that the PB is ON, then the PB was OFF on the previous scan, therefore WAS is still OFF as a result of the last scan.
PB is TRUE and NOT-WAS is TRUE, therefore, FLIP is SET
Moving down to the next branch, FLIP is TRUE and NOT-LIGHT is TRUE (initial condition), therefore, SET the LIGHT Output and RESET FLIP.
The Light that was OFF is now ON.
Moving down to the next branch, FLIP was RESET in the previous branch, so it is FALSE. The LIGHT is TRUE. Since the outputs on this branch are the Set/Reset type, you need a path-of-TRUE's to perform the indicated action. Since the path-of Trues does not exist... no actions occur. These outputs do not "default" to a particular state - they have to be "driven" to act.
The last branch... PB is TRUE, so WAS is Turned ON.
End of Rung / End of Scan X + 1000
SCAN X + 1001 :
Current Conditions:
- PB is ON (it takes more than a scan or two for you to remove your finger from the button)
- Was is ON
- Flip is OFF
- Light is ON
PB is TRUE, so the entire rung will be examined.
PB is TRUE and NOT-WAS is FALSE, therefore FLIP is
not Set.
Next branch, FLIP is OFF so there will be no path-of-Trues and the outputs are the set/reset type and so there will be no action here.
Ditto for the next branch, FLIP is OFF so there will be no path-of-Trues and the outputs are the set/reset type and so there will be no action here.
The last branch... PB is TRUE, so WAS is Turned ON (it already is ON).
End of Rung / End of Scan-2
Several scans later, ya finally get yer big fat finger off of the button...
tick...
tock...
tick...
tock...
SCAN X + 2000 : (you seem to have a heavy finger)
Current Conditions:
- PB is OFF (finally!)
- Was is ON
- Flip is OFF
- Light is ON
The PB contact is FALSE. This means that any outputs on the rung will fall to their "default" conditions... if they have one.
Since WAS is the only output that has a "default" condition, WAS is turned OFF.
tick...
tock...
tick...
tock...
tick...
tock...
tick...
tock...
SCAN X + 10,000,000 : (Hey, Where ya been?)
Current Conditions:
- PB is ON
- Was is OFF
- Flip is OFF
- Light is ON
The PB contact is TRUE again. This means that the entire rung will be examined and manipulated as required.
Since this is the first scan
(after your long... lunch-break?) that the PB is ON, then the PB was OFF on the previous scan, therefore WAS is still OFF as a result of the last scan.
Starting again at the top-left...
PB is TRUE and NOT-WAS is TRUE, therefore, FLIP is SET
Moving down to the next branch, FLIP is TRUE and NOT-LIGHT is FALSE (it was turned On the last time you pressed the button), therefore, this branch does not have a Path-of-Trues and no actions occur on the set/reset type outputs.
Moving down to the next branch, FLIP is TRUE and LIGHT is TRUE, therefore, RESET LIGHT and RESET FLIP.
The Light that was ON is now OFF.
The last branch... PB is TRUE, so WAS is Turned ON.
End of Rung / End of Scan-10,000,000
tick...
tock...
SCAN X + 10,000,500 : (say... you're gettin' a little quicker!)
Current Conditions:
- PB is OFF
- Was is ON
- Flip is OFF
- Light is OFF
The PB contact is FALSE. This means that any outputs on the rung will fall to their "default" conditions... if they have one.
Since WAS is the only output that has a "default" condition, WAS is turned OFF.
End of Rung / End of Scan X + 10,000,500
Again, this doesn't work on all PLC's. As far as having an "edge-detector", that's what the WAS is all about.