TheLearningPit |
The process of converting control objectives into a ladder logic program requires structured thought. Boolean algebra provides the tools needed to analyze and design these systems.
Boolean algebra was developed in the 1800's by James Bool, an Irish mathematician. It was found to be extremely useful for designing digital circuits, and it is still heavily used by electrical engineers and computer scientists. The techniques can model a logical system with a single equation. The equation can then be simplified and/or manipulated into new forms. The same techniques developed for circuit designers adapt very well to ladder logic programming.
Boolean equations consist of variables and operations and look very similar to normal algebraic equations. The three basic operators are AND, OR and NOT; more complex operators include exclusive or (EOR), not and (NAND), not or (NOR). Small truth tables for these functions are shown in See Boolean Operations with Truth Tables and Gates. Each operator is shown in a simple equation with the variables A and B being used to calculate a value for X. Truth tables are a simple (but bulky) method for showing all of the possible combinations that will turn an output on or off.
Boolean Operations with Truth Tables and Gates
In a Boolean equation the operators will be put in a more complex form as shown in See A Boolean Equation. The variable for these equations can only have a value of 0 for false, or 1 for true. The solution of the equation follows rules similar to normal algebra. Parts of the equation inside parenthesis are to be solved first. Operations are to be done in the sequence NOT, AND, OR. In the example the NOT function for C is done first, but the NOT over the first set of parentheses must wait until a single value is available. When there is a choice the AND operations are done before the OR operations. For the given set of variable values the result of the calculation is false.
The equations can be manipulated using the basic axioms of Boolean shown in See The Basic Axioms of Boolean Algebra. A few of the axioms (associative, distributive, commutative) behave like normal algebra, but the other axioms have subtle differences that must not be ignored.
The Basic Axioms of Boolean Algebra
An example of equation manipulation is shown in See Simplification of a Boolean Equation. The distributive axiom is applied to get equation (1). The idempotent axiom is used to get equation (2). Equation (3) is obtained by using the distributive axiom to move C outside the parentheses, but the identity axiom is used to deal with the lone C. The identity axiom is then used to simplify the contents of the parentheses to get equation (4). Finally the Identity axiom is used to get the final, simplified equation. Notice that using Boolean algebra has shown that 3 of the variables are entirely unneeded.
Simplification of a Boolean Equation
Design ideas can be converted to Boolean equations directly, or with other techniques discussed later. The Boolean equation form can then be simplified or rearranges, and then converted into ladder logic, or a circuit.
If we can describe how a controller should work in words, we can often convert it directly to a Boolean equation, as shown in See Boolean Algebra Based Design of Ladder Logic. In the example a process description is given first. In actual applications this is obtained by talking to the designer of the mechanical part of the system. In many cases the system does not exist yet, making this a challenging task. The next step is to determine how the controller should work. In this case it is written out in a sentence first, and then converted to a Boolean expression. The Boolean expression may then be converted to a desired form. The first equation contains an EOR, which is not available in ladder logic, so the next line converts this to an equivalent expression (2) using ANDs, ORs and NOTs. The ladder logic developed is for the second equation. In the conversion the terms that are ANDed are in series. The terms that are ORed are in parallel branches, and terms that are NOTed use normally closed contacts. The last equation (3) is fully expanded and ladder logic for it is shown in See Alternate Ladder Logic. This illustrates the same logical control function can be achieved with different, yet equivalent, ladder logic.
Boolean Algebra Based Design of Ladder Logic
Boolean algebra is often used in the design of digital circuits. Consider the example in See Reverse Engineering of a Digital Circuit. In this case we are presented with a circuit that is built with inverters, nand, nor and, and gates. This figure can be converted into a boolean equation by starting at the left hand side and working right. Gates on the left hand side are solved first, so they are put inside parentheses to indicate priority. Inverters are represented by putting a NOT operator on a variable in the equation. This circuit can't be directly converted to ladder logic because there are no equivalents to NAND and NOR gates. After the circuit is converted to a Boolean equation it is simplified, and then converted back into a (much simpler) circuit diagram and ladder logic.
Reverse Engineering of a Digital Circuit
To summarize, we will obtain Boolean equations from a verbal description or existing circuit or ladder diagram. The equation can be manipulated using the axioms of Boolean algebra. after simplification the equation can be converted back into ladder logic or a circuit diagram. Ladder logic (and circuits) can behave the same even though they are in different forms. When simplifying Boolean equations that are to be implemented in ladder logic there are a few basic rules.
1. Eliminate NOTs that are for more than one variable. This normally includes replacing NAND and NOR functions with simpler ones using DeMorgan's theorem.
2. Eliminate complex functions such as EORs with their equivalent.
These principles are reinforced with another design that begins in See A Boolean Equation and Derived Circuit and Ladder Logic. Assume that the Boolean equation that describes the controller is already known. This equation can be converted into both a circuit diagram and ladder logic. The circuit diagram contains about two dollars worth of integrated circuits. If the design was mass produced the final cost for the entire controller would be under $50. The prototype of the controller would cost thousands of dollars. If implemented in ladder logic the cost for each controller would be approximately $500. Therefore a large number of circuit based controllers need to be produced before the break even occurs. This number is normally in the range of hundreds of units. There are some particular advantages of a PLC over digital circuits for the factory and some other applications.
· the PLC will be more rugged,
· the program can be changed easily
· less skill is needed to maintain the equipment
A Boolean Equation and Derived Circuit and Ladder Logic
The initial equation is not the simplest. It is possible to simplify the equation to the form seen in See A Boolean Equation and Derived Circuit and Ladder Logic. If you are a visual learner you may want to notice that some simplifications are obvious with ladder logic - consider the C on both branches of the ladder logic in See The Simplified Form of the Example.
The Simplified Form of the Example
The equation can also be manipulated to other forms that are more routine but less efficient as shown in See A Canonical Logic Form. The equation shown is in disjunctive normal form - in simpler words this is ANDed terms ORed together. This is also an example of a canonical form - in simpler terms this means a standard form. This form is more important for digital logic, but it can also make some PLC programming issues easier. For example, when an equation is simplified, it may not look like the original design intention, and therefore becomes harder to rework without starting from the beginning.
There are some common Boolean algebra techniques that are used when simplifying equations. Recognizing these forms are important to simplifying Boolean Algebra with ease. These are itemized, with proofs in See Common Boolean Algebra Techniques.
Common Boolean Algebra Techniques
Knowing a simple set of logic forms will support a designer when categorizing control problems. The following forms are provided to be used directly, or provide ideas when designing.
In total there are 16 different possible types of 2-input logic gates. The simplest are AND and OR, the other gates we will refer to as complex to differentiate. The three popular complex gates that have been discussed before are NAND, NOR and EOR. All of these can be reduced to simpler forms with only ANDs and ORs that are suitable for ladder logic, as shown in See Conversion of Complex Logic Functions.
Conversion of Complex Logic Functions
Multiplexers allow multiple devices to be connected to a single device. These are very popular for telephone systems. A telephone switch is used to determine which telephone will be connected to a limited number of lines to other telephone switches. This allows telephone calls to be made to somebody far away without a dedicated wire to the other telephone. In older telepho9ne switch board operators physically connected wires by plugging them in. In modern computerized telephone switches the same thing is done, but to digital voice signals.
In See A Multiplexer a multiplexer is shown that will take one of four inputs bits D1, D2, D3 or D4 and make it the output X, depending upon the values of the address bits, A1 and A2.
Ladder logic form the multiplexer can be seen in See A Multiplexer in Ladder Logic.
The following cases are presented to illustrate various combinatorial logic problems, and possible solutions. It is recommended that you try to satisfy the description before looking at the solution.
Problem: Develop a program that will cause output D to go true when switch A and switch B are closed or when switch C is closed.
Sample Solution for Logic Case Study A
Problem: Develop a program that will cause output D to be on when push button A is on, or either B or C are on.
Sample Solution for Logic Case Study B
Problem: Develop Ladder Logic for a car door/seat belt safety system. When the car door is open, or the seatbelt is not done up, the ignition power must not be applied. If all is safe then the key will start the engine.
Solution to Car Safety System Case
Problem: Design a motor controller that has a forward and a reverse button. The motor forward and reverse outputs will only be on when one of the buttons is pushed. When both buttons are pushed the motor will not work.
Motor Forward, Reverse Case Study
Consider the design of a burglar alarm for a house. When activated an alarm and lights will be activated to encourage the unwanted guest to leave. This alarm be activated if an unauthorized intruder is detected by window sensor and a motion detector. The window sensor is effectively a loop of wire that is a piece of thin metal foil that encircles the window. If the window is broken, the foil breaks breaking the conductor. This behaves like a normally closed switch. The motion sensor is designed so that when a person is detected the output will go on. As with any alarm an activate/deactivate switch is also needed. The basic operation of the alarm system, and the inputs and outputs of the controller are itemized in See Controller Requirements List for Alarm.
Controller Requirements List for Alarm
The next step is to define the controller equation. In this case the controller has 3 different inputs, and a single output, so a truth table is a reasonable approach to formalizing the system. A Boolean equation can then be written using the truth table in See Truth Table for the Alarm. Of the eight possible combinations of alarm inputs, only three lead to alarm conditions.
The Boolean equation in See A Boolean Equation and Implementation for the Alarm is written by examining the truth table in See Truth Table for the Alarm. There are three possible alarm conditions that can be represented by the conditions of all three inputs. For example take the last line in the truth table where when all three inputs are on the alarm should be one. This leads to the last term in the equation. The other two terms are developed the same way. After the equation has been written, it is simplified.
A Boolean Equation and Implementation for the Alarm
The equation and circuits shown in Figure can also be further simplified, as shown in See The Simplest Circuit and Ladder Diagram.
The Simplest Circuit and Ladder Diagram
Alarm Implementation Using A High Level Programming Language
· Logic can be represented with Boolean equations.
· Boolean equations can be converted to (and from) ladder logic or digital circuits.
· Boolean equations can be simplified.
· Different controllers can behave the same way.
· Common logic forms exist and can be used to understand logic.
· Truth tables can represent all of the possible state of a system.
1. Is the ladder logic in the figure below for an AND or an OR gate?
2. Draw a ladder diagram that will cause output D to go true when switch A and switch B are closed or when switch C is closed. The devices are wired to the following locations.
3. Draw a ladder diagram that will cause output D to be on when push button A is on, or either B or C are on.
4. Design ladder logic for a car that considers the variables below to control the motor M. Also add a second output that uses any outputs not used for motor control.
5. a) Explain why a stop button must be normally closed and a start button must be normally open.
(ans. If a NC stop button is damaged, the machine will act as if the stop button was pushed and shut down safely. If a NO start button is damaged the machine will not be able to start.)
b) Consider a case where an input to a PLC is a normally closed stop button. The contact used in the ladder logic is normally open, as shown below. Why are they both not the same?
(ans. For the actual estop which is NC, when all is ok the power to the input is on, when there is a problem the power to the input is off. In the ladder logic an input that is on (indicating all is ok) will allow the rung to turn on the motor, otherwise an input that is off (indicating a stop) will break the rung and cut the power.)
6. Consider a case where an input to a PLC is a normally closed stop button. The contact used in the ladder logic is normally open, as shown below. Why are they both not the same?
(ans. For the actual estop which is NC, when all is ok the power to the input is on, when there is a problem the power to the input is off. In the ladder logic an input that is on (indicating all is ok) will allow the rung to turn on the motor, otherwise an input that is off (indicating a stop) will break the rung and cut the power.)
7. Make a simple ladder logic program that will turn on the outputs with the binary patterns when the corresponding buttons are pushed.
8. Convert the following Boolean equation to the simplest possible ladder logic.
9. Simplify the following boolean equations.
10. Simplify the following Boolean equations,
11. Simplify the Boolean expression below.
12. Given the Boolean expression a) draw a digital circuit and b) a ladder diagram (do not simplify), c) simplify the expression.
13. Simplify the following Boolean equation and write corresponding ladder logic.
14. For the following Boolean equation,
a) Write out the logic for the unsimplified equation.
c) Write out the ladder logic for the simplified equation.
15. a) Given the following truth table, show the Boolean combinations that would give a result of 1.
b) Write the results in a) in a Boolean equation.
c) Simplify the Boolean equation in b)
16. Simplify the following Boolean equation, and create the simplest ladder logic.
17. Simplify the following boolean equation with Boolean algebra and write the corresponding ladder logic.
18. Convert the following ladder logic to a boolean equation. Simplify the equation using Boolean algebra, and then convert the simplified equation back to ladder logic.
19. Convert the following ladder logic to a Boolean equation. Then simplify it, and convert it back to simpler ladder logic.
20. Simplify the following boolean equation with Boolean algebra and write the corresponding ladder logic.
21. Use Boolean equations to develop simplified ladder logic for the following truth table where A, B, C and D are inputs, and X and Y are outputs.
22. a) Develop the Boolean expression for the circuit below.
b) Simplify the Boolean expression.
c) Draw a simpler circuit for the equation in b).
23. Given a system that is described with the following equation,
a) Simplify the equation using Boolean Algebra.
b) Implement the original and then the simplified equation with a digital circuit.
c) Implement the original and then the simplified equation in ladder logic.
24. Simplify the following and implement the original and simplified equations with gates and ladder logic.