
- •Table of Contents
- •Preface
- •Chapter 1 - Ladder Diagram Fundamentals
- •1-1. Objectives
- •1-2. Introduction
- •1-3. Basic Components and Their Symbols
- •1-4. Fundamentals of Ladder Diagrams
- •1-5. Machine Control Terminology
- •1-6. Summary
- •Chapter 2 - The Programmable Logic Controller
- •2-1. Objectives
- •2-2. Introduction
- •2-4. PLC Configurations
- •2-5. System Block Diagram
- •2-6. ... - Update - Solve the Ladder - Update - ...
- •2-7. Update
- •2-8. Solve the Ladder
- •2-9. Summary
- •Chapter 3 - Fundamental PLC Programming
- •3-1. Objectives
- •3-2. Introduction
- •3-3. Physical Components vs. Program Components
- •3-4. Example Problem 1
- •3-5. Disagreement Circuit
- •3-6. Majority Circuit
- •3-7. Oscillator
- •3-8. Holding (also called Sealed, or Latched) Contacts
- •3-9. Always-ON and Always-OFF Contacts
- •3-10. Ladder Diagrams Having More Than One Rung
- •Chapter 4 - Advanced Programming Techniques
- •4-1. Objectives
- •4-2. Introduction
- •4-3. Ladder Program Execution Sequence
- •4-5. RS Flip Flop
- •4-6. One Shot
- •4-8. T Flip Flop
- •4-9. J-K Flip Flop
- •4-10. Counters
- •4-11. Sequencers
- •4-12. Timers
- •Chapter 5 - Mnemonic Programming Code
- •5-1. Objectives
- •5-2. Introduction
- •5-3. AND Ladder Rung
- •5-4. Handling Normally Closed Contacts
- •5-5. OR Ladder Rung
- •5-6. Simple Branches
- •5-7. Complex Branches
- •Chapter 6 - Wiring Techniques
- •6-1. Objectives
- •6-2. Introduction
- •6-3. PLC Power Connection
- •6-4. Input Wiring
- •6-5. Inputs Having a Single Common
- •6-6. Output Wiring
- •6-7. Relay Outputs
- •6-8. Solid State Outputs
- •Chapter 7 - Analog I/O
- •7-1. Objectives
- •7-2. Introduction
- •7-3. Analog (A/D) Input
- •7-4. Analog (D/A) Output
- •7-5. Analog Data Handling
- •7-6. Analog I/O Potential Problems
- •Chapter 8 - Discrete Position Sensors
- •8-1. Objectives
- •8-2. Introduction
- •8-3. Sensor Output Classification
- •8-4. Connecting Discrete Sensors to PLC Inputs
- •8-5. Proximity Sensors
- •8-6. Optical Proximity Sensors
- •Chapter 9 - Encoders, Transducers, and Advanced Sensors
- •9-1. Objectives
- •9-2. Introduction
- •9-3. Temperature
- •9-4. Liquid Level
- •9-5. Force
- •9-6. Pressure/Vacuum
- •9-7. Flow
- •9-8. Inclination
- •9-9. Acceleration
- •9-10. Angle Position Sensors
- •9-11. Linear Displacement
- •Chapter 10 - Closed Loop and PID Control
- •10-1. Objectives
- •10-2. Introduction
- •10-3. Simple Closed Loop Systems
- •10-4. Problems with Simple Closed-Loop Systems
- •10-5. Closed Loop Systems Using Proportional, Integral, Derivative (PID)
- •10-6. Derivative Function
- •10-7. Integral Function
- •10-8. The PID in Programmable Logic Controllers
- •10-9. Tuning the PID
- •10-10. The “Adjust and Observe” Tuning Method
- •10-11. The Ziegler-Nichols Tuning Method
- •Chapter 11 - Motor Controls
- •11-1. Objectives
- •11-2. Introduction
- •11-3. AC Motor Starter
- •11-4. AC Motor Overload Protection
- •11-5. Specifying a Motor Starter
- •11-5. DC Motor Controller
- •11-6. Variable Speed (Variable Frequency) AC Motor Drive
- •11-7. Summary
- •Chapter 12 - System Integrity and Safety
- •12-1. Objectives
- •12-2. Introduction
- •12-3. System Integrity
- •12-4. Equipment Temperature Considerations
- •12-5. Fail Safe Wiring and Programming
- •12-6. Safety Interlocks

Chapter 4 - Advanced Programming Techniques
If we implement this expression using ladder contact logic, the ladder portion would be as shown in Figure 4-9. The input definitions already set are used in this figure.
Figure 4-9 - Contact Logic Required to
Implement T = KQ + J Q
If you refer back to Figure 4-8, you will see this contact configuration in the first rung of the ladder controlling the triggering of the one shot from IN3. The result is that the ladder diagram of Figure 4-8 will function as a J-K flip flop.
4-10. Counters
A counter is a special function included in the PLC program language that allows the PLC to increment or decrement a number each time the control logic for the rung switches from false to true. This special function generally has two control logic lines, one which causes the counter to count each time the control becomes true and one which causes the counter to reset when the control line is true. A typical counter is shown in Figure 4-10.
Figure 4-10 - Counter
4-15

