QUOTE(Doug-P @ Nov 28 2006, 08:55 AM) [snapback]44594[/snapback]
Recently I had to troubleshoot a kluge of PLC-5/40 ladder logic consisting of latches, interlocks, summations, redundancies, and confusing documentation, not to mention the occasional far-flung rung.
The action is a straightforward SEQUENCE: a mechanism pushes a pallet onto a waiting cart and then retracts. After my latest go round with this mess I decided enough is enough and started seriously investigating SFCs (spare 5/40 on the bench with an 8x8 simulator module) with a view to retrofitting to make this thing intelligible. There are currently no SFCs used in any of the A-B processors in the building and I've never dealt with a live one so I'm in uncharted waters here.
I searched the WWW and found lots of articles on the subject. Not surprisingly, this led to more questions:
· One thing I couldn't pin down was: "At what level of complexity do SFCs come into their own?" That is, is a mere eight steps, with no branches, too trivial a task for an SFC? Does it even matter if the machine becomes more understandable and maintainable as a result of SFCs being included?
· Also, are there things an SFC should not be asked to do? My reading so far hints that they are intended to control machinery yet there are times when a process is sequential but is more oriented toward data manipulation.
· The only way I've found to get an SFC active is by adding its program number to the MCP list. There's a lot of information in the A-B help files but invoking SFCs is not mentioned. Is the MCP list the only way?
Any nuggets of SFC wisdom you'd care to pass along would be appreciated.
Thanks
Gee...that sounds familiar. I've got a discrete manufacturing plant, too.
I've looked at SFC's over time. I have 3 problems with the PLC-5 implementation. First, the editor is a pain in the rear. I have a lot of problems getting the diagram just the way I want it. Second, the electricians are utterly confused by them so we run into the old reason that we still use relay logic anyways...clarity.
Third, the question is whether you are trying to implement a state machine or if you have steps operating in parallel. In almost all of my processes, they are sequential. Or at worst, I end up with 2-5 interacting processes, each of which is a separate sequence.
The "traditional" way of doing this aside from some really ugly ladder code is using a sequencer instruction...SQI/SQO. From my experience, these are an even bigger bitch to debug. You essentially have a bunch of state bits toggling on and off almost as phantoms that you can't really trivially debug. Usually the guy before you burned the state diagram too so you have to map it out by hand.
Here is the way I actually do it currently. It is relatively clean and my electricians have no problems troubleshooting it. It is technically a bit "slower" because it uses integers instead of bits, but it is very clear to someone troubleshooting it.
Break your program down into a set of steps. Actually draw it out as a real state diagram. The way I do it is in Visio but you can do it anywhere. Draw one box for each "step" in your sequence. Inside the box, write down what that step is doing. Each box is a state. Draw arrows between the boxes showing how the program moves from one state to the next. On your arrow itself, write down the condition required to cause it to transition to the next state. Usually this is just a bit (limit switch set), a timer output (the timer goes INSIDE the box), or a condition check (tank level>95%). I usually write down both the text and the PLC addresses for reference, with a squiggle (~) representing "NOT" (such as normally closed contacts).
Now number your boxes. I don't care what numbers they use.
Now begin with picking an integer (N7:x) as your sequencer. The integer value equals the numbering you wrote on the boxes.
Your first rung should be something like if this is the first program scan after a power up, then reset the integer to a known safe state (the power up state).
Now start the first rung of your first state. Create a rung TITLE with "State x: Name". In the comment block, list everything inside the box and everything on the outgoing arcs. This basically moves your documentation inside the ladder diagram so that if you ever lose your state diagram, it is still clearly documented. Also, when you look at the "tree" on the left hand pane in RS-Logix 5, your entire state machine will show up there as individual items under the ladder. And you will get one page per state when you print the ladder to a printer.
Inside each rung, you will get code like:
if EQU N7:x y (the state), then do Y (the things inside the box)
...followed by:
if EQU N7:x y (the state) and <conditions> then MOV z N7:x
These correspond to each of the arrows you drew earlier.
When I do these, I also tend to isolate what I call "utility" or low level code from the state machine. I put all that stuff down below under separate rung titles with names like "Pump A", "Rotater B", etc., etc. This separates the state machine from the low level hardware logic.
Debugging gets really simple. You can just check the state variable to go straight to the appropriate piece of code, or the appropriate low level routine. Usually there are a half dozen extra transitions I didn't think of or some screwy error state that I didn't think of that has to be added. I just create another box and add it into what's already there. Adding additional states is relatively easy to do and preserves the "clean" nature of the system.
I've used this successfully on many projects and it has converted the spaghetti crap you described earlier into rock solid systems that are very predictable. At this point the electricians are used to checking 2 things whenever they troubleshoot PLC problems: What state was it in, and what was it doing or not doing? Since they only have to look at what is going on in a single state, the troubleshooting speed is usually dramatically improved.