- •9.7.2 More Timers And Counters
- •9.7.3 Deadman Switch
- •9.7.4 Conveyor
- •9.7.5 Accept/Reject Sorting
- •9.7.6 Shear Press
- •9.8 SUMMARY
- •9.9 PRACTICE PROBLEMS
- •9.10 PRACTICE PROBLEM SOLUTIONS
- •9.11 ASSIGNMENT PROBLEMS
- •10. STRUCTURED LOGIC DESIGN
- •10.1 INTRODUCTION
- •10.2 PROCESS SEQUENCE BITS
- •10.3 TIMING DIAGRAMS
- •10.4 DESIGN CASES
- •10.5 SUMMARY
- •10.6 PRACTICE PROBLEMS
- •10.7 PRACTICE PROBLEM SOLUTIONS
- •10.8 ASSIGNMENT PROBLEMS
- •11. FLOWCHART BASED DESIGN
- •11.1 INTRODUCTION
- •11.2 BLOCK LOGIC
- •11.3 SEQUENCE BITS
- •11.4 SUMMARY
- •11.5 PRACTICE PROBLEMS
- •11.6 PRACTICE PROBLEM SOLUTIONS
- •11.7 ASSIGNMENT PROBLEMS
- •12. STATE BASED DESIGN
- •12.1 INTRODUCTION
- •12.1.1 State Diagram Example
- •12.1.2 Conversion to Ladder Logic
- •12.1.2.1 - Block Logic Conversion
- •12.1.2.2 - State Equations
- •12.1.2.3 - State-Transition Equations
- •12.2 SUMMARY
- •12.3 PRACTICE PROBLEMS
- •12.4 PRACTICE PROBLEM SOLUTIONS
- •12.5 ASSIGNMENT PROBLEMS
- •13. NUMBERS AND DATA
- •13.1 INTRODUCTION
- •13.2 NUMERICAL VALUES
- •13.2.1 Binary
- •13.2.1.1 - Boolean Operations
- •13.2.1.2 - Binary Mathematics
- •13.2.2 Other Base Number Systems
- •13.2.3 BCD (Binary Coded Decimal)
- •13.3 DATA CHARACTERIZATION
- •13.3.1 ASCII (American Standard Code for Information Interchange)
- •13.3.2 Parity
- •13.3.3 Checksums
- •13.3.4 Gray Code
- •13.4 SUMMARY
- •13.5 PRACTICE PROBLEMS
- •13.6 PRACTICE PROBLEM SOLUTIONS
- •13.7 ASSIGNMENT PROBLEMS
- •14. PLC MEMORY
- •14.1 INTRODUCTION
- •14.2 MEMORY ADDRESSES
- •14.3 PROGRAM FILES
- •14.4 DATA FILES
- •14.4.1 User Bit Memory
- •14.4.2 Timer Counter Memory
- •14.4.3 PLC Status Bits (for PLC-5s and Micrologix)
- •14.4.4 User Function Control Memory
- •14.4.5 Integer Memory
- •14.4.6 Floating Point Memory
- •14.5 SUMMARY
- •14.6 PRACTICE PROBLEMS
- •14.7 PRACTICE PROBLEM SOLUTIONS
- •14.8 ASSIGNMENT PROBLEMS
- •15. LADDER LOGIC FUNCTIONS
- •15.1 INTRODUCTION
- •15.2 DATA HANDLING
- •15.2.1 Move Functions
- •15.2.2 Mathematical Functions
- •15.2.3 Conversions
- •15.2.4 Array Data Functions
- •15.2.4.1 - Statistics
- •15.2.4.2 - Block Operations
- •15.3 LOGICAL FUNCTIONS
- •15.3.1 Comparison of Values
- •15.3.2 Boolean Functions
- •15.4 DESIGN CASES
- •15.4.1 Simple Calculation
- •15.4.2 For-Next
- •15.4.3 Series Calculation
- •15.4.4 Flashing Lights
- •15.5 SUMMARY
- •15.6 PRACTICE PROBLEMS
- •15.7 PRACTICE PROBLEM SOLUTIONS
- •15.8 ASSIGNMENT PROBLEMS
plc states - 12.16
Figure 12.17 State Diagram for Prioritization Problem
STC
MCR
D
U STC
L STB
MCR
Figure 12.18 State Diagram for Prioritization Problem
The Block Logic technique described does not require any special knowledge and the programs can be written directly from the state diagram. The final programs can be easily modified, and finding problems is easier. But, these programs are much larger and less efficient.
12.1.2.2 - State Equations
State diagrams can be converted to Boolean equations and then to Ladder Logic. The first technique that will be described is state equations. These equations contain three main parts, as shown below in Figure 12.19. To describe them simply - a state will be on if it is already on, or if it has been turned on by a transition from another state, but it will be turned off if there was a transition to another state. An equation is required for each state in the state diagram.
plc states - 12.17
Informally,
State X = (State X + just arrived from another state) and has not left for another state
Formally, |
|
|
|
|
|
|
|
|
|
|
|
n |
|
|
m |
||||
|
|
|
|
|
|
|
|
|
|
STATEi = |
+ |
∑ ( Tj, i |
• STATEj) |
• |
∏ ( Ti, k • STATEi) |
||||
STATEi |
|
||||||||
|
|
|
j = 1 |
|
|
|
k = 1 |
where, STATEi = A variable that will reflect if state i is on n = the number of transitions to state i
m = the number of transitions out of state i
Tj, i = The logical condition of a transition from state j to i
Ti, k = The logical condition of a transition out of state i to k
Figure 12.19 State Equations
The state equation method can be applied to the traffic light example in Figure 12.8. The first step in the process is to define variable names (or PLC memory locations) to keep track of which states are on or off. Next, the state diagram is examined, one state at a time. The first equation if for ST1, or state 1 - green NS. The start of the equation can be read as ST1 will be on if it is on, or if ST4 is on, and it has been on for 4s, or if it is the first scan of the PLC. The end of the equation can be read as ST1 will be turned off if it is on, but S1 has been pushed and S2 is off. As discussed before, the first half of the equation will turn the state on, but the second half will turn it off. The first scan is also used to turn on ST1 when the PLC starts. It is put outside the terms to force ST1 on, even if the exit conditions are true.
plc states - 12.18
Defined state variables:
ST1 = state 1 - green NS
ST2 = state 2 - yellow NS
ST3 = state 3 - green EW
ST4 = state 4 - yellow EW
The state entrance and exit condition equations:
ST1 = ( ST1 + ST4 TON2( ST4, 4s) ) ST1 S1 S2 + FS
ST2 = ( ST2 + ST1 S1 S2) ST2 TON1( ST2, 4s)
ST3 = ( ST3 + ST2 TON1( ST2, 4s) ) ST3 S1 S2
ST4 = ( ST4 + ST3 S1 S2) ST4 TON2( ST4, 4s)
Note: Timers are represented in these equations in the form TONi(A, delay). TON indicates that it is an on-delay timer, A is the input to the timer, and delay is the timer delay value. The subscript i is used to differentiate timers.
Figure 12.20 State Equations for the Traffic Light Example
The equations in Figure 12.20 cannot be implemented in ladder logic because of the NOT over the last terms. The equations are simplified in Figure 12.21 so that all NOT operators are only over a single variable.
plc states - 12.19
Now, simplify these for implementation in ladder logic.
ST1 = ( ST1 + ST4 TON2( ST4, 4) ) ( ST1 + S1 + S2) + FS
ST2 = ( ST2 + ST1 S1 S2) ( ST2 + TON1( ST2, 4) )
ST3 = ( ST3 + ST2 TON1( ST2, 4) ) ( ST3 + S1 + S2)
ST4 = ( ST4 + ST3 S1 S2) ( ST4 + TON2( ST4, 4) )
Figure 12.21 Simplified Boolean Equations
These equations are then converted to the ladder logic shown in Figure 12.22 and Figure 12.23. At the top of the program the two timers are defined. (Note: it is tempting to combine the timers, but it is better to keep them separate.) Next, the Boolean state equations are implemented in ladder logic. After this we use the states to turn specific lights on.
plc states - 12.20
DEFINE THE TIMERS
ST4 timer on T4:2
delay 4 sec
ST2
THE STATE EQUATIONS |
|
|
ST1 |
|
ST1 |
ST4 |
T4:2/DN |
S1 |
|
|
|
|
|
S2 |
first scan |
|
|
timer on T4:1 delay 4 sec
ST1X
|
ST2 |
|
|
|
|
|
|
|
ST2 |
ST2X |
|||
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST1 |
|
S1 |
S2 |
|
|
T4:1/DN |
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST3 |
ST3 |
ST3X
|
ST2 |
T4:1/DN |
|
|
S1 |
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
S2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST4 |
|
|
|
|
|
|
|
|
|
|
ST4 |
ST4X |
||||
|
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST3 |
|
S1 |
S2 |
|
|
|
|
|
|
T4:2/DN |
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Figure 12.22 Ladder Logic for the State Equations
plc states - 12.21
|
OUTPUT LOGIC FOR THE LIGHTS |
|
|
|||
|
ST1 |
L1 |
||||
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST2 |
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST4 |
L2 |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST3 |
L3 |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST3 |
L4 |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST4 |
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST2 |
L5 |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST1 |
L6 |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Figure 12.23 Ladder Logic for the State Equations
This method will provide the most compact code of all techniques, but there are potential problems. Consider the example in Figure 12.23. If push button S1 has been pushed the line for ST1 should turn off, and the line for ST2 should turn on. But, the line for ST2 depends upon the value for ST1 that has just been turned off. This will cause a problem if the value of ST1 goes off immediately after the line of ladder logic has been scanned. In effect the PLC will get lost and none of the states will be on. This problem arises because the equations are normally calculated in parallel, and then all values are updated simultaneously. To overcome this problem the ladder logic could be modified to the form shown in Figure 12.24. Here some temporary variables are used to hold the new state values. After all the equations are solved the states are updated to their new values.
plc states - 12.22
THE STATE EQUATIONS |
|
|
||
ST1 |
|
|
ST1 |
ST1X |
|
|
|
|
|
ST4 |
T4:2/DN |
S1 |
|
|
|
|
|
|
|
|
|
|
S2 |
|
first scan |
|
|
|
|
ST2 |
|
|
ST2 |
ST2X |
|
|
|
||
ST1 |
S1 |
S2 |
T4:1/DN |
|
|
|
|
|
|
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
|
|
|
|
|
ST3X |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST4X |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Figure 12.24 Delayed State Updating
When multiple transitions out of a state exist we must take care to add priorities.
plc states - 12.23
Each of the alternate transitions out of a state should be give a priority, from highest to lowest. The state equations can then be written to suppress transitions of lower priority when one or more occur simultaneously. The state diagram in Figure 12.25 has two transitions A and C that could occur simultaneously. The equations have been written to give A a higher priority. When A occurs, it will block C in the equation for STC. These equations have been converted to ladder logic in Figure 12.26.
STA |
STC |
B |
D |
A |
C |
|
STB |
first scan
STA = ( STA + STB A) STA B
STB = ( STB + STA B + STC D) STB A STB C + FS
STC = ( STC + STB C A) STC D
Figure 12.25 State Equations with Prioritization