Software Standards Run Amok
A few years ago I wrote a program for a customer using a flowcharting language. It wasn’t just a flowcharting language; the product allows you to use both relay ladder logic and flowcharts. But the customer had a software standard that made the use of ladder logic forbidden!
Imagine a simplified example. Do you think Bill Gates’ kitchen has a blender? Probably. But it’s probably not like the one you or I have. Maybe it’s made out of solid gold and maybe it has a nuclear power source, but most of all I imagine it has a fully fledged industrial control system. Now, imagine we’re programming the control system for this blender.
Of course it would have the standard start and stop buttons, but this blender is top of the line and absolutely safe. It has a sensor to determine if the lid is closed. Obviously, if we’re happily blending away and the lid flies off, we need to stop the blender, and it shouldn’t start again until the lid is back on and the start button is pressed. After all, we wouldn’t want to endanger Bill’s fingers or anything (I happen to know he does a lot of blending).
Many of you have already written this complicated control system in your mind:
Good job! No matter what happens, the lid will have to be closed or the motor simply won’t run. Of course, the software specification says that you can’t use ladder logic.
Well, in flowcharting the start and stop logic is simple:
That’s pretty simple, but it doesn’t take the lid closed switch into account. At first glance, we might have to put the check for the lid closed before every decision block, so we check for the state of the lid switch, then check for the start or stop buttons. Do you see how this could get out of hand quickly?
Fortunately, the language offers a solution:
How’s that? While it’s true that if the lid ever comes off, the motor will stop, we have no way to exit gracefully. This “exception block”, as it’s called, stops whatever you were doing, turns off the motor and starts the whole process over again. I’m sure it would work fine for our simplified example here, but what if we were doing something else later on in the flowchart? What if we were tracking parts, or decelerating an unrelated axis? In the ladder logic example, the lid switch only disables the motor. In the flowchart it stops the logic and then disables the motor.
Of course, to deal with this problem in the complexities of a real machine, you end up writing two different flowcharts: one for the sequence and one for the outputs.
Now take a close look at the right hand flowchart. It scans through both decisions on every single scan of the controller. It’s “ladder logic written sideways”. It’s simple combinational logic that screams to be rewritten in ladder.
In fact, writing the state logic (like auto mode sequences) in flowchart and the combinational logic (like manual mode and faults) in ladder makes a lot of sense, especially for more complicated machines. So why forbid ladder logic? Perhaps it was just to force people to start using the flowcharts.
A software standard that bans ladder logic is a bad idea. Some logic is more readable as flowcharts, and some is more readable in ladder. For years we’ve had to write everything in ladder. We were like the little boy who only had a hammer and thought every problem was a nail. If that boy suddenly traded the hammer for a screwdriver, was he any better off?