- •16. ADVANCED LADDER LOGIC FUNCTIONS
- •16.1 INTRODUCTION
- •16.2 LIST FUNCTIONS
- •16.2.1 Shift Registers
- •16.2.2 Stacks
- •16.2.3 Sequencers
- •16.3 PROGRAM CONTROL
- •16.3.1 Branching and Looping
- •16.3.2 Fault Detection and Interrupts
- •16.4 INPUT AND OUTPUT FUNCTIONS
- •16.4.1 Immediate I/O Instructions
- •16.4.2 Block Transfer Functions
- •16.5 DESIGN TECHNIQUES
- •16.5.1 State Diagrams
- •16.6 DESIGN CASES
- •16.6.1 If-Then
- •16.6.2 Traffic Light
- •16.7 SUMMARY
- •16.8 PRACTICE PROBLEMS
- •16.9 PRACTICE PROBLEM SOLUTIONS
- •16.10 ASSIGNMENT PROBLEMS
- •17. OPEN CONTROLLERS
- •17.1 INTRODUCTION
- •17.3 OPEN ARCHITECTURE CONTROLLERS
- •17.4 SUMMARY
- •17.5 PRACTICE PROBLEMS
- •17.6 PRACTICE PROBLEM SOLUTIONS
- •17.7 ASSIGNMENT PROBLEMS
- •18. INSTRUCTION LIST PROGRAMMING
- •18.1 INTRODUCTION
- •18.2 THE IEC 61131 VERSION
- •18.3 THE ALLEN-BRADLEY VERSION
- •18.4 SUMMARY
- •18.5 PRACTICE PROBLEMS
- •18.6 PRACTICE PROBLEM SOLUTIONS
- •18.7 ASSIGNMENT PROBLEMS
- •19. STRUCTURED TEXT PROGRAMMING
- •19.1 INTRODUCTION
- •19.2 THE LANGUAGE
- •19.3 SUMMARY
- •19.4 PRACTICE PROBLEMS
- •19.5 PRACTICE PROBLEM SOLUTIONS
- •19.6 ASSIGNMENT PROBLEMS
- •20. SEQUENTIAL FUNCTION CHARTS
- •20.1 INTRODUCTION
- •20.2 A COMPARISON OF METHODS
- •20.3 SUMMARY
- •20.4 PRACTICE PROBLEMS
- •20.5 PRACTICE PROBLEM SOLUTIONS
- •20.6 ASSIGNMENT PROBLEMS
- •21. FUNCTION BLOCK PROGRAMMING
- •21.1 INTRODUCTION
- •21.2 CREATING FUNCTION BLOCKS
- •21.3 DESIGN CASE
- •21.4 SUMMARY
- •21.5 PRACTICE PROBLEMS
- •21.6 PRACTICE PROBLEM SOLUTIONS
- •21.7 ASSIGNMENT PROBLEMS
- •22. ANALOG INPUTS AND OUTPUTS
- •22.1 INTRODUCTION
- •22.2 ANALOG INPUTS
- •22.2.1 Analog Inputs With a PLC
- •22.3 ANALOG OUTPUTS
- •22.3.1 Analog Outputs With A PLC
- •22.3.2 Pulse Width Modulation (PWM) Outputs
- •22.3.3 Shielding
- •22.4 DESIGN CASES
- •22.4.1 Process Monitor
- •22.5 SUMMARY
- •22.6 PRACTICE PROBLEMS
- •22.7 PRACTICE PROBLEM SOLUTIONS
- •22.8 ASSIGNMENT PROBLEMS
- •23. CONTINUOUS SENSORS
- •23.1 INTRODUCTION
- •23.2 INDUSTRIAL SENSORS
- •23.2.1 Angular Displacement
- •23.2.1.1 - Potentiometers
- •23.2.2 Encoders
- •23.2.2.1 - Tachometers
- •23.2.3 Linear Position
- •23.2.3.1 - Potentiometers
- •23.2.3.2 - Linear Variable Differential Transformers (LVDT)
- •23.2.3.3 - Moire Fringes
- •23.2.3.4 - Accelerometers
- •23.2.4 Forces and Moments
- •23.2.4.1 - Strain Gages
- •23.2.4.2 - Piezoelectric
- •23.2.5 Liquids and Gases
- •23.2.5.1 - Pressure
- •23.2.5.2 - Venturi Valves
- •23.2.5.3 - Coriolis Flow Meter
- •23.2.5.4 - Magnetic Flow Meter
- •23.2.5.5 - Ultrasonic Flow Meter
- •23.2.5.6 - Vortex Flow Meter
- •23.2.5.7 - Positive Displacement Meters
- •23.2.5.8 - Pitot Tubes
- •23.2.6 Temperature
- •23.2.6.1 - Resistive Temperature Detectors (RTDs)
- •23.2.6.2 - Thermocouples
- •23.2.6.3 - Thermistors
- •23.2.6.4 - Other Sensors
- •23.2.7 Light
- •23.2.7.1 - Light Dependant Resistors (LDR)
- •23.2.8 Chemical
- •23.2.8.2 - Conductivity
- •23.2.9 Others
- •23.3 INPUT ISSUES
- •23.4 SENSOR GLOSSARY
- •23.5 SUMMARY
- •23.6 REFERENCES
- •23.7 PRACTICE PROBLEMS
- •23.8 PRACTICE PROBLEM SOLUTIONS
- •23.9 ASSIGNMENT PROBLEMS
- •24. CONTINUOUS ACTUATORS
- •24.1 INTRODUCTION
- •24.2 ELECTRIC MOTORS
- •24.2.1 Basic Brushed DC Motors
- •24.2.2 AC Motors
- •24.2.3 Brushless DC Motors
- •24.2.4 Stepper Motors
- •24.2.5 Wound Field Motors
plc advanced functions - 16.9
A
SQL
File #N7:20
Source I:001
Control R6:1
Length 9
Position 0
|
B |
SQI |
|
|
|
B3/10 |
|||
|
|
|
|
||||||
|
|
|
|
|
|
||||
|
|
|
File #N7:20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
Mask 0005 |
|
|
|
|
|
|
|
|
|
Source I:002 |
|
|
|
|
|
|
|
|
|
Control R6:2 |
|
|
|
|
|
|
|
|
|
Length 9 |
|
|
|
|
|
|
|
|
|
Position 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C |
|
|
|
|||||
|
ADD |
|
|||||||
|
|||||||||
|
|
|
|
|
|
SourceA R6:2.POS |
|
||
|
|
|
|
|
|
||||
|
|
|
|
|
|
SourceB 1 |
|
||
|
|
|
|
|
|
Dest R6:2.POS |
|
||
|
|
|
|
|
|
|
|||
|
|
|
|
GT |
|
MOV |
|
||
|
|
|
|
SourceA R6:2.POS |
|
Source 1 |
|
||
|
|
|
|
|
|
||||
|
|
|
|
SourceB 9 |
|
Dest R6:2.POS |
|
||
|
|
|
|
|
|
|
|
|
|
Figure 16.9 Sequencer Instruction Examples
These instructions are well suited to processes with a single flow of execution, such as traffic lights.
16.3 PROGRAM CONTROL
16.3.1 Branching and Looping
These functions allow parts of ladder logic programs to be included or excluded from each program scan. These functions are similar to functions in other programming languages such as C, C++, Java, Pascal, etc.
Entire sections of programs can be bypassed using the JMP instruction in Figure
plc advanced functions - 16.10
16.10. If A is true the program will jump over the next three lines to the line with the LBL 01. If A is false the JMP statement will be ignored, and the program scan will continue normally. If A is false X will have the same value as B, and Y can be turned on by C and off by D. If A is true then X and Y will keep their previous values, unlike the MCR statement. Any instructions that follow the LBL statement will not be affected by the JMP so Z will always be equal to E. If a jump statement is true the program will run faster.
A |
|
|
|||
|
JMP |
|
If A is true, the program |
||
|
|
||||
|
Label 01 |
|
will jump to LBL:01. |
||
|
|
|
|
If A is false the pro- |
|
B |
|
||||
X |
gram goes to the next |
||||
|
|
|
|||
|
|
|
line. |
||
|
|
|
|
||
|
|
|
|
C
L Y
D
U Y
E
Z
LBL 01
Figure 16.10 A JMP Instruction
Subroutines jump to other programs, as is shown in Figure 16.11. When A is true the JSR function will jump to the subroutine program in file 3. The JSR instruction two arguments are passed, N7:0 and 123. The subroutine (SBR) function receives these two arguments and puts them in N10:0 and N10:1. When B is true the subroutine will end and return to program file 2 where it was called. The RET function can also returns the value N10:1 to the calling program where it is put in location N7:1. By passing arguments (instead of having the subroutine use global memory locations) the subroutine can be used for more than one operation. For example, a subroutine could be given an angle in degrees and return a value in radians. A subroutine can be called more than once in a program, but if not called, it will be ignored.
plc advanced functions - 16.11
program file 2
program file 3
A |
JSR (Jump subroutine) |
|
Program File 3 |
||
|
||
|
Input par N7:0 |
|
|
||
|
Input par 123 |
|
|
Return par N7:1 |
|
|
|
A separate ladder logic program is stored in program file 3. This feature allows users to create their own functions. In this case if A is true, then the program below will be executed and then when done the ladder scan will continue after the subroutine instruction. The number of data values passed and returned is variable.
SBR (subroutine arguments)
Input par N10:0
Input par N10:1
If B is true the subroutine will return and the values listed will be returned to the return par. For this example the value that is in N10:1 will eventually end up in N7:1
B |
RET |
|
Return par N10:1 |
|
|
|
|
Figure 16.11 Subroutines
The for-next loop in Figure 16.12 will repeat a section of a ladder logic program 5 times (from 0 to 9 in steps of 2) when A is true. The loop starts at the FOR and ends at the NXT function. In this example there is an ADD function that will add 1 to the value of N7:1. So when this for-next statement is complete the value of N7:1 will 5 larger. Notice that the label number is the same in the FOR and NXT, this allows them to be matched. For-next loops can be put inside other for-next loops, this is called nesting. If A was false the program would skip to the NXT statement. All 5 loops will be completed in a single program scan, so a control word is not required. If B is true the NXT statement will no longer return the program scan to the FOR instruction, even if the loop is not complete. Care must be used for this instruction so that the ladder logic does not get caught in an infinite, or long loop - if this happens the PLC will experience a fault and halt.
plc advanced functions - 16.12
|
A |
FOR |
|
|
|
label number 0 |
|
|
|
||
|
|
index N7:0 |
|
|
|
initial value 0 |
|
|
|
terminal value 9 |
|
|
|
step size 2 |
|
|
|
|
|
|
|
|
|
|
|
ADD |
|
|
|
Source A 1 |
|
|
|
Source B N7:1 |
|
|
|
Dest N7:1 |
|
|
|
|
|
|
B |
|
|
BRK
NXT
label number 0
Note: if A is true then the loop will repeat 10 times, and the value of N7:1 will be increased by 10. If A is not true, then the ADD function will only be executed once and N7:1 will increase in value by 1.
Figure 16.12 A For-Next Loop
Ladder logic programs always have an end statement, as shown in Figure 16.13. Most modern software automatically inserts this. PLCs will experience faults if this is not present. The temporary end (TND) statement will skip the remaining portion of a program. If C is true then the program will end, and the next line with D and Y will be ignored. If C is false then the TND will have no effect and Y will be equal to D.
plc advanced functions - 16.13
A B X
C
TND
D
Y
END
When the end (or End Of File) is encountered the PLC will stop scanning the ladder, and start updating the outputs. This will not be true if it is a subroutine or a step in an SFC.
Figure 16.13 End Statements
The one shot contact in Figure 16.14 can be used to turn on a ladder run for a single scan. When A has a positive edge the oneshot will turn on the run for a single scan. Bit B3:0 is used here to track to rung status.
A B3:0
|
ONS |
|
B |
|
|
||
|
|
|
|
A
B
Figure 16.14 One Shot Instruction