Good Programming Practice: Latches?

A lot of what I'm reading is kinda what I do a lot of, latching bits to signify "states" of the machine during the various processes...
 
I worked for a packaging machine company. The program used latch bits to sequence thru the complex program and was written by a mechanical engineer. We received many positive comments from the users about the readability of the program.
Isn't that what it's about?

Usually the best programmers for a given application are those who know the process. My company hires many chemical engineers for programming in the pharmaceutical and biotech industries.
 
I have no clue how to read the code you posted. Here's my example.

The first two rungs show bit N7:0/0 being set with a digital input and being held in with a seal branch. The second two rungs show that same bit being set with a digital input and held in by being a Latch coil. In both cases, input I:1.0/1 will unset the N7:0/0 coil.

Using the seal circuit method in the first two rungs, coil N7:0/0 will not be on after a power cycle. Using the Latch-Unlatch method in the second two rungs, it will. N7:0/0 is a retentive data type.

I also could have just used the I:1.0/1 in the seal circuit directly it makes no difference.

What kind of PLC is that? In a Siemens PLC, the manually latched bit would still stay latched, since the conditions to set it would still be true on power up if the bit is retentive.

By the way, I'm not sure what kind of latch this is demonstrating, but in your example they have two completely different functions. With the manual latch, the SET takes priority over the RESET (if both inputs are held high, N7:0/0 is true), but in the S/R example, the RESET takes priority (if both inputs are held high, N7:0/0 is false).

But if this is a Modicon where the scanning is different than most, maybe it's different.
 
The problem with latch instructions is that they introduce a lot more scan order dependency issues.
I avoid them at all costs, they make commissioning and troubleshooting a hundred times harder. Its is also an indication that most beginner PLC programmers use them constantly, whereas more experienced programmers avoid them.

Sometimes you cannot avoid them, but unless you cant find an alternative, I would not use them.



I had to chime in on this one.
"Scan Order Dependency".

Being confident on how your specific programmable controller scans, and updates Boolean bit status is the most powerful tool to use.

If the programmer does not understand what the controller is doing, it does NOT matter if they are using non-latching instructions or latching instructions.

Most equipment we work on has to track work in process where no sensors exist. It is frequent to latch a bit or set a value and move it along creating a “software” memory throughout the process.

I don’t have a problem with latches, and I do agree with others, when you hear an “older engineer” say “avoid latches”, that they are merely stating that they do not understand them. (PS I am an older engineer).

The PLC/PAC programming software that we use, has an “Instruction HELP” listing right on the top of the screen, and will break down the timing, the function, and the capability of EVERY instruction in the TOOL BOX.

We us latches, indirect addressing, masked moves, bit field distributors, PID, SRTP TPO, MAV moving average… etc…

Why limit yourself to XIC, XIO and OTE????
 
Very early in my in my training I had to troubleshoot a machine that was doing dangerous things after an E-Stop.

Found real outputs latched.
A subroutine to unlatch them.
A conditional return at the end of the subroutine.

With advise from members on this site (in the archives) I made the change below.
Did a safety check with managers and signed off.

I removed the conditions for the return so the latches
would be reset. Because the scan is not going to stop
and wait for conditions.
 
Pmf, but what the hell is a manual latch and a seal in latch? Are you guys talking about latching on an ote instruction? I guess i didnt realize people just used otl and otu to write a whole program. That does seem quaint and foolish. I appriciate the feedback.
 
Pmf, but what the hell is a manual latch and a seal in latch? Are you guys talking about latching on an ote instruction? I guess i didnt realize people just used otl and otu to write a whole program. That does seem quaint and foolish. I appriciate the feedback.

What is "Pmf"

See picture for a seal in latch ( or manual latch if you prefer)

Nothing quaint or foolish about "OTL" or "OTU" you just have to understand the differences and use them cautiously.

sealin.jpg
 
Thanks for the photo. That is exactly what i said, youre latching on an ote instruction. Im not going to argue that any instruction has meaning, and purpose. I was taught not to use them unless there was no other alternative.
 
A Seal on B3/1

----| |---+---|/|---( )--
x | y b3/1
|
----| |---+
b3/1


And a latch on B3/1

---| |---(L)--
x b3/1

---| |---(U)--
y b3/1


Need to remember through a power loss? Use a latch, otherwise seal it. (but never a real output, thank you)

Thankfully, I've only run into a few machines with the use of latches abused.
 
Need to remember through a power loss? Use a latch, otherwise seal it. (but never a real output, thank you)

But isn't that irrelevent? If 3.1 is used to set an output true, then the output is effectively latched.

It always comes down to knowing how to use the instruction set properly and writing code properly (I don't mean you jstolaruk; I know you know your stuff).
 
I get a little nervous when I see a latch on a real output because I believe (and this may not be true of all plc mfgs) that outputs could be turned on before the first scan of the plc program has a chance to set/clr to its intended state. That and along with multiple latch commands on the same bit can get hard to debug; at least with a seal its narrowed down to the last rung executed on that bit.
 
But isn't that irrelevent? If 3.1 is used to set an output true, then the output is effectively latched.

It's not the same thing. The difference is if the PLC loses power. If that happens, then the OTE will be set to 0, while the OTL will remain in its last state.

It always comes down to knowing how to use the instruction set properly and writing code properly.

I've used thousands of latches (it was part of the PLC spec for the code we wrote for Saturn), and never had problems with the software because of the use of latches.

I'm with Peter on this, fear of latches is just superstition.
 

Similar Topics

I'm looking for some starter kits but there aren't so many on the market, so I'm thinking about buying individual components for my needs. I just...
Replies
15
Views
2,535
Good Day Friends! I really want to advance in PLC Programming like our guys here in this forum, and I'm Pleading to all friends here to help by...
Replies
5
Views
2,778
hi al.. i am a bigginer to plc programming..ladder logic can anybody pls suggest the best programming practices using in industries..
Replies
21
Views
5,214
Morning folks--I have been programming in RS 5 and 500 for quite a few years. I need to get proficient in navigating in 5000 and I would like to...
Replies
3
Views
1,800
Hi, Following a large project our company recently finished, I would like to ask what is the best method for object oriented programming. We...
Replies
10
Views
12,473
Back
Top Bottom