11. Programmable Logic Controllers (PLCs)
• CONTROL - Using artificial means to manipulate the world with a particular goal.
• System types,
• Continuous - The values to be controlled change smoothly.
e.g. the speed of a car as the gas pedal is pushed
• Logical - The values to be controlled are easily described as on-off.
e.g. The car motor is on-off (like basic pneumatics).
Note: All systems are continuous but they can be treated as logical for simplicity.
• Logical control types,
• Conditional - A control decision is made by looking at current conditions only.
e.g. A car engine may turn on only when the key is in the ignition and the transmission is in park.
• Sequential - The controller must keep track of things that change and/or know the time and/or how long since something happened.
e.g. A car with a diesel engine must wait 30 seconds after the glow plug has been active before the engine may start.
Note: We can often turn a sequential problem into a conditional by adding more sensors.
mixed (continuous and logical) systems:
• A Programmable Logic Controller (PLC) is an input/output processing computer.
• Advantages of PLCs are:
- cost effective for complex systems
- flexible (easy to add new timers/counters, etc)
- computational abilities
- trouble shooting aids
- easy to add new components
• Ladder logic was originally introduced to mimic relay logic.
11.1 Ladder Logic
• The PLC can be programmed like other computers using specialized “languages.”
- Ladder Logic - a programming technique using a ladder-like structure. It was originally adopted because of its similarity to relay logic diagrams to ease its acceptance in manufacturing facilities. The ladder approach is somewhat limited by the lack of loops, etc. (although this is changing).
- Mnemonic - instructions and opcodes, similar to assembly language. It is more involved to program, but also more flexible than ladder logic. This will be used with the hand held programmers.
• There are other methods that are not as common,
- sequential function charts/petri nets
- state space diagrams
11.2 What Does Ladder Logic Do?
11.2.1 Connecting A PLC To A Process
• The PLC continuously scans the inputs and changes the outputs.
• The process can be anything - a large press, a car, a security door, a blast furnace, etc.
• As inputs change (e.g. a start button), the outputs will be changed. This will cause the process to change and new inputs to the PLC will be received.
11.2.2 PLC Operation
• Remember: The PLC is a computer. Computers have basic components, as shown below:
• In fact the computer above looks more like the one below:
• Notice that in this computer, outputs aren’t connected to the CPU directly.
• A PLC will scan a copy of all inputs into memory. After this, the ladder logic program is run once and it creates a temporary table of all outputs in memory. This table is then written to the outputs after the ladder logic program is done. This continues indefinitely while the PLC is running.
• PLC operation can be shown with a time-line -
SELF TEST - Checks to see if all cards error free, resets watch-dog timer, etc. (A watchdog timer will cause an error, and shut down the PLC if not reset within a short period of time - this would indicate that the ladder logic is not being scanned normally).
INPUT SCAN - Reads input values from the chips in the input cards and copies their values to memory. This makes the PLC operation faster and avoids cases where an input changes from the start to the end of the program (e.g., an emergency stop). There are special PLC functions that read the inputs directly and avoid the input tables.
LOGIC SOLVE/SCAN - Based on the input table in memory, the program is executed one step at a time, and outputs are updated. This is the focus of the later sections.
OUTPUT SCAN - The output table is copied from memory to the output chips. These chips then drive the output devices.
11.3 More Ladder Logic
• Ladder logic has been developed to mimic relay logic - to make the computer more acceptable to companies and employees.
• Original efforts resisted the use of computers because they required new skills and approaches, but the use of ladder logic allowed a much smaller paradigm shift.
• Original relay ladder logic diagrams show how to hook-up inputs to run outputs.
Relay - An input coil uses a voltage/current to create a magnetic field. As the coil becomes magnetic it pulls a metal switch (or reed) towards it and makes an electrical contact. The contact that closes when the coil is energized is normally open. There is a contact that the reed touches without the coil energized is called the normally closed contact. Relays are used to let one power source close a switch for another (often high current) power source while keeping them isolated.
Schematic - The drawing below shows the relay above in a symbolic form.
A Circuit - A mix of inputs and outputs allows logical selection of a device.
• We can then imaging this in context of a PLC. (this idea was suggested by Walt Siedelman of Ackerman Electric)
11.3.1 Relay Terminology
• Contactor - special relays for switching of large loads.
• Motor Starter - Basically a contactor in series with an overload relay to cut off when too much current is drawn.
• Rated Voltage - Suggested operation voltage. Lower levels can result in failure to operate: voltages above shorten life.
• Rated Current - The maximum current before contact damage occurs (welding or melting).
• DC relays require special arc suppression. AC relays have a zero crossing to reduce relay arc problems.
• AC relays require a shading pole to maintain contact. If a DC relay is used with AC power on the coil, it clicks on-and-off at the frequency of the AC (also known as chattering).
11.3.2 Ladder Logic Inputs
• Contact coils are used to connect the PLC power lines to drive the outputs.
• The inputs can come from electrical inputs or memory locations.
• Note: if we are using normally closed contacts in our ladder logic, this is independent of what the actual device is. The choice between normally open or closed is based on what is logically needed, and not the physical device.
• For the Micrologix PLCs the inputs are labelled ‘I:0.0/x’ where x is the input number 0 to 9.
11.3.3 Ladder Logic Outputs
• The outputs allow switches to close that supply or cut-off power to control devices.
• Ladder logic indicates what to do with the output, regardless of what is hooked up -- The programmer and electrician that connect the PLC are responsible for that.
• Outputs can go to electrical outputs, or to memory.
• Output symbols -
• We can relate these to actual outputs using numbers (look for these on the front of the PLC).
• For the Micrologix PLCs the outputs are labelled ‘O:0.0/x’ where x is the output number 0 to 5.
11.4 Ladder Diagrams
• These diagrams are read from left to right, top to bottom.
• For the ladder logic below the sequence of operations would be B1, B2 on the top first, then the bottom. This would be followed by T1, then F1.
• Power flow can be used to consider how ladder diagrams work. Power must be able to flow from the left to the right.
11.4.1 Ladder Logic Design
eg. Burglar Alarm
1. If alarm is on, check sensors.
2. If window/door sensor is broken (turns off), sound alarm and turn on lights.
3. If motion sensor goes on (detects thief), sound alarm and turn on lights.
A = Alarm and lights switch (1 = on)
W = Window/Door sensor (1 = OK)
M = Motion Sensor (0 = OK)
S = Alarm Active switch (1 = on)
11.4.2 A More Complicated Example of Design
• There are some devices and concepts that are temporal/sequential (time based) or sequential. This means that they keep track of events over time, as opposed to conditional logic that decides based on instantaneous conditions.
• Controls that have states or time dependence will require temporal controls (also known as sequential).
• Some devices that are temporal are:
Flip-Flops - These can be latched on or off.
Latches - Will stay on until reset (Similar to flip-flops)
Counters - Keeps a count of events
Timers - Allows inputs and outputs to be delayed or prolonged be a known amount
• We can show how these latches respond with a simple diagram.
• As an example consider the ladder logic:
• In most PLCs, latches will keep their last state even when the PLC is turned off and back on.
(Note: In some other PLCs latches are only used for keeping the state of the PLC when it was turned off, they don’t ‘stick’ on or off)
• We use timers to do some or all of the following:
- Delay turning on
- Delay turning off
- Accumulate time passed (retentive)
• When using timers (especially retentive) we must reset values when done. The (RES) instruction does this.
• Count up/count down counters will track input events.
• Count down counters are similar.
• Consider the example below,
11.9 Design and Safety
11.9.1 Flow Charts
• Good when the PLC only does one thing at a time in a predictable sequence.
• The real advantage is in modeling the process in an orderly manner.
• The case of an object should be tied to ground to give current a path to follow in the case of a fault that energizes the case. (Note: fuses or breakers will cut off the power, but the fault will be on for long enough to be fatal.)
• Step potential is another problem. Electron waves from a fault travel out in a radial direction through the ground. If a worker has two feet on the ground at different radial distances, there will be a potential difference between the feet that will cause a current to flow through the legs. If there is a fault, don’t run/walk away/towards.
• Always ground systems first before applying power. (The first time a system is activated it will have a higher chance of failure.)
• Safe current levels are listed below [ref hydro handbooks], but be aware that in certain circumstances very low currents can kill. When in doubt, take no chances.
• Fail-safe wiring should be used so that if wires are cut or connections fail, the equipment should turn off. For example, if a normally closed stop button is used and the connector is broken off, it will cause the machine to stop, as if the stop button has been pressed and broken the connection.
• Programs should be designed so that they check for problems and shut down in safe ways. Some PLC’s also have power interruption sensors; use these whenever danger is present.
• Proper programming techniques will help detect possible problems on paper instead of in operation.
11.10.3 PLC Safety Rules
• Use a fail-safe design.
• Make the program inaccessible to unauthorized persons.
• Use predictable, non-configurable programs.
• Use redundancy in hardware.
• Directly connect emergency stops to the PLC, or the main power supply.
• Check for system OK at start-up.
• Provide training for new users and engineers to reduce careless and uninformed mistakes.
• Use PLC built in functions for error and failure detection.
1. Look at the process and see if it is in a normal state. i.e. no jammed actuators, broken parts, etc. If there are visible problems, fix them and restart the process.
2. Look at the PLC to see which error lights are on. Each PLC vendor will provide documents that indicate which problems correspond to the error lights. Common error lights are given below. If any off the warning lights are on, look for electrical supply problems to the PLC.
HALT - something has stopped the CPU
RUN - the PLC thinks it is OK (and probably is)
ERROR - a physical problem has occurred with the PLC
3. Check indicator lights on I/O cards to see if they match the system. i.e., look at sensors that are on/off, and actuators on/off, check to see that the lights on the PLC I/O cards agree. If any of the light disagree with the physical reality, then interface electronics/mechanics need inspection.
4. Turn the PLC off and on again. If this fixes the problem it could be a programming mistake, or a grounding problem. Programming mistakes often happen the same way each time. Grounding problems are often random, and have no pattern.
5. Consult the manuals or use software if available. If no obvious problems exist, the problem is not simple and requires a technically skilled approach.
6. If all else fails call the vendor (or the contractor) for help.
11.11 Design Cases
11.11.1 Deadman Switch
A motor will be controlled by two switches. The Go switch will start the motor and the Stop switch will stop it. If the Stop switch was used to stop the motor, the Go switch must be thrown twice to start the motor. When the motor is active a light should be turned on. The Stop switch will be wired as normally closed.
A conveyor is run by switching on or off a motor. We are positioning parts on the conveyor with an optical detector. When the optical sensor goes on, we want to wait 1.5 seconds, and then stop the conveyor. After a delay of 2 seconds the conveyor will start again. We need to use a start and stop button - a light should be on when the system is active.
11.11.3 Accept/Reject Sorting
For the conveyor in the last case we will add a sorting system. Gages have been attached that indicate good or bad. If the part is good, it continues on. If the part is bad, we do not want to delay for 2 seconds, but instead actuate a pneumatic cylinder.
11.11.4 Shear Press
The basic requirements are,
1. A toggle start switch (TS1) and a limit switch on a safety gate (LS1) must both be on before a solenoid (SOL1) can be energized to extend a stamping cylinder to the top of a part.
2. While the stamping solenoid is energized, it must remain energized until a limit switch (LS2) is activated. This second limit switch indicates the end of a stroke. At this point the solenoid should be de-energized, thus retracting the cylinder.
3. When the cylinder is fully retracted a limit switch (LS3) is activated. The cycle may not begin again until this limit switch is active.
4. A cycle counter should also be included to allow counts of parts produced. When this value exceeds 5000 the machine should shut down and a light lit up.
5. A safety check should be included. If the cylinder solenoid has been on for more than 5 seconds, it suggests that the cylinder is jammed or the machine has a fault. If this is the case, the machine should be shut down and a maintenance light turned on.
• To use advanced data functions in a PLC, we must first understand the structure of the data in the PLC memory.
• There are two types of memory used in a PLC-5.
Program Files - these are a collection of 1000 slots to store up to 1000 programs. The main program will be stored in program file 2. SFC programs must be in file 1, and file 0 is used for program and password information. All other program files from 3 to 999 can be used for ‘subroutines’.
Data Files - This is where the variable data is stored that the PLC programs operate on. This is quite complicated, so a detailed explanation follows.
11.12.1 Data Files
• In brief PLC memory works like the memories in a pocket calculator. The values below are for a PLC-5, although most Allen-Bradley PLCs have a similar structure.
• These memory locations are typically word oriented (16 bits, or 2 bytes). This includes the bit memory. But the T4, C5, R6 data files are all three words long.
• All values are stored and used as integers (except when specified, eg. floating point). When integers are stored in binary format 2’s complements are used to allow negative numbers. BCD values are also used.
• There are a number of ways the PLC memory can be addressed,
bit - individual bits in memory can be accessed - this is like addressing a single output as a data bit
word/integer - 16 bits can be manipulated as a group
data value - an actual data value can be provided
file level - an array of data values can be manipulated and operated on as a group
indirect - another memory location can be used in the description of a location.
expression - a text string that describes a complex operation
• For the user assigned data files from 9 to 999 different data types can be assigned. These can be one of the data types already discussed, or another data type.
A - ASCII
B - bit
BT - block transfer
C - counter
D - BCD
F - floating point
MG - message
N - integer (signed, unsigned, 2s compliment, BCD)
PD - PID controller
R - control
SC - SFC status
ST - ASCII string
T - timer
220.127.116.11 - Inputs and Outputs
• Recall that the inputs and outputs use octal for specific bits. This means that the sequence of output bits is 00, 01, 02, 03, 04, 05, 06, 07, 10, 11, 12, 13, 14, 15, 16, 17
18.104.22.168 - User Numerical Memory
• Bit data file B3 is well suited to use of single bits. the data is stored as words and this allows two different ways to access the same bit.
B3:0/0 = B3/0
B3:0/10 = B3/10
B3:1/0 = B3/16
B3:1/5 = B3/21
B3:2/0 = B3/32
• The integer file N7 stores words in 2’s complement form. This allows values from -32768 to 32767. These values can be addressed as whole words, and individual bits can also be changed.
• The floating point file F8 will store floating point numbers that can only be used by floating point functions. The structure of these numbers does not allow bit access.
22.214.171.124 - Timer Counter Memory
• Timer T4 values are addressed using the number of the timers, and an associated data type. For example the accumulator value of timer 3 is T4:3.ACC or T4:3/ACC.
EN - timer enabled bit
TT - timer timing bit
DN - timer done bit
PRE - preset word
ACC - accumulated time word
• Counter C5 values are addressed using the number of the counters, and an associated data type. For example the accumulator value of counter 3 is C5:3.ACC or C5:3/ACC.
CU - count up bit
CD - count down bit
DN - counter done bit
OV - overflow bit
UN - underflow bit
PRE - preset word
ACC - accumulated count word
126.96.36.199 - PLC Status Bits (for PLC-5s)
• Some of the more commonly useful status bits in data file S2 are given below. Full listings are given in the manuals.
S2:0/0 carry in math operation
S2:0/1 overflow in math operation
S2:0/2 zero in math operation
S2:0/3 sign in math operation
S2:1/14 first scan of program file
S2:8 the scan time (ms)
S2:28 watchdog setpoint
S2:29 fault routine file umber
S2:30 STI (selectable timed interrupt) setpoint
S2:31 STI file number
S2:46-S2:54,S2:55-S2:56 PII (Programmable Input Interrupt) settings
S2:55 STI last scan time (ms)
S2:77 communication scan time (ms)
188.8.131.52 - User Function Memory
• Control file R6 is used by various functions to track progress. Values that are available are, listed below. The use of these bits is specific to the function using the control location.
EN - enable bit
EU - enable unload
DN - done bit
EM - empty bit
ER - error bit
UL - unload bit
IN - inhibit bit
FD - found bit
LEN - length word
POS - position word
11.13 Instruction Types
• There are basic categories of instructions,
Basic (discussed before)
- relay instructions
- timer instructions
- counter instructions
- immediate inputs/outputs
- fault/interrupt detection
Basic Data Handling
- computation instructions
- boolean instructions
Advanced Data Handling
- file instructions
- shift registers/stacks
- high speed counters
- ASCII string functions
• The reader should be aware that some functions are positive edge triggered (i.e. they only work the scan is active). while most are active any time the input is active. Some examples of edge triggered and non-edge triggered functions are listed below,
TON, TRO, TOF, ADD, MUL, etc.
11.13.1 Program Control Structures
• These change the flow of execution of the ladder logic.
11.13.2 Branching and Looping
• These functions allow control found in languages like Fortran
IF-THEN is like MCR (Master Control Reset)
GOTO is like JMP (Jump)
SUBROUTINES is like Program Files
• MCR blocks have been used earlier, but they are worth mentioning again.
• Block of ladder logic can be bypassed using a jump statment.
• Subroutines allow reusable programs to be written and called as needed. They are different from jump statements because they are not part of the main program (they are other program files), and arguments can be passed and returned.
• For next loops can also be done to repeat blocks of ladder logic inside a single scan. 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.
• Ladder logic programs always have an end statement, but it is often taken for granted and ignored. Most modern software automatically inserts this. Some PLCs will experience faults if this is not present.
• There is also a temporary end (TND) that for a single ladder scan will skip the remaining portion of a program.
• A one shot contact can be used to turn on a ladder run for a single scan. When the run has a positive rising edge the oneshot will turn on the run for a single scan. Bit ‘B3:0’ is used here to track to rung status.
184.108.40.206 - Immediate I/O Instructions
• This approach avoids problems caused by logic setting and resetting outputs before done.
• If we have a problem we may want to update an output immediately, and not wait for the PLC to complete its scan of the ladder logic. To do this we use immediate inputs and outputs.
220.127.116.11 - Fault Detection and Interrupts
• The PLC can be set up to run programs automatically. This is normally done for a few reasons,
- to deal with errors that occur (eg. divide by zero)
- to run a program at a regular timed interval (eg. SPC calculations)
- to respond when a long instruction is complete (eg. analog input)
- when a certain input changed (eg. panic button)
• Two types of errors will occur - terminal (critical) and warnings (non-critical). A critical failure will normally stop the PLC.
• In some applications faults and failures must be dealt with in logic if possible, if not the system must be shut down.
• There are some memory locations that store indications of warning and fatal errors that have occurred. The routine in program file [S:29] needs to be able to detect and clear the fault.
S:29 - program file number to run when a fault occurs
• To set a timed interrupt we will set values in the status memory as indicated below. The program in file [S:31] will be run every [S:30]ms.
S:30 - timed delay between program execution - an integer number of ms
S:31 - the program number to be run
• To cause an interrupt when a bit changes the following bits can be set.
S:46 - the program file to run when the input bit changes
S:47 - the rack and group number (eg. if in the main rack it is 000)
S:48 - mask for the input address (eg. 0000000000000100 watches 02)
S:49 - for positive edge triggered =1 for negative edge triggered = 0
S:50 - the number of counts before the interrupt occurs 1 = always up to 32767
11.13.3 Basic Data Handling
• Some handy functions found in PLC-5’s (similar functions are available in other PLC’s)
18.104.22.168 - Move Functions
• There are two types of move functions,
MOV(value,destination) - moves a value to a memory location
MVM(value,mask,destination) - moves a value to a memory location, but with a mask to select specific bits.
• The following function moves data values between memory locations. The following example moves a floating point number from floating point memory 7 to 23
• The following example moves a floating point number from floating point memory F8:7 to integer memory N7:23
• The following example puts an integer value 123 in integer memory N7:23
• A more complex example of the move functions follows,
11.14 Math Functions
• These functions use values in memory, and store the results back in memory (Note: these functions do not use variables like normal programming languages.)
• Math functions are quite similar. The following example adds the integer and floating point number and puts the results in ‘F8:36’.
• Basic PLC-5 math functions include,
ADD(value,value,destination) - add two values
SUB(value,value,destination) - subtract
MUL(value,value,destination) - multiply
DIV(value,value,destination) - divide
NEG(value,destination) - reverse sign from positive/negative
CLR(value) - clear the memory location
• Consider the example below,
• As an exercise, try the calculation below with ladder logic,
• Some intermediate math functions include,
CPT(destination,expression) - does a calculation
ACS(value,destination) - inverse cosine
COS(value,destination) - cosine
ASN(value,destination) - inverse sine
SIN(value,destination) - sine
ATN(value,destination) - inverse tangent
TAN(value,destination) - tangent
XPY(value,value,destination) - X to the power of Y
LN(value,destination) - natural log
LOG(value,destination) - base 10 log
SQR(value,destination) - square root
• Examples of some of these functions are given below.
• For practice implement the following function,
• Some functions are well suited to statistics.
AVE(start value,destination,control,length) - average of values
STD(start value,destination,control,length) - standard deviation of values
SRT(start value,control,length) - sort a list of values
• Examples of these functions are given below.
• There are also functions for basic data conversion.
TOD(value,destination) - convert from BCD to binary
FRD(value,destination) - convert from binary to BCD
DEG(value,destination) - convert from radians to degrees
RAD(value,destination) - convert from degrees to radians
• Examples of these functions are given below.
11.15 Logical Functions
11.15.1 Comparison of Values
• These functions act like input contacts. The equivalent to these functions are if-then statements in traditional programming languages.
• Basic comparison functions in a PLC-5 include,
CMP(expression) - compares two values for equality
EQU(value,value) - equal
NEQ(value,value) - not equal
LES(value,value) - less than
LEQ(value,value) - less than or equal
GRT(value,value) - greater than
GEQ(value,value) - greater than or equal
• The comparison function below compares values at locations A and B. If they are not equal, the output is true. The use of the other comparison functions is identical.
• More advanced comparison functions in a PLC-5 include,
MEQ(value,mask,threshold) - compare for equality using a mask
LIM(low limit,value,high limit) - check for a value between limits
• Examples of these functions are shown below.
11.16 Binary Functions
• These functions allow Boolean operations on numbers and values in the PLC memory.
• Binary functions are also available for,
AND(value,value,destination) - Binary and function
OR(value,value,destination) - Binary or function
NOT(value,value,destination) - Binary not function
XOR(value,value,destination) - Binary exclusive or function
• Examples of the functions are,
11.17 Advanced Data Handling
11.17.1 Multiple Data Value Functions
• We can also deal with large ‘chunks’ of memory at once. These will not be covered, but are available in texts. Some functions include,
- move/copy memory blocks
- add/subtract/multiply/divide/and/or/eor/not/etc blocks of memory
• These functions are similar to single value functions, but they also include some matrix operations. For a PLC-5 a matrix, or block of memory is also known as an array.
• The basic functions are,
FAL(control,length,mode,destination,expression) - will perform basic math operations to multiple values.
FSC(control,length,mode,expression) - will do a comparison to multiple values
COP(start value,destination,length) - copies a block of values
FLL(value,destination,length) - copies a single value to a block of memory
• These functions are done on a PLC-5 using file commands. Typical operations include
file to file - copy an array of memory from one location to another.
element to file - one value is copied to a block of memory
file to element - can convert between data types
file add - add arrays
file subtract - subtract arrays
file multiply - multiply arrays
file divide - divide an array by a value
convert to/from BCD
AND/OR/XOR/NOT - perform binary functions.
• Examples of these functions are shown below.
• a useful function not implemented on PLC-5 processors is a memory exchange.
11.17.2 Block Transfer Functions
• Certain PLC cards only have a single address (eg. O:001 or I:001) but multiple data values need to be read or written to it. To do this the block transfer functions are used.
• These will be used in the labs for analog input/output cards.
• These functions will take more than a single scan, and so once activated they will require a delay until they finish.
• To use the write functions we set up a block of memory, the function shows this starting at N9:0, and it is 10 words long (this is determined by the special purpose card). The block transfer function also needs a control block of memory, this is BT10:1
• To read values we use a similar method. In the example below 9 values will be read from the card and be placed in memory locations from N9:4 to N9:11.
11.18 Complex Functions
11.18.1 Shift Registers
• The values can be shifted left or right with the following functions.
BSL - shifts left from the LSB to the MSB. The LSB must be supplied
BSR - similar to the BSL, except the bit is input to the MSB and shifted to the LSB
• These use bit memory blocks of variable length.
• An example of a shift register is given below. In this case it is taking the value of bit B3:1/0 and putting it in the control word bit R6:2/UL. It then shifts the bits once to the right, B3:1/0 = B3:1/1 then B3:1/1 = B3:1/2 then B3:1/2 = B3:1/3 then B3:1/3 = B3:1/4. Then the input bit is put into the most significant bit B3:1/4 = I:000/00.
• There are other types of shift registers not implemented in PLC-5s.
• We can also use stack type commands. These allow values to be stored in a ‘pile’. This allows us to write programs that will accumulate values that can be used later, or in sequence.
• The basic concept of a FIFO stack is that the first element in is the first element out.
• The PLC-5 commands are FFL to load the stack, and FFU to unload it.
• The example below shows two instructions to load and unload the stack. The first time FFL is activated it will grab all of the bits from the input card I:001 and store them on the stack, at N7:0. The next value would be at N7:1, and so on until the stack length is met. When FFU is used the value at N7:0 will be moved to set all of the bits on the output card O:003 and the values on the stack will be shifted up so that the value previously in N7:1 is now in N7:0, etc. (note: the source and destination do not need to be inputs and outputs)
• A Last-In-First-Out stack can also be used with the LFL/LFU functions.
• Basically, sequencers are a method for using predetermined patterns to drive a process
• These were originally based on motor driven rotating cams that made and broke switches. When a number of these cams were put together, they would be equivalent to a binary number, and could control multiple system variables.
• A sequencer can keep a set of values in memory and move these to memory locations (such as an output card) when directed.
• These are well suited to state diagrams/processes with a single flow of execution (like traffic lights)
• The commands are,
SQO(start,mask,source,destination,control,length) - sequencer output from table to memory address
SQI(start,mask,source,control,length) - sequencer input from memory address to table
SQL(start,source,control,length) - sequencer load to set up the sequencer parameters
• An example of a sequencer is given below for traffic light control. The light patterns are stored in memory (entered manually by the programmer). These are then moved out to the output card as the function is activated. The mask (003F = 0000000000111111) is used so that only the 6 LSB are changed.
11.19 ASCII Functions
• ASCII functions can be used to interpret and manipulate strings in PLCs.
• These functions include,
ABL(channel, control, )- reports the number of ASCII characters including line endings
ACB(channel, control, ) - reports the numbers of ASCII characters in buffer
ACI(string, dest) - convert ASCII string to integer
ACN(string, string,dest) - concatenate strings
AEX(string, start, length, dest) - this will cut a segment of a string out of a larger string
AIC(integer, string) - convert an integer to a string
AHL(channel, mask, mask, control) - does data handshaking
ARD(channel, dest, control, length) - will get characters from the ASCII buffer
ARL(channel, dest, control, length) - will get characters from an ASCII buffer
ASC(string, start, string, result) - this will look for one string inside another
AWT(channel, string, control, length) - will write characters to an ASCII output
• An example of this function is given below,
• Try the problem below,
11.20 Design Techniques
11.20.1 State Diagrams
• We can implement state diagrams seen in earlier sections using many of the advanced function discussed in this section.
• Most PLCs allow multiple programs that may be used as subroutines. We could implement a block logic method using subroutine programs.
• Consider the state diagram below and implement it in ladder logic. You should anticipate what will happen if both A and C are pushed at the same time.
11.21 Design Cases
• If-then can be implemented different ways, as a simple jump, or as a subroutine call.
• For-next can be implemented as shown below, but recall that PLC programs do not execute one line at a time.
• A For/Next function is also available in the PLC.
• A do-while can be done as a simple variation of this.
• Consider a conveyor where parts enter on one end. they will be checked to be in a left or right orientation with a vision system. If neither left nor right is found, he part will be placed in a reject bin. The conveyor layout is shown below.
11.23 PLC Wiring
• Many configurations and packages are available. But essential components are:
power supply - Provides voltage/current to drive the electronics (often 5V, +/- 12V, +/- 24V)
CPU - Where ladder logic is stored and processed; the main control is executed here.
I/O (Input/Output) - A number of input/output terminals to connect to the actual system
Indicator lights - Indicate mode/power and status. These are essential when diagnosing problems.
• Common Configurations:
Rack/Chassis - A rack or number of racks are used to put PLC cards into. These are easy to change, and expand.
Shoebox - A compact, all-in-one unit (about the size of a shoebox) that has limited expansion capabilities. Lower cost and compactness make these ideal for small applications.
• Criteria for evaluation:
Rack, shoebox or micro
# of inputs/outputs (digital)
Memory - often 1K and up. Need is dictated by size of ladder logic program. A ladder element will take only a few bytes and will be specified in manufacturers documentation.
# of I/O modules - When doing some exotic applications, a large number of special add-on cards may be required.
Scan Time - The time to execute ladder logic elements. Big programs or faster processes will require shorter scan times. The shorter the scan time, the higher the cost. Typical values for this are 1 microsecond per simple ladder instruction.
Communications - Serial and networked connections allow the PLC to be programmed and talk to other PLCs. The needs are determined by the application.
11.23.1 Switched Inputs and Outputs
A PLC is just a computer. We must get information in so that it may make decisions and have outputs so that it can make things happen.
Switches - Contact, deadman, etc. all allow a voltage to be applied or removed from an input.
Relays - Used to isolate high voltages from the PLC inputs, these act as switches.
Encoder - Can keep track of positions.
22.214.171.124 - Input Modules
• Input modules typically accept various inputs depending upon specified values.
• Typical input voltages are:
• DC voltages are usually lower and, therefore, safer (i.e., 12-24V)
• DC inputs are very fast. AC inputs require a longer time (e.g., a 60Hz wave would require 1/60sec for reasonable recognition).
• DC voltages are flexible being able to connect to greater varieties of electrical systems.
• DC input cards typically have more inputs.
• AC signals are more immune to noise than DC, so they are suited to long distances and noisy (magnetic) environments.
• AC signals are very common in many existing automation devices.
126.96.36.199 - Actuators
• Inductive loads - Inductance is caused by a coil building up a magnetic field. When a voltage is removed from the coil, the field starts to collapse. As it does this, the magnetic field is changed back to current/voltage. If this change is too sudden, a large voltage spike is created. One way to overcome this is by adding a surge suppressor. One type of design was suggested by Steel McCreery of Omron Canada Ltd.
188.8.131.52 - Output Modules
• Typical Outputs
Motors - Motors often have their own controllers, or relays because of the high current they require.
Lights - Lights can often be powered directly from PLC output boards,
• WARNING - ALWAYS CHECK RATED VOLTAGES AND CURRENTS FOR PLC’s AND NEVER EXCEED!
• Typical outputs operate in one of two ways:
Dry contacts - A separate relay is dedicated to each output. This allows mixed voltages (AC or DC and voltage levels up to the maximum) as well as isolated outputs to protect other outputs and the PLC. Response times are often greater than 10ms. This method is the least sensitive to voltage variations and spikes.
Switched outputs - A voltage is supplied to the PLC card and the card switches it to different outputs using solid state circuitry (transistors, triacs, etc.) Triacs are well suited to AC devices requiring less than an amp. They are sensitive to power spikes and might inadvertently turn on when there are transient voltage spikes. A resistor may need to be put in parallel with a load to ensure enough current is drawn to turn on the triac. The resistor size can be determined by
Transistor outputs use NPN or PNP transistors up to 1A typically. Their response time is well under 1ms.
11.24 The PLC Environment
11.24.1 Electrical Wiring Diagrams
• PLC’s are generally used to control the supply of power to a system. As a result, a brief examination of electrical supply wiring diagrams is worthwhile.
• Generally electrical diagrams contain very basic circuit elements, such as relays, transformers, motors, fuses, lights, etc.
• Within these systems there is often a mix of AC and DC power. 3 phase AC power is what is delivered universally by electric utilities, so the wiring diagrams focus on AC circuits.
• A relay diagram for a simple motor with a seal in circuit might look like the one shown below,:
• The circuit designed for the motor controller must be laid out so that it may be installed in an insulated cabinet. In the figure below, each box could be a purchased module(s).
• After the Layout for the cabinet is determined, the wire paths must be determined. The figure below lays out the wire paths and modules to be used.
• Discrete inputs - If a group of input voltages are the same, they can be grouped together. An example of this is shown below:
• If the input voltages are different and/or come from different sources, the user might use isolated inputs.
• Analog Inputs - The continuous nature of these inputs makes them very sensitive to noise. More is discussed in the next section, and an example is given below:
11.24.3 Shielding and Grounding
• In any sort of control system, wire still carries most inputs/outputs/communications
• We transmit signals along wires by pushing/pulling electrons in one end of the metal wires. Based upon the push/pull that shows up at the other end, we determine the input/output/communications. *** The key idea is that a signal propagates along the wire.
• There are two problems that occur in these systems.
1. Different power sources in the same system can cause different power supply voltages at opposite ends of a wire. As a result, a current will flow and an unwanted voltage appears. This can destroy components and create false signal levels.
2. Magnetic fields crossing the long conductors or in conductor loops can induce currents, destroy equipment, give false readings, or add unwanted noise to analog data signals.
• General design points
- Choose a good shielding cabinet
- Avoid “noisy” equipment when possible
- Separate voltage levels, and AC/DC wires from each other when possible.
• typical sources of grounding problems are:
- Resistance coupled circuits
- Ground loops
• Shielded wire is one good approach to reducing electrostatic/magnetic interference. The conductors are housed in a conducting jacket or the circuitry in housed in a conducting metal cabinet.
• Resistance coupled devices can have interference through a common power source, such as power spikes or brownouts caused by other devices in a factory.
• Ground loops are caused when too many separate connections to ground are made creating loops of wire that become excellent receivers for magnetic interference that induces differences in voltage between grounds on different machines. The common solution is to use a common ground bar.
11.24.4 PLC Environment
• Care must be taken to avoid certain environmental factors.
Dirt - dust and grime can enter the PLC through air ventilation ducts. As dirt clogs internal circuitry and external circuitry, it can effect operation. A storage cabinet such as Nema 4 or 12 can help protect the PLC.
Humidity - Humidity is not a problem with the modern plastic construction materials. But if the humidity condenses, the water can cause corrosion, conduct current, etc. Condensation should be avoided at all costs.
Temperature - The semiconductor chips in the PLC have operating ranges where they are operational. As the temperature is moved out of this range, they will not operate properly and the PLC will shut down. Ambient heat generated in the PLC will help keep the PLC operational at lower temperatures (generally to 0°C). The upper range for the devices is about 60°C, which is generally sufficient for sealed cabinets, but warm temperatures, or other heat sources (e.g. direct irradiation from the sun) can raise the temperature above acceptable limits. In extreme conditions, heating or cooling units may be required. (This includes “cold-starts” for PLCs before their semiconductors heat up).
Shock and Vibration - The nature of most industrial equipment is to apply energy to exact changes. As this energy is applied, there are shocks and vibrations induced. Both will travel through solid materials with ease. While PLCs are designed to withstand a great deal of shock and vibration, special elastomer/sprung or other mounting equipment may be required. Also note that careful consideration of vibration is also required when wiring.
- Interference - Discussed in shielding and grounding.
- Power - Power will fluctuate in the factory as large equipment is turned on and off. To avoid this various options are available. Use an isolation transformer. A UPS (Uninterruptable Power Supply) is also becoming an inexpensive option and are widely available for personal computers.
11.24.5 Special I/O Modules
• each card will have 1 to 16 counters generally.
• typical sample speeds 200KHz
• often allow count up/down
• the counter can be set to zero, or up/down, or gating can occur with an external input.
• High Speed Counter - When pulses are too fast to be counted during normal PLC ladder scans, a special counter can be used that will keep track of the pulses.
• Position controller - A card that will drive a motor (servo motor or stepper motor), and use feedback of the motor position to increase accuracy (feedback is optional with stepper motors).
• PID modules - For continuous systems, for example motor speed.
• There are 2 types of PID modules. In the first, the CPU does the calculation; in the second, a second controller card does the calculation.
- When the CPU does the calculation, the PID loop is slower.
- When a specialized card controls the PID loop, it is faster, but it costs more.
• Typical applications - positioning workpieces.
• Thermocouple - Thermocouples can be used to measure temperature, but these low voltage devices require sensitive electronics to get accurate temperature readings.
• Analog Input/Output - These cards measure voltages in various ranges and allow monitoring of continuous processes. These cards can also output analog voltages to help control external processes, etc.
• Programmers - There are a few basic types of programmers in use. These tend to fall into 3 categories:
1. Hand held units (or integrated) - They allow programming of PLC using a calculator type interface. And is often done using mnemonics.
2. Specialized programming units - Effectively these are portable computers that allows graphical editing of the ladder logic, and fast uploading/downloading/monitoring of the PLC.
3. PLC Software for Personal Computers - They are similar to the specialized programming units, but the software runs on a multi-use, user supplied computer. This approach is typically preferred over 2.
• Man Machine Interface (MMI) - The user can use,
• touch screens
• screen and buttons
• LCD/LED and buttons
• keypad to talk to PLC
• PLC CPU’s - A wide variety of CPU’s are available and can often be used interchangeably in the rack systems. The basic formula is price/performance. The table below compares a few CPU units in various criteria.
• Specialty cards for IBM PC interface.
- Siemens/Allen-Bradley/Etc have cards that fit into IBM computers and will communicate with PLC’s. Most modern PLCs will connect directly to a PC using ethernet or serial (RS-232) cables.
• IBM PC computer cards - an IBM compatible computer card that plugs into a PLC bus and allows use of common software
• For example, the Siemens CP580 Simatic AT
- 1 com port (RS-232C)
- 1 serial port (?)
- 1 RS-422 serial port
- RGB monitor driver (VGA)
- 3.5” disk
- TTY interface
- 9 pin RS-232C mouse
• Diagnostic Modules
- Plug in and all they do is watch for trouble.
• ID Tags - Special “tags” can be attached to products and, as they pass within range of pickup sensors, they transmit (via radio) an ID number or a packet of data. This data can then be used, updated and rewritten to the tags by the PLC
• e.g., Omron V600/V620 ID system
• a basic method for transmission of a text based message
• tags on parts carry message
• transceivers that receive and transmit changes
• Voice Recognition/Speech - In some cases verbal I/O can be useful. Speech recognition methods are still very limited, the user must control their speech. Background noise causes problems.
11.25 Practice Problems
1. A switch will turn a counter on when engaged. This counter can be reset by a second switch. The value in the counter should be multiplied by 5, and then displayed as a binary output using (201-208)
2. 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. In addition the key must be able to switch ignition power.
1. List of Inputs
2. Draw Ladder
3. TRUE / FALSE -- PLC outputs can be set with Bytes instead of bits.
4. Create a ladder logic program that will start when input ‘A’ is turned on and calculate the series below. The value of ‘n’ will start at 1 and with each scan of the ladder logic ‘n’ will increase until n=100. While the sequence is being incremented, any change in ‘A’ will be ignored.
5. A thumbwheel input card acquires a four digit BCD count. A sensor detects parts dropping down a chute. When the count matches the BCD value the chute is closed, and a light is turned on until a reset button is pushed. A start button must be pushed to start the part feeding. Develop the ladder logic for this controller. Use a structured design technique such as a state diagram.
6. Design and write ladder logic for a simple traffic light controller that has a single fixed sequence of 16 seconds for both green lights and 4 second for both yellow lights. Use either stacks or sequencers.
7. A PLC is to be used to control a carillon (a bell tower). Each bell corresponds to a musical note and each has a pneumatic actuator that will ring it. The table below defines the tune to be programmed. Write a program that will run the tune once each time a start button is pushed. A stop button will stop the song.
8. The following program uses indirect addressing. Indicate what the new values in memory will be when button A is pushed after the first and second instructions.
9. Divide the string in ST10:0 by the string in ST10:1 and store the results in ST10:2. Check for a divide by zero error.
10. Write a number guessing program that will allow a user to enter a number on a terminal that transmits it to a PLC where it is compared to a value in ’N7:0’. If the guess is above "Hi" will be returned. If below "Lo" will be returned. When it matches "ON" will be returned.
11. Write a program that will convert a numerical value stored in ‘F8:0’ and write it out the RS-232 output on a PLC-5 processor.
Bryan, L.A., Bryan, E.A., Programmable Controllers, Industrial Text Company, 19??.
Cox, R., Technician’s Guide to Programmable Controllers, Delmar Publishing, 19??.
Filer and Linonen, Programmable Controllers and Designing Sequential Logic, Dryden & Saunders/HBJ, 19??.
Petruzella, F., Programmable Logic Controllers, McGraw-Hill Publishing Co., 19??.
Sobh, M., Owen, J.C., Valvanis, K.P., Gracanin, S., “A Subject-Indexed Bibliography of Discrete Event Dynamic Systems”, IEEE Robotics and Applications Magazine, June 1994, pp. 14-20.
Sugiyama, H., Umehara, Y., Smith, E., “A Sequential Function Chart (SFC) Language for Batch Control”, ISA Transactions, Vol. 29, No. 2, 1990, pp. 63-69.
Swainston, F., A Systems Approach to Programmable Controllers, Delmar Publishing, 19??.
Teng, S.H., Black, J. T., “Cellular Manufacturing Systems Modelling: The Petri Net Approach”, Journal of Manufacturing Systems, Vol. 9, No. 1, 1988, pp. 45-54.
Warnock, I., Programmable Controllers: Operation and Application, Prentice Hall, 19??.
Wright, C.P., Applied Measurement Engineering, Prentice-Hall, New Jersey, 1995.
11.27 Laboratory - Serial Interfacing to a PLC
To write C++ and ladder logic program to communicate over RS-232.
only transmit a fixed number of characters
line endings important
when plc receives the following charaters it should,
A - turn on an output
B - turn off an output
C - return ’0’ if output is off, or ’1’ if output is on
1. If necessary review PLC basics and the PLC-5 tutorial.
2. Write a ladder logic program to receive ASCII commands as described in the Overview, and perform the desired action.
3. Write a C++ program to communicate with the ladder logic program using a user menu.
1. Enter the ladder logic program and test it with a terminal program.
2. Enter the C++ program and test it with a terminal emulator.
3. Test the two programs together.