This thread has been very entertaining and brings to light the fact that the subject of latch/unlatch vs. seal w/OTE is still a muddy area for a lot of programmers.
I have seen the instruction severely abused by OEM programmers. I had to debug a 3000 line PLC program that contained over 1000 latch/unlatch instructions. After a few hours, I scrapped the whole POS and started over with "normal" logic.
I am not against the use of SET and RESET. They can clean up confusing logic. The are great for fault logic, parts tracking, sequence control and a lot of other things.
I try to only have one SET and one RESET per bit. I try to keep them next to each other in the program, but not always. As an example: I have a global bit "PICKUP_POSITION_OCCUPIED" that interfaces two different sequences. The bit is latched by one sequence and unlatched by the next. That helps identify for the troubleshooter how the two sequences interact. If I put the event from one sequence in the ladder file for the other, just to keep the instructions side by side, it would foul up the organization of both modules.
I use Set/Reset for things I need to keep track of during power cycles. I want to know if a piece of cut stock is awaiting pickup. I want to know that my indexing conveyor extend limit switch failed and a fault occurred.
I will use RESET all by itself somteimes. It may confuse the next guy who wonders "what turns this bit on?", but it's sometimes the right thing to do. I RESET HMI pushbuttons that are supposed to be momentary. (I've seen RSView and PV550s fail to turn off momentary bits, and comms can fail at any moment). I'd rather confuse a troubleshooter than risk damage to people and machinery.
Originally Posted by darrenj
here is a perfect example of when NOT to use latch/unlatch!
A plant just put in a pallet strapper, There was a plblem with the straps so one of the guys flicked it over to manual and went in to fix (I know a little stupid..he should have pushed the EM stop) When he was in there he walked in front of an eye and the arm came out and hit him in the head..It moves slow so no big deal..I looked at the program and it was FULL of latched bits..So halfway thru the sequence even tho it was in man mode it was waiting for the eye to be blocked to move.. The programmer never Unlatched his bits when going from auto to hand..
I don't blame that occurence on the abuse of the SET/RESET instructions. There should have been an XIC Auto_Mode contact to prevent that motion from occuring, and yes, LOTO procedures were violated. But, the truth is, you MUST program the machine to behave in a predictable manner in every mode. No unexpected motion in manual mode is a simple one.
I see these instructions used more by people who learned to program with languages other than ladder logic. People who learned to "program" using relay logic with hand tools generally wire their ladders the same way. We expect to see very few latching relays in hardwiring compared to "sealed in" relays. I think we expect the same thing from our PLC code.
I first learned assembly, then several other "high-level" programming languages. Years later I learned relay wiring. Then I learned PLC ladder logic. I was shocked when I found out that the latest industrial machinery was being controlled by such seemingly crude techniques, but after using it for years, I understand why.
Programming styles will always vary as much as the people who use them. Just make sure you know exactly what happens when you cycle power, pull out a comm cable, etc. Make it part of your testing and you shouldn't go wrong.