Chapter 4 - Advanced Programming Techniques
Notice that this special function has two control lines one containing a normally open contact IN1 and one containing normally open contact IN2. The counter itself has a coil associated with it that is numbered CTR1. Notice too, that inside the function block are two labels, ACTUAL and PRESET. These ACTUAL and PRESET items contain numbers. The PRESET value is the maximum count allowed for the counter. This number may be held as a constant value in permanent memory or as a variable in a Holding Register. A holding register is a memory location in RAM which may be altered as required. The programmer would use a holding register for the PRESET value of the counter if the maximum count value needed to change depending upon program operation such as in a program that needed to count items to be placed in a box. If different size boxes were used depending upon the product and quantity to be shipped, the counter maximum may need to change. The ACTUAL value is maintained in a RAM location because it is the present value of the counter. As the counter counts, this value must change and it is this value compared to the PRESET value that the PLC uses to determine if the counter is at its maximum value. As the ACTUAL value increases with each count it is compared to the PRESET value. When the ACTUAL value is equal to the PRESET value, the counter will stop counting and the coil associated with the counter (in this case CTR1) will be energized.
In our example in Figure 4-10, contacts IN1 and IN2 control the counter. The top line, containing IN1, is referred to as the COUNT LINE. The lower control line, containing IN2 is referred to as the RESET LINE. Note that with some PLC manufacturers the two input lines are reversed that shown in Figure 4-10, with the RESET line on top and the
COUNT line below. In operation, if IN2 is closed the counter will be held in the reset condition, that is, the ACTUAL value will be set to zero no matter whether IN1 is open or closed. As long as the reset line is true, the ACTUAL value will be held at zero regardless of what happens to the count line. If the RESET LINE is opened, the counter will be allowed to increment the ACTUAL value each time the count control line switches from false to true (off to on). In our example that will be each time IN1 switches from open to closed. The counter will continue to increment the ACTUAL value each time IN1 switches from open to closed until the ACTUAL value is equal to the PRESET value. At that time the counter will stop incrementing the ACTUAL value and coil CTR1 will be energized. If at any time during the counting process the RESET control line containing IN2 is made to switch to true, the ACTUAL value will be reset to zero and the next count signal from IN1 will cause the ACTUAL value to increment to 1.
Different PLC manufacturers handle counters in different ways. Some counters operate as described above. Another approach taken in some cases is to reset the ACTUAL value to the PRESET value (rather than reset it to zero), and decrement the
ACTUAL value toward zero. In this case the coil associated with the counter is energized when the ACTUAL value is equal to zero rather than when it is equal to the PRESET value.
4-16

Chapter 4 - Advanced Programming Techniques
Some manufacturers have counters that are constructed using two separate rungs.
These have an advantage in that the reset rung can be located anywhere in the program and does not need to be located immediately following the count rung. Figure 4-11 shows a counter of this type. In this sample program, note that N/O IN1 in rung 1 causes the counter to increment (or decrement, if it is a down counter) and N/O IN2 in rung 2 causes the counter C1 to reset to zero (or reset to the preset value if it is a down counter). Rung
3 has been added to show how a counter of this type can be used. Contact C1 in rung 3 is a contact of counter C1. It is energized when counter C1 reaches its preset value (if it is a down counter, it will energize when C1 reaches a count of zero). The result is that output OUT1 will be energized when input IN1 switches on a number of times equal to the preset value of counter C1.
* IN1 C1 1)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(CTR)1
*
*
*
* IN2 C1 2)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[RSctr]1
*
*
*
* C1 OUT1 3)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(OUT)1
*
Figure 4-11 - Two-Rung Counter and Output Rung
In some cases it is convenient to have a counter that can count in either of the two directions, called a bidirectional counter. For example, in a situation where a PLC needs to maintain a running tally of the total number of parts in a que where parts are both entering and exiting the que, a bidirectional counter can be incremented when a part enters and decremented when a part exits the que. Figure 4-12 shows a bidirectional counter, C2, which has three inputs and consists of three rungs. Rung one controls the counting of C2 in the up direction, rung two controls C2 in the down direction, and rung three resets C2.
4-17
|
Chapter 4 - Advanced Programming Techniques |
|
* IN1 |
C2 |
|
1)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[Upctr]1
*
*
*
* IN2 C2 2)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[DNctr]1
*
*
*
* IN3 C2 3)))1 /)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))[RSctr]1
*
Figure 4-12 - UP/Down Counter
4-11. Sequencers
Some machine control applications require that a particular sequence of events occur, and with each step of the controller, a different operation be performed. The programming element to do this type of control is called a sequencer. For example, the timer in a washing machine is a mechanical sequencer in that it has the machine perform different operations (fill, wash, drain, spin) in a predetermined sequence. Although a washing machine timer is a timed sequencer, sequencers in a PLC are not necessarily timed. An example of a non-timed sequencer is a garage door opener. It performs the sequence ...up, stop, down, stop, up stop,... with each step in the sequence being activated by a switch input or remote control input.
PLC sequencers are fundamentally counters with some extra features and some minor differences. Counters will generally count to either their preset value (in the case of up counters) or zero (for down counters) and stop when they reach their terminal count. However, sequencers are circular counters; that is, they will “roll over” (much like an automobile odometer) and continue counting. If the sequencer is of the type that counts up from zero to the preset, on the next count pulse after reaching the preset, it will reset to zero and begin counting up again. If the sequencer is of the type that counts down, on the next count pulse after it reaches zero, it will load the preset value and continue counting down. Like counters, sequencers have reset inputs that reset them either to zero (for the types that count up) or to the preset value (for the types that count down). As with counters, some PLC manufacturers provide sequencers with a third input (usually called
UP/DN) that controls the count direction. These are called bidirectional sequencers or reversible sequencers. Alternately, other bidirectional sequencers have separate count up and count down inputs.
4-18