Midweek PLC Musings
In Support of Ladder Logic
Not that ladder logic needs my support specifically to keep it alive. It’s doing quite well actually against the seasoned adversaries of functionblock, structured-text, functionchart and the woebegone instructionlist languages. In spite of the so ill-informed plant electrical chief in Port Moody whom I was (unsuccessfully) trying to sell my services to in 1983, who’s words still ring in my ears: “PLC? PLCs are a passing fad, not buying into that!” Not four years later I replaced every one of the major machine group control systems with PLCs there. They lasted more than twenty years (much longer than his rain). Programmed in Ladder Logic.
And now and again, when a computer science trained guy joins one of my training courses, we hear it on Monday morning - and well into the afternoon: “Ladder Logic is so primitive! How can you guys stand it?”. But usually, by Wednesday afternoon, at the latest by Thursday we don’t hear anything but the odd “Wow, you can do this?!”.
There is a lot of well-hidden power and complexity built into the old ladder logic language! Just look at the simple --] [-- instruction. Yes, to many people, and even some sadly uninformed trainers, this is a relay contact. What it really is, is a perfectly formed object created in the 1970’s with machine language, yet adhering to today’s object orientation principles. First of all, it is an instruction. One that is made to look like a relay contact, and it believably exhibits the graphical behaviour of a relay contact. But it is an instruction. So what does it instruct? It instructs the CPU to: “Look at the incoming line condition (on the left), and if it is true go the address specified above the relay symbol and have a look to ‘Examine if it’s On’ - if that address location data is on (or true, or 1) then come back and mark your exit condition (to the right), and also show graphically that the condition is true”.
By this feat there can be two things derived from the simple XIC (yes that is what the --] [-- is really called, a mnemonic: Examine If Closed) instruction: First, if its quest is found to be true, the instruction can pass on the true state to the next instruction to the right, to let it do its job and so on to the very right when the output instruction is encountered. Second, if the quest was answered with false, this is a real valuable bit of information. Because now all the other instructions to the right can go into ‘fast-false’ mode. No sense going out to examine stuff, you know the outcome already, unless it is a branch - but let’s ignore that for a moment. The false mode can skip along all the instructions it encounters until the output instruction is encountered – and simply mark it false.
The output instruction? Its machine language task is: “Look at the incoming line condition (on the left), and if it is true go the address specified above the coil symbol and set it to true (1), if not set it to false.” That’s why it is called OTE, Output Energize.
The real genius behind ladder logic was the recognition that any rung, of any complexity, can be made into a single chain of instructions that is then simple to evaluate by the CPU from left (start) to right (the end of the rung)! This is accomplished with the branch instruction. Unlike the other instructions, the branch consists of two separate graphical components for each branch. The first one, the branch start, is really just a marker that says “this is where the branch begins, this is where to come back to when you encounter the branch end”. The second, the branch end instruction says “this is where the branch ends, and I’m remembering the condition from the first branch end evaluation”. So if the line condition going into the first branch was true, and the first branch was evaluated false – this evaluation is kept until the next branch is finished evaluating – and only marked false if both the branches are false. In this manner the branch structure is simply made into one long linear chain.
I hope my above explanation is good enough to help you understand why it is of benefit to put the key operating mode determining instructions as far to the left as possible to make your code as fast as possible.
Well, time to go back to work. Are you getting anything out of this? A chuckle? Should I continue next week with something special? Let me know.
Owner at Valley West Controls ltd
4 年Right on Hugo! Ladder Logic still rules. Although not all Ladder languages are created equally. Easiest is the one you use the most. :)