plc study meterial

74
D.J.Dunn 1 PROGRAMMABLE LOGIC CONTROLLERS TUTORIAL – OUTCOME 1 This work covers all of outcome 1 of the Edexcel standard module: UNIT 21799P PROGRAMMABLE LOGIC CONTROLLERS The material is quite suitable for anyone wishing to study this interesting subject and does not require a lot of mathematical knowledge. Obviously, access to suitable computer software such as Pneusim Pro or Bytronics simulation software will be a great help. You do need to have a reasonable knowledge of computer technology and a good background understanding of industrial processes. SYLLABUS Design characteristics: unitary, modular, rack-mounted Input and output devices: mechanical switches, non-mechanical digital sources, transducers, relay. Communication links: twisted pair, coaxial, fibre optic, networks. Internal architecture: CPU, ALU, storage devices, memory, opto-isolators, input and output units, flags, shift, registers Operational characteristics: scanning, performing logic operations, continuous updating, mass 1/O copying Outcome Assessment Criteria Describe the design characteristics of typical programmable logic devices. Describe different types of input and output device. Describe the types of communication link used in programmable logic control systems. Describe the internal architecture of a typical programmable logic device. 1. Investigate the design and operational characteristics of programmable logic control systems Describe the operational characteristics of the CPU.

Upload: sargunam-sankaravadivel

Post on 13-Apr-2015

97 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Plc Study Meterial

D.J.Dunn 1

PROGRAMMABLE LOGIC CONTROLLERS

TUTORIAL – OUTCOME 1

This work covers all of outcome 1 of the Edexcel standard module:

UNIT 21799P PROGRAMMABLE LOGIC CONTROLLERS

The material is quite suitable for anyone wishing to study this interesting subject and does not require a lot of mathematical knowledge. Obviously, access to suitable computer software such as Pneusim Pro or Bytronics simulation software will be a great help. You do need to have a reasonable knowledge of computer technology and a good background understanding of industrial processes. SYLLABUS Design characteristics: unitary, modular, rack-mounted Input and output devices: mechanical switches, non-mechanical digital sources, transducers, relay. Communication links: twisted pair, coaxial, fibre optic, networks. Internal architecture: CPU, ALU, storage devices, memory, opto-isolators, input and output units, flags, shift, registers Operational characteristics: scanning, performing logic operations, continuous updating, mass 1/O copying

Outcome

Assessment Criteria

Describe the design characteristics of typical programmable logic devices. Describe different types of input and output device. Describe the types of communication link used in programmable logic control systems. Describe the internal architecture of a typical programmable logic device.

1. Investigate the design and operational characteristics of programmable logic control systems

Describe the operational characteristics of the CPU.

Page 2: Plc Study Meterial

D.J.Dunn 2

1. PURPOSE AND ORIGINS The PLC has its origins in the motor manufacturing industries. Manufacturing processes were partially automated by the use of rigid control circuits, electrical, hydraulic and pneumatic. It was found that when ever a change had to be made, the system had to be rewired or reconfigured. The use of wiring boards on which connections could be changed by unplugging them and changing them around followed. With the development of micro-computers it was realised that if the computer could switch things on or off and respond to a pattern of inputs, then the changes could be made by simply reprogramming the computer and so the PLC was born. There are still many applications of automated systems with permanent connections to perform a single control action. Often the system uses logic components to produce the correct action (electronic and pneumatic). The PLC mimics this process by performing the logical operations with the programme rather than with real components. In this way cost savings are produced as fewer components are needed and more flexibility is introduced as programmes can be changed more easily than reconfiguring a hard ware system. Programming is covered in Outcomes 2 and 3. A Programmable Logic Controller is a mini computer specifically designed for industrial and other applications. Examples are:

• Pneumatic machines. • Hydraulic machines. • Robots. • Production processes. • Packaging Lines. • Traffic Lights and signalling systems. • Refining processes.

2. ARCHITECTURE AND TERMINOLOGY The PLC activates its output terminals in order to switch things on or off. The decision to activate an output is based on the status of the system’s feed-back sensors and these are connected to the input terminals of the PLC. The decisions are based on logic programmes stored in the RAM and/or ROM memory. They have a central processing unit (CPU), data bus and address bus. A typical unitary PLC is shown below.

Figure 1

Page 3: Plc Study Meterial

D.J.Dunn 3

The next diagram shows a very oversimplified diagram of the structure. The Central processing Unit controls everything according to a programme stored in the memory (RAM or ROM). Everything is interconnected by two busses, the address bus and the data bus (shown as a single red line). The system must be able to communicate with external devices such as programmers, display monitors and Analogue/Digital converters.

Figure 2

THE CPU The next diagram shows the internal structure of the Central Processing Unit in its simplest form. It usually contains (but sometimes it is external and separate) an Arithmetic Logic Unit. This is the part that performs operations such as adding, subtracting, multiplying, dividing and comparing. The Buffers act as switches that isolate the lines on either side if required. A, B and C are latches that passes the data from one side to the other when told to do so. Digital data is passed around through busses. The busses were originally 4 parallel lines but as technology progressed this become 8, then 16 and now 32. Digital numbers and how they are put onto busses is explained in outcome 2. The busses are connected to memory chips. In a memory chip, digital numbers are stored in locations. The number is the data and the location is the address. Data can be sent to or brought from memory locations by either writing it or reading. The lines labelled R and W are signal lines that makes the CPU read or write. A REGISTER is a temporary memory location where data is put to be manipulated and then taken away. The CLOCK line is pulsed at a regular rate to synchronise the operations. Currently this has reached a rate measure in Giga Hertz (1000 million times a second). The Reset line when activated resets the programme Counter to Zero. The operations are carried out to a set of instruction (the programme) and these are decoded in the ID (Instruction Decoder)

Page 4: Plc Study Meterial

D.J.Dunn 4

Figure 3

INPUT MODULE The input module connects the input terminals to the rest of the system. Each terminal is usually electrically

isolated from the internal electronics by OPTO ISOLATORS. This is a way of passing on the status of the input (on or off) by use of a light emitting diode and phototransistor. A typical opto isolator is shown. They have the advantage of reducing the effects of spurious pulses generated from electro magnetic sources. It is also a safety feature to prevent live voltages appearing on the input lines in the event of a fault.

Figure 4 OUTPUT MODULE The output module contains switches activated by the CPU in order to connect two terminals and so allow current to flow in the external circuit. This will activate devices such as pneumatic solenoid valves, hydraulic solenoid valves, motors, pipe line valves, heating elements and so on. Care must be taken not to overload the contacts. The switch may be a transistor or a relay. The diagram shows a typical output arrangement. The terminals are numbered and these numbers are used in the programme.

Figure 5

Page 5: Plc Study Meterial

D.J.Dunn 5

MEMORY The PLC has RAM (Random Access Memory) and ROM (Read Only Memory). The programme, when written and entered, is stored in the RAM. The ROM contains permanent programmes such as that required to monitor the status of the inputs and outputs and to run diagnostic tests. TESTING The PLC has certain diagnostic, monitoring and testing facilities within the software. Light Emitting Diodes (LED) shows the status of the inputs and outputs. It is also possible to fix a bank of switches to the input side and test a programme by setting the switches to a certain state and seeing if the appropriate output action is taken. The most advanced method connects the PLC to a computer with appropriate software and runs a complete simulation of the system being controlled showing the status of everything. PROGRAMMING METHODS The P.L.C. is programmed with logical commands. This may be done through a programming panel or by connection to a computer. There are several types of programming panels varying in complexity from a simple key pad to a full blown hand held computer with graphics screen. Computers are able to run programming software with graphics, simulators, diagnostics and monitoring. This could be a laptop carried to the site or a main computer some distance away. Often the programme is developed and tested on the computer and the programme is transferred to the PLC. This could be by a communication link, by a magnetic tape, compact dusc or more likely with an EEPROM. The EEPROM is a memory chip to which the programme is written. The chip is then taken to the PLC and simply plugged in. The memory cannot be overwritten but it can be erased by exposure to UV light and reused. 3. STYLES The main styles are UNITARY, MODULAR and RACK MOUNTING.

Figure 6. A range of styles

Page 6: Plc Study Meterial

D.J.Dunn 6

UNITARY The Unitary PLC contains every feature of a basic system in one box. They are attached to the machine being controlled.

Figure 7 Unitary PLCs MODULAR These use a range of modules that slot together to build up a system. The basic modules are the power supply, the main module containing the CPU, the input module and the output module. Other modules such as A/D converters may be added. The main advantage is that the number of input and output terminals can be expanded to cope with changes to the hardware system. Modular PLCs may be designed to be fixed direct to a back panel. Usually they are arranged on a rack or rail and mounted inside a large cabinet for protection and security.

Figure 8 Modular PLCs

RACK MOUNTING This is a similar concept to the modular design but the modules are on standard cards that slot into a standard rack inside a cabinet. These are flexible and allow expansion of the system.

Page 7: Plc Study Meterial

D.J.Dunn 7

4. INPUT SENSORS

A range of sensors are needed to provide feed-back to the input terminals of the PLC. These measure or monitor many things such as:

• Position (linear and angular) • Temperature • Speed • Pressure • Weight • Quantity • Flow rate • Depth • Density • Acidity • Content (e.g. the carbon dioxide in a flue gas) • Voltage • Current • Torque • Power

Some of the sensors simply determine if something is on or off, such as:

• Simple switches (like start and stop) • Micro switches • Proximity switches • Relays • Voltage sensing relays • Outputs of A/D converters

Figure 9 A Range of Sensors

In order to control the position of actuators (electrical, hydraulic or pneumatic), sensors may be placed on them or on the machine that they move. These detect when the correct position has been reached (e.g. a switch to indicate that a guard is in place). If the control valves are electrically (solenoid) operated, simple mechanically operated electric switches may be used (micro switches).

Page 8: Plc Study Meterial

D.J.Dunn 8

Switches and valves may be normally open (NO) or normally closed (NC).

Figure 10

In many cases it is best to fit the sensor to the actuator. Cylinders are often fitted with reed switches, which are activated by a magnet fixed in the piston. These only work if the barrel is made of non-magnetic material such as aluminium.

Figure 11

There are ranges of devices, which switch on when something comes close to them. These are called PROXIMITY switches. They work on various electronic principles. The switching signal is turned on or off when the sensor is activated. Some will detect any material, some will only detect iron, and some will only detect metals in general. In this way, for example, it is possible to detect if the object is metal or plastic).

Figure 12

A similar sensor uses light beams and sensors. Often the light used in infrared. These sensors switch on or off when the light beam is interrupted. These might be used for detecting an item passing on a conveyor belt and activate a cylinder accordingly. They are widely used for counting the number of objects passing by.

Figure 13

Page 9: Plc Study Meterial

D.J.Dunn 9

VOLTAGE SENSING RELAYS These are used with analogue devices that produce a voltage representing the variable (e.g. a DC tachometer for measuring speed). The unit is adjusted to trip a relay when a certain point is reached (e.g. to indicate a motor has reached its correct speed). Typically 24 V is applied to the PLC input. Another example is a level measuring device that produces a voltage proportional to level and when the level reaches a certain depth, the voltage sensing relay trips and activates the PLC input. INPUT VOLTAGES Typical input voltages are 12V and 24V but sometimes they can be as low as 5V (the normal computer bus voltage) or as high as 110 or 240 V (normal mains a.c. levels). They may accept d.c. or a.c. No two PC’s are the same so you must take care to check the input rating. 5. OUTPUT DEVICES Output devices are switched on by the PLC. This can be anything electrical such as the following. • D.C. motor (e.g. to start a conveyor belt). • A.C. motor (e.g. to start a pump). • Linear electric actuator • Solenoid valve in hydraulic or pneumatic systems. • Solenoid valves on plant systems (e.g. to open a pipe line valve or allow steam into a heater). • Lights (e.g. traffic lights) • Alarms (e.g. fire alarm or oil level alarm). • Heating elements (e.g. heater in a hydraulic tank) Typical switching voltages are 12V, 24V, 110 and 240 V. In many cases, the PLC cannot switch the device directly because of the high voltage or current needed. In this case power switching relays or transistors are used. RELAYS

Some output switches are not able to switch high currents directly and the module would be damaged by high currents. They have to be interfaced to the hard ware by relays. A relay is used to allow a small current to operate devices with high current ratings. The relay is a mechanical switch and the contacts are moved by a solenoid.

Figure 14

Page 10: Plc Study Meterial

D.J.Dunn 10

6. COMMUNICATING A PLC must communicate with other devices. This is needed to link them to programming devices and to other equipment. Many modern instruments and other equipment send and receive information digitally so they are connected to the PLC by some form of network. The PLC’s may form part of a larger system controlled by a mainframe computer. The PLCs must be linked to each other and to the computer by a network. This is covered in Outcome 2. The diagram shows a network connecting a mainframe computer to a series of PLCs.

Figure 15

Links may be made through cables using serial data or parallel data. Parallel data may be through a ribbon cable (e.g. the ribbon cable linking a disc drive to a motherboard in a computer) or a screened multi-core cable (e.g. the printer cable on a computer). Serial data only requires two wires (e.g. a modem) although often many more are used (e.g. the Com port on a computer is serial but uses many wires).

Figure 16

Page 11: Plc Study Meterial

D.J.Dunn 11

TWISTED PAIR When information is sent along two wires, often a twisted pair is used. An example of this is the ordinary copper wire that connects your landline telephone to the network. To reduce the chances of picking up stray electro-magnetic signals from other lines running along side it, the two insulated copper wires are twisted around each other. More than one twisted pair may be placed inside an outer insulated layer and sometimes the cable is screened or shielded by a grounded outer layer. Twisted pairs come with each pair uniquely colour coded when it is packaged in multiple pairs. Different uses such as analogue, digital, and Ethernet require different pair multiples. Although the twisted pair is often associated with home use, a higher grade of twisted pair is often used for horizontal wiring in LAN installations because it is less expensive than coaxial cable. COAXIAL CABLES Coaxial cable is the kind of cable used to connect a TV set to the aerial. It is also used to connect telephone exchanges to the telephone poles near to users. It is also widely used to connect computers and PLC’s with systems such as Ethernet and other types of local area network (LAN).

The cable has an inner conductor surrounded by a concentric conductor (coaxial with it) made from copper mesh and separated by a layer of insulation. The outer layer is usually grounded. They can carry information for a great distance.

FIRE OPTICS Fibre optic cables are basically thin glass strands. When light is shone into one end of a strand (e.g. by a laser) it is carried inside the fibre over enormous distances without losing its strength. The light can be pulsed to carry digital information at enormous speeds and rates. Optical fibre carries much more information than conventional copper wire and is in general not subject to electromagnetic interference and the need to retransmit signals. Many strands can be bundled together to give many more channels. Computers needing high speed data transmission usually have fibre optic links to the server. You ill find a full explanation of everything to do with fibre optics at: http/rwm.org/of/theory011.htm

Page 12: Plc Study Meterial

D.J.DUNN 1

PROGRAMMABLE LOGIC CONTROLLERS

TUTORIAL – OUTCOME 2 Part 1

This work covers part of outcome 2 of the Edexcel standard module:

UNIT 21799P PROGRAMMABLE LOGIC CONTROLLERS

The material is quite suitable for anyone wishing to study this interesting subject.

This tutorial requires basic mathematical skills and a reasonable knowledge of digital

electronic terminology. An industrial background will also be of great benefit to

students. Obviously, access to suitable computer software such as Pneusim Pro or

Bytronics simulation software will be a great help.

The shaded areas are covered in this tutorial.

SYLLABUS

Investigate programmable logic controller information and communication techniques

Forms of signal: analogue (0-10 V dc, 4 - 20mA), digital, discrete

Resolution and relationships: 9-bit,10-bit,12-bit

Number systems: decimal, binary, octal, Hexadecimal, BCD

Protocols: RS232, IEE4BB, RS422, 20Ma

Networking methods and standards: master to slave, peer to peer, ISO, IEE, MAP

Logic functions: AND, OR, EXCLUSIVE OR, NAND, NOR

Outcome

Assessment Criteria

Outcome 2

Information and

communication techniques.

Describe the different forms of signal used in programmable

logic control.

Describe the resolution and relationship between analogue

inputs and outputs and word length.

Express numbers using different number systems.

Investigate the typical protocols used in signal

communication.

Investigate networking methods and networking standards.

Derive simple programs using logic functions based on relay

ladder logic.

Page 13: Plc Study Meterial

D.J.DUNN 2

1. INTRODUCTION

Programmable logic controllers are digital devices and using the same kind of internal structure as

computers. The information is processed internally in digital forms using data and address busses.

They must communicate with external devices such as other computers and programming panels.

The digital communication must conform to industrial standards. In industrial applications there are

many analogue signals and these must be converted into or from the digital form before they can be

received or sent by the PLC.

We first need to look at digital information and how it forms numbers of various forms.

2. NUMBER SYSTEMS

2.1 BINARY NUMBERS

A number may be represented in digital form by a simple pattern. The pattern may be generated for

example with a row of lights switched on by an electric current. The pattern will also exist in the

wires connected to the light bulbs. In digital electronics the pattern exists as a voltage relative to

zero. Ideally in a typical computer, 5V is on or high and zero is off or low but to make a clear

distinction, a voltage of over 3 is regarded high and below 2 is regarded as low. The patterns were

originally developed in computers for 8 lines and then this became 16 and now it is 32. Consider a

pattern of 8 lines. We indicate on or high with a 1 and off or low with a 0. Each line carries a bit of

information as on or off and so the line is referred to as a bit.

In the denary system the digit that represents the highest value is on the left (e.g. the 3 in 32 or the 4

in 461). The digit representing the lowest value is on the right. These are called the most significant

digit and least significant digit. In binary numbers we adopt the same idea with the bit on the left

being the most significant bit (MSB) and the one on the right being the least significant bit (LSB).

Figure 1

The total pattern is called a word and the one shown is an 8 bit word. The pattern may be stored in a

register so it is also referred to as an 8 bit register. A register is a temporary store where the word

may be manipulated.

Each bit has a value of zero when off (low) or the denary value shown when on (high). The denary

value of the pattern is found by adding them all up. The maximum value for an 8 bit word is when

all the bits are high and corresponds to 255.

Page 14: Plc Study Meterial

D.J.DUNN 3

WORKED EXAMPLE No.1

What is the denary value of the digital pattern below?

Figure 2

SOLUTION

128 + 64 + 8 + 2 = 202

SELF ASSESSMENT EXERCISE No.1

Write down the decimal value represented by the following 8 bit patterns.

1 0 1 0 1 0 1 1 ________________________________

1 0 0 1 0 0 1 0 ________________________________

0 1 0 0 1 0 1 1 ________________________________

Here is a small table of binary numbers with the equivalent denary values.

BINARY

00 01 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111

DENARY

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

CONVERSION

A way of converting decimal into binary is to keep dividing the number by 2 as follows.

Convert decimal 12 into binary form.

12 ÷ 2 = 6 remainder 0

6 ÷ 2 = 3 remainder 0

3 ÷ 2 = 1 remainder 1

1 ÷ 2 = 0 remainder 1

The binary pattern is hence 1 1 0 0

Page 15: Plc Study Meterial

D.J.DUNN 4

Another way to express the value of each bit comes about by realising that each bit is 2 raised to the

power of the bit number.

Figure 3

2.2. OCTAL and HEXADECIMAL

Octal is a numbering system based on cycles of 8. It is quite easy to convert a digital number into

octal and for this reason it is used by programmers to address memory locations and port addresses

(printer port, com port, CD driver address and so on). Early computers used words with 8 bits so

octal was convenient to use.

Hexadecimal is a numbering system based on 16 and was introduced for the same reasons as octal

when computers were developed with 16 bit registers. Hexadecimal Numbers are of far greater

importance in modern computing. One Nibble (4 bits) is represented by 1 Hex digit. One Byte is

represented by 2 Hex Digits.

In octal we have no need for the figures 9 as the cycle restarts after 7.

In hexadecimal, we need extra figures and the letters A, B, C, D, E and F are used.

Here is the beginning of a conversion table:

Decimal Binary Octal Hexadecimal

0 00000 0 0

1 00001 1 1

2 00010 2 2

3 00011 3 3

4 00100 4 4

5 00101 5 5

6 00110 6 6

7 00111 7 7

8 01000 10 8

9 01001 11 9

10 01010 12 A

11 01011 13 B

12 01100 14 C

13 01101 15 D 14 01110 16 E

15 01111 17 F

16 10000 20 10

· · · ·

· · · ·

· · · ·

Page 16: Plc Study Meterial

D.J.DUNN 5

2.3 CONVERSION TO/FROM BINARY

Whereas Decimal seems to have no connection with Binary, from this table we can see that Octal

and Hexadecimal are linked to Binary. The first digit in Octal corresponds to the first three digits in

it's Binary equivalent, and so on. The same is true for Hexadecimal, but this time each digit

represents four Binary digits.

(It may be useful to note that 8 = 23, and 16 = 2

4).

An advantage of knowing this is that is makes conversion to/from Binary very easy.

WORKED EXAMPLE No.2

Convert :1111101 Into Octal and Hexadecimal

SOLUTION

Octal: Split the number into groups of 3 starting from the L.S.B. on the right.

1 111 101

Now convert each group immediately into one Octal digit, i.e. 1 becomes 1, 111 becomes 7,

101 becomes 5.

So :1111101 = @175 (@ is the prefix indicating an Octal number)

Hexadecimal: Split the number into groups of 4.

111 1101

Convert each group immediately into one Hex digit, i.e. 111 becomes 7, 1101 becomes D.

So :1111101 = &7D (& is the prefix indicating a Hexadecimal number)

Conversion from Octal and Hexadecimal to Binary is similarly easy.

Page 17: Plc Study Meterial

D.J.DUNN 6

2.4 DECIMAL TO OCTAL CONVERSION

This is done in a similar way to converting Decimal to Binary. Repeatedly divide the decimal

number by 8 and read off the remainders in reverse order.

WORKED EXAMPLE No.3

Convert 70 Into Octal.

SOLUTION

70 ÷ 8 = 8 Remainder 6

8 ÷ 8 = 1 Remainder 0

1 ÷ 8 = 0 Remainder 1

So 70 = @106

WORKED EXAMPLE No.4

Convert 125 into Octal

SOLUTION

125 ÷ 8 = 15 Remainder 5

15 ÷ 8 = 1 Remainder 7

1 ÷ 8 = 0 Remainder 1

So 125 = @175

2.5 DECIMAL TO HEX CONVERSION

This again is done by repeatedly dividing the Decimal number by 16 and reading off the remainders

in reverse order.

WORKED EXAMPLE No.5

Convert 70 into Hexadecimal

SOLUTION

70 ÷ 16 = 4 Remainder 6

4 ÷ 16 = 0 Remainder 4

So 0 = &46

Page 18: Plc Study Meterial

D.J.DUNN 7

WORKED EXAMPLE No.6

Convert 125 into Hexadecimal

SOLUTION

125 ÷ 16 = 7 Remainder D

7 ÷ 16 = 0 Remainder 7

So 125 = &7D

An application of Hexadecimal numbers is for representing bit patterns. For example the letter "A"

is represented in ASII codes as 0100 0001 or more conveniently &41. Similarly, the letter "B" is

represented as &42.

SELF ASSESSMENT EXERCISE No.2

1. Convert 45 into Hex.

2. Convert 20 into Octal

3. Convert 125 into Binary.

Note that most scientific/engineering calculators are able to do these conversions.

Page 19: Plc Study Meterial

D.J.DUNN 8

2.6. APPLICATIONS

Consider the basic operation of a computer memory ship. The chip has an address bus and a data

bus. It also has a read or write command

line.

Each line in the bus can be on (high) or

off (low) so the system is based on

binary patterns. Older equipment had 8

lines in each bus and so Octal became

useful. Later this increased to 16 lines so

hexadecimal became useful. It has since

moved on to 32 and 64 lines.

Clearly to use larger numbers, you need

more lines in the bus.

Figure 4

The diagram shows 8 lines in each bus. When they are all low the decimal value is 0. When they are

all high the decimal value is 255 so there are 256 different values that can be represented.

When the R/W line is set to write, the binary pattern on the data bus is transferred into a store at the

address represented by the binary pattern on the address line. This store is also called a register and

the binary pattern is contained in this register.

When the R/W line is set to read, the pattern stored in the register at the address on the address bus

is transferred to the data bus.

SELF ASSESSMENT EXERCISE No.3

Write down the data value in decimal and the address in octal for the case shown.

Figure 5

Page 20: Plc Study Meterial

D.J.DUNN 9

2.7. MANIPULATION

Numbers stored in registers may be added or subtracted to a number stored in another register. This

is done in a processing chip. The number from two memory locations is transferred into data

registers. A command to the processor makes it add them and the result is placed in a third data

register and perhaps transferred to a memory location.

ADDING IN DECIMAL

235+

926

1161

Starting with the LSB 5 + 6 = 11 write down 1 carry 1

Next 3 +2 + carry 1 =6 write down 6 carry 0

Next 2 + 9 + carry 0 = 11 write down 1 carry 1

Next start a new column and write down carry 1

ADDING IN BINARY

The process is the same.

01101101 +

11011001

101000110

Starting the LSB, 1+1 = 10 write down 0 carry 1

Moving to bit 1 0+0 + carry = 1 write down 1 carry 0

Moving to bit 2 1+0 + carry 0 = 1 write down 1 carry 0

Moving to bit 3 1+1+ carry 0 = 10 write down 0 carry 1

Moving to bit 4 0+1+ carry 1 = 10 write down 0 carry 1

Moving to bit 5 1+0+ carry 1 = 10 write down 0 carry 1

Moving to bit 6 1+1+carry 1 = 11 write down 1 carry 1

Moving to bit 7 0+1+carry 1 = 11 Write down 1 carry 1

Moving to bit 8 which does not exist there is an implied 0 + 0 + carry 1 so write down 1. Clearly to

store this number you would need a register with more than 8 bits.

ADDING IN OCTAL

This is similar but remember that it is based on 8.

332 + 167

521

Starting with the LSB 2 + 7 = 1 1 write down 1 carry 1

Next 3 + 6 + carry 1=12 write down 2 carry 1

Next 3+1+ carry 1 = 5 write down 5

Adding in HEX is more difficult as you need to remember the values of ABCDEF

It is best to do it on the calculator. Computers do it in binary and the answers are usually expressed

in Decimal, Octal or Hex.

Page 21: Plc Study Meterial

D.J.DUNN 10

SELF ASSESSMENT EXERCISE No.4

Use your calculator to do the following calculations.

Binary Octel Hexadecimal

11011 x 01101= @27 x @35= &2D5 x &3A1=

11100 + 101100= @326 + @667= &5CE + &9EF=

11000 – 01011= @642 – @341= &FF5 – &3DE=

Page 22: Plc Study Meterial

D.J.DUNN 11

2.8. BINARY DECIMAL CODES

BCD is yet another way of presenting digital data as a number and it is used in industrial

applications (e.g. to code or decode a digital signal from a position transducer).

The digital pattern in a register is converted into a 3 digit BCD as follows. The first 4 bits are turned

into a normal (denary) number and this number is the units. The next 4 bits are the tens and the next

4 bits are the hundreds. The units cannot exceed a total of 9. The tens cannot exceed a total of 90

and the hundreds cannot exceed a total of 900. The maximum number which can be represented is

999.

WORKED EXAMPLE No.7

Deduce the value of the BCD pattern.

Figure 6

SOLUTION

The first 4 bits decode to 4 + 2 = 6

The second 4 bits decode to 2 + 1 = 3

The third 4 bits decode to 4 + 1 = 5

The decimal value represented is hence 536

SELF ASSESSMENT EXERCISE No.5

Deduce the value of this pattern

Figure 7

Answer 695

Page 23: Plc Study Meterial

D.J.DUNN 12

3. REGISTERS

A register is a memory location containing a digital number. The difference between a register and

any other memory location is that the bits may be manipulated under control of the programme.

Hence the bits may be shifted right or left or rotated. Depending on the programme, the new bit may

be a 1 or a 0.

SHIFTING

Consider the example below where the register is shifted right with a 1 being added.

What is the decimal value before the shift? _________________________

What is the decimal value after the shift? _________________________

Now consider the same problem with a right shift.

What is the decimal value before the shift? _________________________

What is the decimal value after the shift? _________________________

Each bit of the register may be used to control an output so if a bit changes from 0 to 1 the output

connected to the bit is turned on. There are many uses for shifting; one of them is to produce a

counter.

ROTATING

Rotating is similar to shifting but the bit that drops off the end reappears as the new bit.

Numbers stored in registers can be manipulated.

ADDING and SUBTRACTION

The contents of one register are added or subtracted to/from the contents of another and the result

placed in a third register.

MULTIPLICATION and DIVISION

The contents of one register may be multiplied or divided by the contents of another and the result

placed in a third register.

INCREMENTING AND DECREMENTING

The decimal value of the register is increased by 1 when incremented and decreased by 1 when

decremented.

Page 24: Plc Study Meterial

D.J.DUNN 13

COMPARISON

The contents of two registers may be compared to see if they are the same.

Other arithmetical operations may be done such as square roots and differentiation depending on the

PLC. The actual operation is much more complicated than discussed here and the result leads to

carry over or borrowing of bits. There are special flags that are switched on to indicate these things.

FLAGS are single bits in a register that are switched on to indicate the status of something. They

are not physical outputs. They can be addressed and used within a programme. PLCs often contain

flags that are automatically switched on when a certain event happens such as illustrated below.

Figure 8

4. ANALOGUE TO DIGITAL and DIGITAL TO ANALOGUE CONVERSION

Analogue to digital conversion is a process of turning an analogue voltage or current into a digital

pattern that can be read by a computer and processed.

Digital to analogue conversion is the reversed process.

A typical module for a PLC is shown below. There are two A/D channels and one D/A channels.

The module is connected to the PLC by a ribbon cable or plugs directly to the PLC.

Figure 9

The analogue signals are 4 to 20 mA in a modern system but 0 – 10 volts is still common and

others are possible. The appropriate signal must be connected to the appropriate terminal (V for

Volts, I for current and C common). To read an analogue signal into the PLC a routine must be

executed within the programme to read the appropriate input. The module produces the conversion

and the digital number representing the analogue signal is read into a designated register of the

PLC.

To produce an analogue output, a routine must be executed to take a digital value in a designated

register and put it out to the module where it is converted into a voltage or current.

Page 25: Plc Study Meterial

D.J.DUNN 14

RESOLUTION

When a digital number is converted into a voltage, each increment of the binary value corresponds

with an increment in the voltage output. The value of this increment is the resolution.

Consider an 8 bit system. The minimum and maximum number that can be stored is 0 and 255 so

there are 255 steps. An analogue voltage in the range 0 to 10 V van be divided up into 254 steps so

the resolution is 10/255 = 0.0392 V. This is adequate for most purposes but if very small changes in

voltages are to be detected, a higher resolution is needed. A/D and D/A systems commonly

available use anything from 4 bits to 32 bits depending on the resolution required. For example if a

thermocouple is used to measure temperature, the voltage change for 1oC is very small and a fine

resolution is needed. Other instruments fall in this category.

WORKED EXAMPLE No.8

An analogue instrument produces a variable voltage of 0 to 10 V. It is processed with an A/D

converter using 5 bits. Calculate the minimum change in voltage that can be detected.

SOLUTION

5 bits has maximum value of 1 + 2 + 4 + 8 + 16 = 31 so the smallest voltage detectable is 10/31

= 0.322V

SELF ASSESSMENT EXERCISE No.6

An analogue instrument produces a signal with a range 4 to 20 mA. It is processed with a 9 bit

A/D converter. What is the smallest current change that ca be detected.

Answer 0.0313 mA

Page 26: Plc Study Meterial

D.J.DUNN 1

PROGRAMMABLE LOGIC CONTROLLERS

TUTORIAL – OUTCOME 2 Part 2

This work covers part of outcome 2 of the Edexcel standard module:

UNIT 21799P PROGRAMMABLE LOGIC CONTROLLERS

The material is quite suitable for anyone wishing to study this interesting subject. This tutorial requires basic mathematical skills and a reasonable knowledge of digital electronic terminology. An industrial background will also be of great benefit to students. Obviously, access to suitable computer software such as Pneusim Pro or Bytronics simulation software will be a great help. The areas covered are shaded. SYLLABUS Investigate programmable logic controller information and communication techniques Forms of signal: analogue (0-10 V dc, 4 - 20mA), digital, discrete Resolution and relationships: 9-bit,10-bit,12-bit Number systems: decimal, binary, octal, Hexadecimal, BCD Protocols: RS232, IEE4BB, RS422, 20Ma Networking methods and standards: master to slave, peer to peer, ISO, IEE, MAP Logic functions: AND, OR, EXCLUSIVE OR, NAND, NOR

Outcome

Assessment Criteria

Describe the different forms of signal used in programmable logic control. Describe the resolution and relationship between analogue inputs and outputs and word length. Express numbers using different number systems. Investigate the typical protocols used in signal communication. Investigate networking methods and networking standards.

Outcome 2 Information and communication techniques.

Derive simple programs using logic functions based on relay ladder logic.

Page 27: Plc Study Meterial

D.J.DUNN 2

1. COMMUNICATION When you come to a set of traffic lights, you observe the colour and interpret red as meaning stop and green as go. In Britain we also have orange which gives a warning of change but it does not take priority over stop or go. This is PROTOCOL and other countries have a different protocol so we must be very careful to use the correct protocol. Another example of protocol is shaking the head to mean no and nodding to mean yes. There are countries where the opposite applies. When you use a computer or mobile phone to communicate with someone else, the data is transmitted digitally. Each end of the communication link has a MODEM (Modulator/Demodulator) to encode or decode the digital data. The transmission may be through a radio link, through copper wires or optic fibres. (see outcome 1) More complex systems such as used in industry or at a telephone exchange, send multiple channels in both directions and in order to do this they need a multiplexer. When sending data the multiplexer mixes the channels together to form one channel. The modem sends them (a bit of each at a time). When receiving signals, the process is reversed. Signals are needed to tell the equipment when to send and when to receive. Other signals are needed to synchronise the signals at both ends. This is another example of protocol.

Figure 1

On electronic equipment we find many types of standard plugs and sockets. Here are 3 popular types.

Figure 2

These are used typically on printers, scanners, disc drives and COM ports. They may be attached to all forms of industrial equipment as well as computers. Some carry SERIAL transmission and other PARALLEL transmission. Serial transmission means the data is sent one bit at a time while parallel transmission might send a whole word in one go. Digital data transmission is not covered in detail here.

Page 28: Plc Study Meterial

D.J.DUNN 3

Industrial systems also use many methods of linking equipment such as PLCs, computers, sensors, monitors and automated machinery. In order that equipment can be interconnected physically, the sockets, plugs and wiring connections must be the same for everyone otherwise you could not work with each other. The standards covering a range of sizes and applications are numerous. Here are details of some of the standard forms of links and protocols. RS232

RS-232 is a system originally developed for linking telly printers and is a relatively slow serial data transmission system. The standard is for the physical interface and protocol used in many links from computers to industrial electronic equipment. The system has undergone many updates and RS232C is the current one. Typical uses are in computer modems and linking any device using serial communication. Somewhere in the equipment is a Universal Asynchronous Receiver/Transmitter (UART) chip. The data is transmitted to a modem (or other serial device) from its Data Terminal Equipment (DTE) interface. Data inside equipment flows along busses (Data and Address busses) and these are parallel circuits. Serial devices can only handle one bit at a time. The UART chip converts the groups of bits in parallel to a serial stream of bits. The 9 pin (DB9) and 25 pin (DB25) sockets are shown below with their connections for RS 232.

Figure 3

Here are the pin connections for joining the plugs without explanation.

DB-9 PIN (Male) FUNCTION ABBREVIATION 1 --------------------------- Data Carrier Detect CD or DCD 2 ------------------------------ Receive Data RD or RX 3 ---------------------------- Transmitted Data TX or TD 4 ---------------------------- Data Terminal Ready DTR 5 ------------------------------ Signal Ground GND 6 ------------------------------ Data Set Ready DSR 7 ------------------------------ Request To Send RTS 8 ------------------------------ Clear To Send CTS 9 ------------------------------ Ring Indicator RI DB-25 PIN (Male) FUNCTION ABBREVIATION 1 ---------------------------- Chassis/Frame Ground GND 2 ------------------------------ Transmitted Data TX or TD 3 -------------------------------- Receive Data RX or RD 4 ------------------------------ Request To Send RTS 5 ------------------------------- Clear To Send CTS 6 ------------------------------- Data Set Ready DSR 7 ------------------------------- Signal Ground GND 8 ---------------------------- Data Carrier Detect DCD or CD 9 ------------------------- Transmit + (Current loop) TD+ 11 ------------------------ Transmit - (Current Loop) TD- 18 ------------------------- Receive + (Current Loop) RD+ 20 --------------------------- Data Terminal Ready DTR 22 ----------------------------- Ring Indicator RI 25 ------------------------- Receive - (Current Loop) RD-

2in to 9 pin 9 pin to 9 pin

Figure 4

Page 29: Plc Study Meterial

D.J.DUNN 4

RS422

The RS422 is similar to the RS232 but it more suited to transmissions over long cables. Converters are devices which allow different systems such as the RS232 and 422 to communicate even though the protocols are different.

IEEE 488 This is the main standard for parallel data transmission such as used on the printer ports (LPT) of computers. Usually you find the DB25 at the computer end and the Centronics type (36 pins) at the other end. These are widely used to link industrial equipment using digital technology.

When the Centronics parallel interface was first developed, the main peripheral was the printer. Since then, portable disk drives, tape backup drives, and CD-ROM players are among devices that have adopted the parallel interface. These new uses caused manufacturers to look at new ways to make the Centronics parallel interface better. In 1991, Lexmark, IBM, Texas instruments, and others met to discuss a standard that would offer more speed and bi-directional communication. Their effort and the sponsorship of the IEEE resulted in the IEEE 1284 committee. The IEEE 1284 standard was approved for release in March, 1994.

DB-25 PIN (Female) SIGNAL DB-25 MALE CONN DB-25 FEMALE CONN 1 ------------------------------- > STROBE * 2 ------------------------------- > DATA 0 3 ------------------------------- > DATA 1 4 ------------------------------- > DATA 2 5 ------------------------------- > DATA 3 6 ------------------------------- > DATA 4 7 ------------------------------- > DATA 5 8 ------------------------------- > DATA 6 9 ------------------------------- > DATA 7 10< ------------------------------ ACK * 11< ------------------------------ BUSY 12< ------------------------------ PAPER END 13 ------------------------------ SLCT (select) 14 ------------------------------ >AUTOFEED * 15< ------------------------------ ERROR * 16 --------------------------->INITIALIZE PRINTER * 17 ------------------------------- SLCTIN (select in) 18 thru 25 ----------------------- GND

Page 30: Plc Study Meterial

D.J.DUNN 5

INDUSTRIAL APPLICATIONS Manufacturing And process industries use similar methods of communication to link the systems to each other. A typical manufacturing system is illustrated below. Various machines are controlled by individual PLCs and these are linked to each other and to the main computer.

Figure 5

The computer at the top is the MASTER and the plc are the SLAVES. Communication between them is master to slave or slave to master. Communication between the PLCs is peer to peer. There are various protocols and standards laying down the way they communicate such as: ISO International Standards Organisation IEEE Institute of Electrical and Electronic Engineers MAP Manufacturing Automation Protocols This is a token-passing local area network configuration adopted by General Motors for factory automation.

NETWORKS - Definitions LAN Local Area Network ETHERNET This is a very common method of networking computers in a LAN using copper cabling. Ethernet will handle about 10,000,000 bits-per-second and can be used with almost any kind of computer. INTRANET This is a general name for networks linking computers within a private organisation such as colleges, businesses and government departments. They use standard network technologies like Ethernet and web servers. Users connected to the intranet often have access to the internet but a firewall prevents external users accessing it. Sometimes it may allow access to an extranet to provide controlled access to some outsiders (e.g. other government departments). EXTRANET An extranet is a private network that allows limited access to specified users. It uses the Internet for these links. A typical example is a bank with internet access for customers using secure protocols.

Page 31: Plc Study Meterial

D.J.DUNN 6

INSTRUMENT TELEMETRY On a complex process plant, the need to transmit many process variables plus the state of many switches (on or off) has led to the use of TELEMETRY SYSTEMS. Typically the process variables are converted into digital data. The many sources of data is continuously scanned and compressed into a single stream and transmitted through a MODEM as serial data. The data is sent through radio, cables and optic fibres. At the other end the process is reversed. The diagram shows a simplified system in which various elements in a water pumping station are controlled and monitored remotely.

Figure 6

Digital data in such a system is usually sent in SERIAL form such as RS232 on the shorter links and RS422 on the longer links. All these methods involve recognition of a voltage level to decide if a bit is on or off and it is prone to interference. Whereas voltage might be degraded over a long wire, current is not so another protocol uses 20 mA to indicate a high bit.

Page 32: Plc Study Meterial

D.J.DUNN 1

PROGRAMMABLE LOGIC CONTROLLERS

TUTORIAL – OUTCOME 2 Part 3

This work covers part of outcome 2 of the Edexcel standard module:

UNIT 21799P PROGRAMMABLE LOGIC CONTROLLERS

The material is quite suitable for anyone wishing to study this interesting subject. This tutorial requires basic mathematical skills and a reasonable knowledge of digital electronic terminology. An industrial background will also be of great benefit to students. Obviously, access to suitable computer software such as Pneusim Pro or Bytronics simulation software will be a great help. The areas covered are shaded. SYLLABUS Investigate programmable logic controller information and communication techniques Forms of signal: analogue (0-10 V dc, 4 - 20mA), digital, discrete Resolution and relationships: 9-bit,10-bit,12-bit Number systems: decimal, binary, octal, Hexadecimal, BCD Protocols: RS232, IEE4BB, RS422, 20Ma Networking methods and standards: master to slave, peer to peer, ISO, IEE, MAP Logic functions: AND, OR, EXCLUSIVE OR, NAND, NOR

Outcome

Assessment Criteria

Describe the different forms of signal used in programmable logic control. Describe the resolution and relationship between analogue inputs and outputs and word length. Express numbers using different number systems.. Investigate the typical protocols used in signal communication.. Investigate networking methods and networking standards..

Outcome 2 Information and communication techniques.

Derive simple programs using logic functions based on relay ladder logic.

Page 33: Plc Study Meterial

D.J.DUNN 2

1. INTRODUCTION Programming a PLC is helped by various aids such as LOGIC CIRCUITS, LADDER DIAGRAMS, TRUTH TABLES and BOOLEAN EXPRESSIONS. They are all linked and the following shows how they are related. We will consider the main logical functions and explain them in terms of each. 2. LOGIC FUNCTIONS OR FUNCTION Suppose a light may be switched on by pressing switch A or B. This may be achieved in a hard wired circuit by placing two normally open switches in parallel so that when either A or B is closed, current flows in the circuit from plus to minus. This may be represented as LADDER LOGIC. The American Ladder Logic simply shows the switches as open contacts. European ladder logic symbols are more complex and indicate the type of switch as well (see symbols overleaf). The same function may be made with a hardware item called a logic gate. Here we are considering electronic gates but pneumatic versions perform the same function with air instead of electricity. The European and American symbol is shown below. In general the output of the gate is labelled Z and this become live (high) when either A or B is made live (goes high). The TRUTH TABLE is a way of showing the logic function. We indicate that a terminal is high (on or live) with a 1 and low (off or dead) with a 0. The table shows that the output is only low when both A and B are low.

Figure 1

Yet another tool to help us understand these things is BOOLEAN ALGEBRA. Basically this is a method of turning words into symbols so when we say output Z is on when either line A or B is on or A and B is on together. We write: Z = A + B + A.B The plus sign means OR and the dot means AND Boolean Algebra can be manipulated according to certain rules to reduce complex expressions to simpler expression. This is not covered here. INVERSION An O added to any input terminal inverts the signal (i.e. it is a not gate). The following gate produces a Boolean statement of Z = .BA

Figure 2

Page 34: Plc Study Meterial

D.J.DUNN 3

AND FUNCTION The output Z is turned on when input A and B is turned on. The hard wire circuit would be two switches in series and this is shown as ladder logic. The Boolean statement is Z = A.B meaning Z is high only when A AND B are high.

Figure 3

NOT FUNCTION This is a function equivalent to a normally closed switch. The light is normally on but when the switch is pressed the light goes out. In logic terms the output is on when the input is off and off when the input is on. The Boolean statement is either Z = A or Z = A The over score indicates low or off.

Figure 4

EXCLUSIVE OR (XOR) The output is on when A or B is on but not when both are on. The hard wire circuit requires each switch to have a normally open and a normally closed contact. The Boolean statement is:

Z = A + B which means Z is on when A is on and B is off or when A is off and B is on.

Figure 4

Page 35: Plc Study Meterial

D.J.DUNN 4

NAND FUNCTION This is the opposite of an and. The equivalent hard circuit uses two normally closed switches in parallel so the light is always on except when both are pressed. The Boolean statement is:

Z = A.B meaning Z is Off when A and B are both on.

Figure 5

NOR FUNCTION This is the reverse of the OR gate and it can be created by two normally closed switches in series. The output is only on when both switches are not operated (off). The Boolean statement is:

Z = BA +

Figure 6

MULTIPLE INPUTS Logic gates may have as many inputs as you like. This one has three inputs so the output Z is turned on when A and B and C is turned on.

Figure 7

Page 36: Plc Study Meterial

D.J.DUNN 5

BUILDING A CIRCUIT A more complex logic circuit is shown below with four inputs. The truth table is shown with only the conditions for turning the output on. The pattern of the inputs can be interpreted as a digital number.

Figure 8

There are three possible combinations that can turn the output on. The three digital numbers that will turn the output on are hence 14, 1 and 15. (With A forming the most significant bit). If A, B, C and D were connected to a computer data bus then the computer could switch the output on when it recognises these numbers.

Page 37: Plc Study Meterial

D.J.DUNN 6

3. INTRODUCTION TO LADDER DIAGRAMS In the previous section you have seen how a logic circuit can be made with hardware. A PLC programme simulates a hardware circuit and produces the same result. The input and output elements are real items but the way they are connected is purely simulation. In addition, imaginary hardware items such as counters and timers may be added to produce the desired results. Programming is covered in more detail in outcome 3. The following is an introduction to the subject. Basically, to switch something on, a circuit has to be made continuous between the plus and minus power buses of the system. When a circuit is laid out in this way it resembles the rung of a ladder, hence the name ladder diagram. Consider the simple case of turning on a motor by pressing push button switch.

Figure 9

Things can be switched on by sensor switches such as a position sensor as well as manual switches. These are input elements. Things that can be switched on (motors, relays, lamps etc) are called output elements. The European symbols show more information about the type of element and is more widely used for real hardware circuits. As this is of no importance in programming a PLC the American system is widely adopted for PLC work. The next diagram shows a solenoid operated directly by a sensor with no relay.

Figure 10

This next diagram shows a solenoid valve operated by a relay. The relay is operated by the position sensor. The sensor contacts may be normally open or normally closed. Note the need to use identifiers such as X for input components and Y for outputs.

Figure 11

Page 38: Plc Study Meterial

D.J.DUNN 7

A ladder diagram may have many circuits connected between the power busses and hence the diagram resembles a ladder with many rungs. The rungs must be numbered. The same elements may appear in several rungs. Logic functions such as AND, OR, NAND and so on are created by using parallel and serial branches. Latches may be created and outputs can be put in parallel. The words shown are usually changed to simple code called MNEMONICS. This is covered in outcome 3. Here is a typical example.

Figure 12

The following symbols show various switches and sensors.

Figure 13

AMERICAN LADDER LOGIC SYMBOLS American symbols seem to be widely used and they do not indicate the form of input and output devices. They simply show the contacts as normally open or normally closed. Output devices are all the same.

Page 39: Plc Study Meterial

D.J.DUNN 8

SELF ASSESSMENT EXERCISE No. 1 The diagram shows a lamp Z that is switched on by a combination of switches A, B, C and D.

Complete the truth table and deduce the digital numbers that will turn the output on. Construct a ladder logic diagram for the circuit.

Figure 14

SOLUTION

Figure 15

Page 40: Plc Study Meterial

D.J.Dunn 1

PROGRAMMABLE LOGIC CONTROLLERS

TUTORIAL – OUTCOME 3 PART 1

This work covers part of outcome 3 of the Edexcel standard module:

UNIT 21799P PROGRAMMABLE LOGIC CONTROLLERS

Outcome 3 is the most demanding of the outcomes and can only be affectively studied with the use of suitable hardware and/or simulation software such as PneusimPro or Bytronics simulation software. An industrial background will also be of great benefit to students. SYLLABUS Methods of programming: ladder and logic diagrams, statement lists, Boolean algebra, function diagrams, BASIC; `C' and Assembler; Graphical Programming language. Advanced function: less than, greater than, Binary to BCD, calculations, PID control Producing and storing text : contact labels, rung labels, programming lists, cross referencing. Testing and debugging: forcing inputs, forcing outputs, changing data, comparing files (tapes, EPROM, disc), displayed error analysis. Associated elements: contacts, coils, timers, counters, override facilities, flip- flops, shift registers, sequences.

Investigates methods of programming PLCs Investigates the range and type of advanced functions of PLCs Describes the advantages of offline programming. Investigates methods of producing and storing text and documentation. Investigates methods of testing and debugging hardware and software. Identify elements associated with the preparation of a PLC programme.

Outcome 3 Programming techniques

Produce and demonstrate a PLC programme of at least 50 instructions for an engineering application.

The work is continued in part 2 where more advanced programming is covered.

Page 41: Plc Study Meterial

D.J.Dunn 2

1. INTRODUCTION Let’s first recall what PLC’s are about. They are used to control automated systems such as manufacturing cells and plant processes. Their origins are in the use of relays to perform automatic functions and the wiring diagrams for these relay logic circuits resembled a ladder. PLCs replace the physical relays with imaginary ones that are part of the programme. They are physically connected to a set of input sensors/switches and control the on/off status of the output contacts. The programme within the PLC determines the way the inputs control the outputs. There are many methods of programming a PLC and this outcome is mainly about these. The basic programming methods are the same for each manufacturer but the PLCs that they manufacture have wide differences in their capabilities and protocols. Each manufacturer produces their own system for programming their PLCs and will often supply the hardware and software to do it. There is no universal programming hardware/software that will allow you to programme any type of PLC, although some progress has been made towards developing a common method. 2. REVISION and SUMMARY OF PROGRAMMING TERMS Tags and Labels and identifiers Tags, labels and identifiers are the names and symbols given to hardware components to identify them in the PLC programme. Flip flops and Darlington Pairs These are methods for converting two data lines into one and vice versa. Flow Charts These are more a programming aid than a method of programming and it is explained later. A flow chart is also known as an Algorithm. Step Functions This is a simpler method of programming where the control action is a set of sequential steps. The programme can be produced as a ladder diagram with the special condition that each rung is activated in sequence and it is then called a STEP LADDER PROGRAMME. PLCs that are specifically designed for step functions are explained later. Function Diagrams This is a system that was produced in France in an effort to produce a standard graphical method that would work with any PLC (so long as the manufacturer designed it to accept the method). It is popularly known as Grafcet. Ladder Logic Diagrams This is a popular method that allows you to produce the logic control circuits as rungs on a ladder as described briefly in Outcome 2. Programmes may be designed on a computer in which the ladder diagram is constructed. It is important to remember that each rung of the ladder is an independent circuit that can be activated at any time and not in any specific order. Statement List This is a more basic and more difficult method. The programme is produced as a series of statements using mnemonics. Most ladder diagrams can be automatically converted into a statement list and vice versa. Advanced Graphics Some manufacturers produce state of the art graphical programmes that allow you to construct a virtual system and simulate it. The programme is automatically generated. Truth Tables and Boolean Algebra These were explained in outcome 2 and more fully later. This is a programming tool rather than a method. Timing Diagrams This is explained later as a useful tool to help produce programmes. Let’s now look at these in more detail.

Page 42: Plc Study Meterial

D.J.Dunn 3

3. TAGS , LABELS and IDENTIFIERS Consider the simple arrangement shown with four input elements connected to the PLC terminals and four output elements.

Figure 1

The input and output terminals and other internal relays used inside a PLC are identified by the manufacturer. For example on the Mitsubishi range of PLCs, input terminals are numbered with an X such as X40, X41 and so on. Output terminals start with a Y (e.g.Y40). Other letters are used for internal functions such as T for timers and C for counters. The input and output devices such as switches, sensors motors and actuators and many other items are more easily recognised with labels and tags such as Start, Stop, Guard, Fill, Conveyor, and so on. When programming the PLC, you have to set up the labels and tags first so that if you allocate Start to terminal X40, then whenever you enter Start, X40 is automatically identified. How this is done depends upon the programming method being used but it makes it easier to programme. Programming software also allows you to add comments with the labels to help you remember what they represent. 4. FLIP FLOPS and DARLINGTON PAIRS Consider the circuit shown.

Figure 2

Page 43: Plc Study Meterial

D.J.Dunn 4

The pneumatic cylinder identifier is A. A Darlington Pair has two outputs connected to the two solenoids. The single input is connected to the PLC terminal and tagged A. If the PLC puts a high signal onto this terminal, the solenoid A+ is switched on and the cylinder extends. If the PLC puts a low signal on the terminal the solenoid A- is energised and the A+ de-energised and the cylinder retracts. In this way only one terminal on the PLC is needed to control the cylinder as either on (high) or off (low). (Note that the same object may be achieved without a Darlington pair by using one solenoid and a spring at the other end). The cylinder has two proximity switches tagged A1 and A0. The problem is that when the piston is between the sensors, neither sensor is activated and this makes programming difficult. Ideally we wish to connect to a single input terminal on the PLC to indicate whether the cylinder is out (on) or in (off). This is done with a FLIP FLOP. A flip flop has two inputs. The status of the output remains unchanged until the other input changes. The status of the feedback signal remains unchanged when the piston is in between the sensors. Hence the single signal line to the PLC is high (on) when the cylinder is out and low (off) when the cylinder is in and does not change status while moving from one to the other.

5. FLOW CHARTS Flow diagrams (also called algorithms) are widely used to explain decision making processes that arrive at a logical answer. They are particularly useful for computer programmers because most programmes can be reduced to a series of YES or NO answers to each decision that must be made. In PLC work they can be a useful tool to help produce a ladder logic diagram. The main symbols for flow diagrams are shown here.

Figure 3

WORKED EXAMPLE No.1 A machine has 2 actuators A and B that must perform the sequence A+(on) B+ (on) B- (off)

A- (off) . Each actuator has a sensors and flip flops so that a single signal indicates when they are on or off. Each actuator is operated by a single on/off signal. Produce a flow chart for the sequence.

Page 44: Plc Study Meterial

D.J.Dunn 5

SOLUTION

Figure 4

Step 1 – When we start we must make sure both actuators are off by switching them off. Step 2 – Start the cycle by switching A on. Step 3 – Check that A is on and if it is not, then keep looping back until it is. Step 4 – When A is on switch on B. Step 4 – Check that B is on and if it is not, then keep looping back until it is. Step 5 – When B is on, switch B off. Step 6 – Check if B is off and if it isn’t keep looping back until it is. Step 7 – When B is off, switch A off. Step 8 – Check if A is off and if it isn’t keep looping back until it is. Step 9 – Loop back to the start.

Page 45: Plc Study Meterial

D.J.Dunn 6

6. STEP CONTROLLERS For a sequence like the one in the last section, the best form of PLC is a dedicated STEP controller. These have input and output terminals in the normal way. They are programmed through a built in panel with programming buttons and a display to show the programme and the state of the inputs and outputs. These conduct the steps one at a time waiting for the correct feedback data before executing the next step. A typical display from a sequential controller is like this.

Figure 5

The display informs us that at step 63 in the programme, OUTPUTS 1 and 4 are already switched ON and before it will advance to step 64, the sensors attached to terminals 11 OR 12 must be activated. The OP numbers are codes for logical commands and in this case OP5 is an OR. Ordinary PLCs can be programmed in this way also if they are designed for it. 7. FUNCTION DIAGRAMS - GRAFCET–SFC Grafcet (Sequential Functional Chart) is a method of programming PLC’s that is gaining in popularity but few PLC manufacturers have produced software to enable it to be done this way. The method is easiest to use with machines that go through a fixed sequence of operations with feed back after the completion of each step to confirm that it has happened (like the previous example) but it is possible to do more advanced things as well. There is an international body that is setting standards so that all PLC will respond in the same way to a programme. A useful website to visit is http://www.lurpa.ens-cachan.fr/grafcet.html. The chart starts with an initial step shown as a doub le box. This is followed by a transition state and here you must enter the tag (PB1) of the input switches that must be activated in order to proceed. In this case PB1 (Push Button 1) must be pressed before you can proceed to step 2. This is followed by the next step (2) and to this is attached an action box. In the action box you enter the tag name for the output element. In this case it switches on actuator B and the tag is B+.

Figure 6 If you want two things to happen together you attach a second action box. At the end of the programme you may loop back to the beginning to complete the sequence. You may also use logic statements such as AND, OR, NAND and so on at the transition points. The next step is not performed until the logical condition is met. This makes it a versatile system. It is also possible to branch and jump to other routines.

Page 46: Plc Study Meterial

D.J.Dunn 7

8. OTHER COMPUTER PROGRAMMING LANGUAGES

Some PLCs may be programmed using computer programming language such as C++. Other programming software allows you to use statements like this:

IF A>B AND B<C THEN SET D ELSE RESET D.

This means if A is larger than B and B is smaller than C then set D otherwise Reset D. Some people might recognise this as similar to basic computer programming language such as BBC Basic and other similar ones used on PCs but now falling into disuse. Elements of this are incorporated in the SFC programming method where statements such as these may be used at the transition state point. PLCs like the Festo/Beck range use this form of programming. WORKED EXAMPLE No.2 Produce a sequential function diagram to control the system shown so that the actuators

perform the following sequence. It starts with everything off (retracted). Closing the push button switch PB1 starts the cycle. Next B goes on (B+) and then when reaching full stroke it goes off again (B-) When B is fully retracted (off) it is switched on again. When B reaches its full stroke for the second time, A is switched on. When A reaches full stroke both cylinders are switched off together and retract together. The cycle stops until PB1 is pushed again. B+ B- B+ A+ (A- B-) simultaneously, If you have access to PneusimPro simulation software, you should construct the circuit and

Grafcet programme using appropriate tags and simulate the result to see if it works.

Figure 7

Page 47: Plc Study Meterial

D.J.Dunn 8

SOLUTION In this kind of circuit it is normal to tag the actuators A, B, C etc. Plus (+) means extend, minus

(-) means retract. These tags are allocated to the solenoids that produce the required action. The sensors are located at the two positions of each cylinder and are tagged A0/B0 for the retracted position and A1/B1 for the extended position and so on for each cylinder.

Figure 8

Page 48: Plc Study Meterial

D.J.Dunn 9

8. LADDER LOGIC DIAGRAMS INPUT AND OUTPUT ELEMENTS This was briefly covered in outcome 2. Here we will revise it and take it further. Each rung of the ladder is an imaginary circuit linking the Plus and Minus bus rails. When the circuit is made, current flows and the output element is on. We shall only use American symbols here. Consider the circuit below. The left diagram shows a motor connected through an open contact. When the contact is closed the motor is switched on. The right circuit shows the motor connected through a closed contact and will normally be on. Operating the switch will disconnect the motor and turn it off.

Figure 9

It is of great importance to note that the normally closed symbol should be regarded as a NOT gate. The actual switch connected to the PLC may be normally open but the PLC programme reverses it and makes it normally closed. It should be seen like this.

Figure 10

Closing A turns the motor off. It can be very confusing working with real normally closed switches as the not gate converts them into normally open. Remember that output elements may be a wide range of things such as heating elements, solenoids, valves and so on. They may also be imaginary relays used for various purposes such as latches and flags. They are commonly tagged with L, M or F. LATCHES On many PLCs, the programming allows you to use an imaginary switch with the same tag as the output. The left circuit below shows that when A is operated the motor comes on and the imaginary contact tagged M will close so that if A is opened again, the motor stays on. Another way to do this is to use another imaginary output (often called internal relay) which carry identifiers such as L for Latch and use them as shown in the right diagram. The origins of this are in the equipment that used actual relays which when turned on, closed a set of contacts connected across the switch so that the switch became latched.

Figure 11

Page 49: Plc Study Meterial

D.J.Dunn 10

The next diagram shows how two normally open switches are used to start and stop a motor. When the start switch is operated, the programme turns the motor and the Latch on. The latch keeps the motor running even when the start switch is released. The stop switch is seen by the programme as a normally closed switch. When operated, the programme breaks the circuit, the motor stops and the latch is broken.

Figure 12

Some PLCs have a function called SET. When an output is set, it stays on no matter what else happens until the command RESET is used. This is simpler than using latches.

LOGIC FUNCTIONS The rungs of the ladder can be designed to produce many logical functions such as AND, OR, NAND, NOR and so on.

Figure 13

MORE ON FLIP FLOPS It is possible to make the PLC perform the flip flop function. On the downside, this means that two PLC input terminals are used per cylinder instead of 1. Consider a cylinder with two proximity detectors A1 and A0 which are both normally open switches. The programme treats A0 as if it were normally closed.

Figure 14

When the cylinder is in between the two positions the contact A1 is open. The circuit is not made and F4 is off. If the cylinder moves out and operates A1, then the circuit is made and F4 is turned on. F4 is latched across A1 so if the piston retracts and A1 becomes disconnected, the circuit is still complete and F4 stays on. When fully retracted, the sensor A0 is activated and breaks the circuit. F4 is then switched off. If the piston moves forward again, F4 remains off until the contact A1 is again

Page 50: Plc Study Meterial

D.J.Dunn 11

closed. In this way the status of the cylinder is indicated by F4. The contact F4 should now be used instead of the contact A in the programme. TIMERS AND COUNTERS The way that timers and counters work varies from one type of PLC to another. The right diagram shows a timer. When switch A is closed, the timer starts running and after 2 seconds (indicated by k2) the timer contact closes and switches on the motor. The right hand diagram shows a counter. The counter is set to 8 (the k8 term). Each time switch A is closed the counter decrements. If the switch is closed and opened repeatedly, after the eighth closure, the counter contact closes and turns on the motor.

Figure 15

There are many variations on this such as counting up rather than down. Once a counter or timer has operated, they need to be reset again before they can be reused. On some PLCs the timer automatically resets when the switch A is opened. The diagrams above show that switch B is used to reset the counter and timer. Reset is an example of a command being used as an output element. TIMING DIAGRAMS Many items of equipment such as traffic lights, may work entirely off timers. In order to help produce a PLC programme a timing diagram is very useful. These are useful when using timers to control a sequence and when the same set of conditions exist more than once in a cycle. WORKED EXAMPLE No.3 Two motors (outputs M1 and M2) are to be controlled as follows. • When the run switch is operated both motors must run. • After 4 minutes motor 1 must stop. • Motor 2 continues running for another 2 minutes and stops. • At this point a lamp is switched on. • After a further 90 seconds, the lamp goes off and the cycle restarts. • If a stop switch is operated at any time, the system will continue to the end of the cycle and then

stop. Produce a PLC programme to make it work.

Page 51: Plc Study Meterial

D.J.Dunn 12

SOLUTION There are many solutions to this problem and this is just one. Timers may run in parallel or

series or both. Here is the timing cycle diagram.

Figure 16

In this solution we shall need 3 timers T1, T2 and T3. T1 and T2 are started together. Timer 1

is set to 4 minutes, timer 2 to 6 minutes. Timer 3 is started after 6 minutes and runs for 90 seconds (1.5 minutes).

There are a wide variety of PLC commands for ladder logic. For example, in the Mitsibushi system timers and counters are automatically reset when the logic which starts them running becomes untrue. In other types such as Bytronics - LADSIM programmes, you need to use a reset command to reset timers and counters.

The following is the solution for a Mitsubishi using MEDOC programming. When the run switch is activated all timers are off. If the cycle is turned into ladder logic, this is the result.

RUNG 1 Timers 1 and 2 are set running by timer 3 being off (i.e. as soon as the run switch is activated). RUNG 2 Motor 1 runs as long as timer 1 is off. After 4 minutes timer 1 comes on and motor 1 stops. RUNG 3 Motor 2 runs as long as timer 2 is off. Timer 2 continues running and after 6 minutes from start it comes on and motor 2 stops. RUNG 4 The lamp is on only if timer 2 is on (Motor 2 stopped) and timer 3 is off. Hence the lamp comes on as soon as motor 2 stops and goes off after 90 seconds when timer 3 comes on. Since timer 3 OFF is in rung 1, timers 1 and 2 are automatically reset and go off causing rung 1 to be reactivated. STOP If the STOP switch is put on, timers 1 and 2 will not reset and the cycle stops at the end.

Figure 17 An alternative for Mitsubishi PLC is to use special relay M77 to interrupt the cycle by disabling

all outputs. This would be activated by the interrupt switch in series with T3 to stop the cycle when the lamp comes off.

Page 52: Plc Study Meterial

D.J.Dunn 13

WORKED EXAMPLE No.4 Components pass along a chute and interrupt a light switch which goes low (off) each time it is

interrupted. Every time 6 components have been counted, an eject operation is used to remove the batch and the then it all starts again. Produce a ladder logic diagram to do this operation. The counter is designated C460.

SOLUTION Again, the solution depends upon the type of PLC and programming facilities. This is a

solution for a Mitsubushi.

Figure 18

EXPLANATION RUNG 1 Each time the light switch is interrupted, the counter is decremented by 1. The counter

is set up for 6 counts (the k6). RUNG 2 When the counter value reaches zero, the counter contact (C460) closes and operates

the eject mechanism. RUNG 3 The eject output is used as an input contact so that each time the eject command is

executed, the counter is reset (R C460). RUNG 4 Most PLCs require an END command as shown to stop it running on into any other

programme fragments left in the memory.

Page 53: Plc Study Meterial

D.J.Dunn 14

9 INSTRUCTION SETS Any of the programmes so far described can be created using statement lists. These use mnemonics to describe the action. The mnemonic is also known as the OPCODE. The OPERAND is the data to be executed by the opcode. For example the mnemonic Ld X400 is an instruction to load something (the opcode) and the something is the status of input X400 (the operand). Here are the mnemonics used by Mitsubishi.

Figure 19

This is the statement list for the last ladder programme.

Figure 20

Instructions sets can use labels and tags in just the same way as ladder diagrams and they can be automatically produced from a ladder diagram.

Page 54: Plc Study Meterial

D.J.Dunn 15

10 TRUTH TABLES This was explained in Outcome 2 but we need to examine them again. A truth table should be considered as a binary number or pattern covering every possible combination of input conditions. Suppose we have four input sensors. We need a table with 4 bits and we will put the most significant bit (MSB) on the left.

Figure 21

The maximum possible value is 15 so there are 16 possible combinations of input conditions. Show each starting with a binary value of 0 and ending with 15. When the truth table has been filled in as shown, you must decide which combinations switch on which outputs.

Figure 22

Suppose there are two outputs A and B and these are only to be switched on as follows. A is on when S3 OR S2 AND S1 is on. B is on when S4 or S1 is on. The truth table below only shows the conditions that switch on A and B. If the outputs are being controlled by a computer, it is useful to know the binary value required to switch the outputs on. The number that switches on A is 2, 3 and 12. The number hat switches on B are 1, 3 and 8.

Figure 23

Page 55: Plc Study Meterial

D.J.Dunn 16

11. BOOLEAN ALGEBRA This was partially covered in outcome 2 but we need to refresh ourselves on the subject. It is a useful tool for writing out and simplifying logic statements in short hand. A plus sign means OR and a dot means AND. Here are the four main logic gates shown as American Logic symbols along with the ladder logic diagram, truth table and Boolean expression. Remember a circle on the symbol at the input or output is a NOT gate and inverts the action.

Figure 24

Here is another example.

Figure 25

Boolean algebra can be used to simplify logic circuits. Consider the following circuit.

Figure 26

Page 56: Plc Study Meterial

D.J.Dunn 17

The output may be simplified first by removing the square brackets which makes no difference to the result. Z= (A.C) + (A.D) + (B.C) + (B.D) Next take out common A and B Z = A. (C + D) + B. (C + D) Next form a new bracket Z = (A + B) . (C + D) Now redraw the circuit.

Figure 27

SELF ASSESSMENT EXERCISE A machine is switched on by either of two push buttons A or B. There is a safety barrier on the

machine with a limit switch D at the closed position. In addition there is proximity switch C to detect if anyone is standing inside the barrier. If there is the machine must not start. All have normally open contacts.

• Write out a suitable Boolean expression. • Draw a ladder logic diagram for the Boolean expression • Write out the instruction set. • Construct the truth Table.

Page 57: Plc Study Meterial

D.J.Dunn 18

ANSWERS

Z = (A + B) . C . D

Ld A Or B Ani C And D

Page 58: Plc Study Meterial

PROGRAMMABLE LOGIC CONTROLLERS

TUTORIAL – OUTCOME 3 PART 2

This work covers part of outcome 3 of the Edexcel standard module:

UNIT 21799P PROGRAMMABLE LOGIC CONTROLLERS

Outcome 3 is the most demanding of the outcomes and can only be affectively studied with the use of suitable hardware and/or simulation software such as PneusimPro or Bytronics simulation software. An industrial background will also be of great benefit to students. SYLLABUS Methods of programming: ladder and logic diagrams, statement lists, Boolean algebra, function diagrams, BASIC; `C' and Assembler; Graphical Programming language. Advanced function: less than, greater than, Binary to BCD, calculations, PID control Producing and storing text : contact labels, rung labels, programming lists, cross referencing. Testing and debugging: forcing inputs, forcing outputs, changing data, comparing files (tapes, EPROM, disc), displayed error analysis. Associated elements: contacts, coils, timers, counters, override facilities, flip- flops, shift registers, sequences.

Investigates methods of programming PLCs Investigates the range and type of advanced functions of PLCs Describes the advantages of offline programming. Investigates methods of producing and storing text and documentation. Investigates methods of testing and debugging hardware and software. Identify elements associated with the preparation of a PLC programme.

Outcome 3 Programming techniques

Produce and demonstrate a PLC programme of at least 50 instructions for an engineering application.

The following work is based around the Mitsubishi PLC functions and the Medoc programming software. It can be adapted for similar PLCs. Some information on programming the FX series is contained in assignment 3.

Page 59: Plc Study Meterial

TESTING AND DEBUGGING The diagram illustrates the layout of a typical PLC. The Light Emitting Diodes are a useful feature to help monitor and debug the programme. The input terminals have a bank of switches attached to it to enable each to be set high or low. These are normally available as standard for simulation, testing and debugging.

The main monitoring and debugging tools are in the software used to programme the PLC. If the PLC is connected to the computer with a suitable interface, the programmes may be moved either way between the PC and the PLC. The Medoc software highlights the parts of the ladder diagram that are active and the status of timers, counters and registers are displayed at the bottom of the screen. The following work is presented as a series of exercises based on the Mitsubishi PLC and Medoc software but it may be adapted to other types. With the Medoc software, you may monitor the PLC as follows. Enter the programme and go into ladder edit mode using F2 and F8. The contents of timers and counters are automatically displayed at the bottom of the screen by pressing the F5 key. You must enter the number of the registers that you wish to monitor e.g. K700 monitors data register D700. Press F8 to resume monitoring. Remember that the run switch on the PLC must be closed before anything takes affect.

Page 60: Plc Study Meterial

EXERCISE No.1 - TIMERS On completion of this exercise you should be able to programme a simple timer sequence into a PLC. You will need a Mitsubishi PLC (F20) linked to a P.C. with Medoc software. Numeric Designations T50 to 57 and T 450 to 457 Typical Use Timing a heating process. Consider a machine which has to insert a component into a heat treatment oven for a fixed time and then remove it. Let the timer used be T450 Let the input used to start the timer be X400 Let the output used to start the removal routine be Y430. (Note it might be a jump to a new routine). K is the time delay in seconds. LADDER DIAGRAM INSTRUCTION SET

LD 400 OUT 450 K 6 LD 450 OUT 430 END

EXPLANATION When contact 400 is closed the timer starts running. After K seconds the timer contact closes and switches on output 430. If the input contacts X400 are open, the timer is reset. Enter the above programme into your PLC and test it.

Page 61: Plc Study Meterial

EXERCISE No.2 - COUNTERS On completion of this exercise you should be able to enter simple counter programme into a PLC. You will need a Mitsubishi PLC (F20) and pc with Medoc software. Numeric Designations C 60 to 67 and C 460 to 467 Typical Use Batching Consider a machine which has to inspect a component one at a time, set aside the rejects and stack the good ones in a packing case. Every time K good ones have been stacked, the machine must go into a new routine to pack the components, remove the packing case and then start on a new batch. Let the counter used be C460 Let the input used to reset the counter be X400 Let the input used to count components be X401 Let the output used to start the packaging routine be Y430. (Note it might be a jump to a new routine).

LADDER DIAGRAM LD 400 OUT 460 K 6 LD 460 OUT 430 LD 401 RST 460 END

EXPLANATION When contact 401 is closed the counter is reset to zero. Each time contact 400 is closed the count is decremented by 1. When the counter value reaches zero, the counter contacts close. When the counter contact closes, output 430 is switched on. Enter the above programme into your PLC and test it.

Page 62: Plc Study Meterial

EXERCISE No.3 - REGISTERS INFORMATION ON MITSUBISHI REGISTERS Numeric Designations of registers M100 - 177 general M200 - 277 general M300 - 377 retentive (battery back up) 70 - 77 dedicated 470 - 477 dedicated 570 - 577 dedicated 670 - 677 dedicated D700 to 777 are data registers. • A register may be thought of as a bank of elements (called auxiliary relays) which are on or off.

In our case there are 16 in each bank. Each bank starts with a number ending in zero e.g. M160 and ends with a number ending in 5 e.g. M175.

• Each element may be addressed and used individually and used for flagging operations. These may also be thought of as bits in a binary code.

• If a bank is addressed (e.g. M160) then you cannot address individual elements in it but you can use them as inputs.

• The registers in the range D700 - D777 are data registers for numeric operations in advanced programming (F20 only, not F12).

• A register may be reset with the RST command. This sets the first element on or high. • A register may be shifted using the SFT command. This moves the pattern of high and low

settings along one element. On completion of this exercise you should be able to do the following. • Programme a register into a PLC and shift the register. • Monitor the contents of the register. • Decrement a register. • Increment a register. • Shift a register. • Understand how a pattern represents a 3 digit binary decimal coded number BCD). PART 1 SHIFTING AN AUXILIARY REGISTER Enter the programme into your PLC using Medoc software and test it. It will be used to demonstrate a register shifting.

LD 401 OUT 160 LD 402 SFT 160 LD 403 RST 160 LOAD 160 OUT 430 LD 161 OUT 431 LD 162 OUT 432 and so on to LD 167 OUT 437 END

Page 63: Plc Study Meterial

EXPLANATION When input X401 is on the bank of auxiliary relays M160 to M175 are recognised as a register and bit 0 (M160) is set high. Each time input X402 is pulsed, the bit is moved along to M161, M162 and so on. Each individual bit is used to turn on a corresponding output in order to indicate its status. For example if bit M165 is high, then output Y435 is turned on. Switch on X401 and output 430 should light up. Each time input X402 is pulsed the bit moves along and the next output light ups. When input X403 is pulsed, the register is reset. If X401 is off a low is loaded into M160. If a shift is performed, the low (light off) is carried along with each shift. By switching X401 on or off and shifting, it is possible to arrange any pattern on the register. When you are satisfied that your programme works, produce a binary pattern on the 6 outputs to represent a decimal number of 375

Page 64: Plc Study Meterial

PART 2 PERFORMING OPERATIONS ON A DATA REGISTER POKING

The next programme pokes numbers direct to a register. Enter the programme into the PLC using Medoc software. Note that data registers are designated by the letter K in the programming. X400 activates the programme. 300 is the first number to be stored and it is stored in data register 710. F670 K33 performs the operation. 180 is the second number to be stored and it is stored in data register 720. Transfer the programme into the PLC and run it. Monitor the data registers and note that the numbers 300 and 180 are stored in the appropriate register.

SUBTRACTING Add the following programme to the last. When X401 is activated the contents of register 720 is subtracted from the contents of register 710 and the result is placed in register 730. F671 K710 defines the first data register as D710 F672 K720 defines the second data register as D720. F670 K68 subtracts one from the other places the result in D730.

Enter the above programme and monitor the contents of the data registers. You should see the result of the subtraction in register K730. DIVIDING

If the command F670 K83 is used, register 710 is divided by register 720 and displayed in register 730. Change your programme and demonstrate that you can divide say 770 by 11 and display the result. INCREMENTING AND DECREMENTING

Add the following programme to the existing one and monitor all three data registers in use. Switch off X400 so that it does not overwrite the contents of K710. Each time X402 is pulsed, the contents of register 710 are increased by 1 and the changed result of the subtraction should be seen. The instruction F670 K72 does this. Each time X403 is pulsed, the contents of register 710 are reduced by 1 and the changed result of the subtraction should be seen. The instruction F670 K73 does this.

Page 65: Plc Study Meterial

EXERCISE No.4 - ANALOGUE/DIGITAL CONTROL On completion of this exercise you should be able to do the following.

• Interface an A/D and D/A module to the Mitsubishi PLC. • Read an analogue signal into a data register and monitor it. • Write to an analogue port and monitor the output.

In order to complete this assignment you must

• Read the notes and manuals for the Mitsubishi PLC. • Read the manuals for programming the PLC with a keyboard. • Read the manual for the Medoc software. • Read your notes and text books on A/D and D/A conversion. • Read the RS data sheet on the I/O module.

It is advised that MEDOC programming be used. The following information should be read carefully before attempting to programme the PLC. The I/O module is connected to the PLC by a ribbon cable to the socket numbered 400. The module contains 4 input ports numbered 410, 411, 412 and 413. It also contains two output ports numbered 400 and 401. The ports may be configured with dip switches to use 0 -5 V, 0 -10V, 0 -20 mA or 4 - 20 mA. For this assignment they should be configured for 0 - 10V. There are 64 data registers starting at address 700 (octal). In medoc programming they are prefixed with a K and they must have an address ending with a zero (e.g. 720 but not 721). This function is only available on the types F1 20 and F1 12 made after Sept 1988. Check the serial number. Data may be placed in these registers from timers, counters, analogue inputs or from the programme. They may be manipulated (incremented, decremented, added, subtracted, divided and so on). The manipulated data may be placed back to the counter, timer, analogue output etc. The commands to specify the manipulation are carried out with an instruction F670 followed by a K value to specify the type of manipulation. Data to be used in the command is entered with F671, F672 and so on followed by a K number to specify the data or its address. For each rung with an F670 command, you must store the data in F671, F672 and so on. These may be used several times in a programme but only once in each ladder rung with an F670 command. Load the complete programme from exercise 3. Add the following routines to demonstrate use of the A/D and D/A module.

Page 66: Plc Study Meterial

PART 1. READ ANALOGUE INPUT AND PLACE IN REGISTER. The following routine is used to read an analogue signal and place the digital data into a data register.

X404 is used to activate the operation. F671 K410 is the functional instruction to prepare analogue port 410. F672 K710 is the functional instruction to place the data in data register D710. F670 K85 is the functional instruction to carry out the operation.

Enter the above routine. Switch off X400 so that it does not overwrite the contents of K710. Connect analogue port 410 to a 0-10V source and monitor the digital value in register 710 using F8 F5 online monitoring. Note that the subtraction routine from the last worksheet still works. PART 2. WRITES TO ANALOGUE OUTPUT PORT. The following routine takes data from a data register and places it to the analogue output port.

F671 K730 defines data register D712 as the source. F672 K400 defines output channel 400 for the analogue data. F670 K86 performs the operation.

Add the programme above and monitor the output of the port with a voltmeter or ammeter. Change the contents of K710 by changing the analogue input. Note that this changes the result of subtraction in K730 and so the analogue output changes as the contents of K730 changes. Also increment and decrement K710 and note that you can make the analogue output go up or down. THE MITSUBISHI FX SERIES PROGRAMMES The following shows how to do the above the exercise with the FX series. READ FROM A/D PORT This routine reads the analogue input port. The result is represented by a number in the range 0 – 254 and it is placed in register designated D0.

WRITE TO A/D PORT This routine takes the digital information in D0 and places it as an analogue signal on the Analogue output port.

Page 67: Plc Study Meterial

P.I.D. and PLC PROGRAMMING To understand this topic you need to study the stand alone tutorial on 3 term control. It is a major topic and it s doubtful that the module designers intended you to study the topic. Briefly, when a PLC is used to control a system such as an electric motor, the system error is reduced by using 3 term control. The three terms are Proportional, Integral and Derivative so it is referred to as P.I.D. control. Analogue systems have controllers that provide this function. Usually you must set three constants to optimise the system performance. Many systems are controlled with a PLC using analogue/digital conversion. The signals are digitally processed. Some types of PLC's have a programming command to calculate the incremental change in the following.

• The change in the error. • The change in the time integral of the error. • The change in the rate of change of the error.

Each of these are multiplied by a constant and the result is added to the previous value. The PLC is programmed with the three constants. Typically this command to invoke the processing is PIDINC. Often the sampling period is part of the command. The error is found by subtracting the output signal from the input signal (this being the correct value). If these are analogue signals they must be converted into digital form. These values would be read into the PLC and stored. This would be repeated at intervals of T seconds. Three successive samples would be stored and then updated every T seconds. The numerical processing is carried out. A further command to add the incremental change to the last value must also be used and the resulting value placed out on the I/O module as an analogue signal. A typical ladder diagram would contain the sub-routine shown below to do this. The exact diagram will depend upon the type of PLC used.

Page 68: Plc Study Meterial

D.J.DUNN 1

THREE TERM (PID) CONTROL The following is a stand alone tutorial to explain the meaning of P.I.D. or 3 Term control used in analogue and digital control systems. P.I.D. stands for Proportional, Integral and Derivative. It is difficult to understand this feature on a PLC unless you are familiar with control theory. Here is an attempt to explain it briefly using the control of the speed of an electric motor as an example. Here is a block diagram of a control system for an electric motor. The PID element will be in the signal processor.

Figure 1

The idea is to make the output speed Y the same as the input X at all times. The input would be from some kind of calibrated instrument producing the setting as a voltage. The output speed would be converted into a voltage by some form of transducer but this is not shown to keep it simple. If we change the value of X or some external disturbance causes Y to change, we get an error. The error is determined by the comparer or error detector. This works by subtracting Y from X so the error is:

E =X – Y. This is called NEGATIVE FEEDBACK. The error is then processed by the processor. For the moment treat this as an amplifier with a gain of K. The signal from the processor is K E and this is added to the input with an adder. The input to the power amplifier is X + K E. The power amplifier converts this signal into electric power that drives the motor. The power amplifier should be powerful enough to cope with all requirements. Suppose for some reason there is an error so that the motor is running slower than that selected. The input to the system will increase by an amount K E so the motor will speed up again until E = 0 and we have restored balance. If the motor is running too fast, E is negative and the input to the system is reduced and it slows down until balance is restored. Let us consider the importance of the PROCESSOR. We have just treated it as an amplifier with a gain of K. In fact this is the P.I.D. unit and processes the signal in three ways, Proportional, Integral and Derivative. This is how it works. PROPORTIONAL CONTROL If the processor is a simple amplifier with proportional gain then the output signal is K1 E

K1 is the constant of proportionality but in fact it is the gain of the amplifier. The larger the value of this gain, the faster the motor will respond to any error. If this gain is too high, the motor can become unstable and speed up too quickly to stop in time at the right speed. This is called OVERSHOOT. It can also work the other way when slowing down (UNDERSHOOT). In the worst case the speed continuously goes up and down and doesn’t settle at the correct value. This is known as HUNTING. We aim for the maximum gain without producing ill affects.

Page 69: Plc Study Meterial

D.J.DUNN 2

Figure 2

INTEGRAL CONTROL This is used to get rid of OFFSET ERROR. Typically this occurs when the output settles at the wrong speed. This could be due to stiction in the system, small errors in the transducers and most likely in the case of a motor, excessive load slowing it down. If this happens we need to make the input to the system even larger to produce more power to the motor.

Figure 3

Integral control action increases the power with time such that the output is ∫ dt Ek 2

Figure 4

K2 is the integral constant. So long as an error exists, the output will grow with time. In this way the power signal will build up until the motor speed is back to its normal level. The power signal will build up until it is big enough to overcome the stiction or load and so totally eliminate the error. Of course there is a limit to which any thing can grow and the system should be designed to have a suitable limit. The use of integral control brings in a new problem, an increase in the tendency to overshoot, especially when the system has a large proportional constant. This is solved by using derivative action also.

Page 70: Plc Study Meterial

D.J.DUNN 3

DERIVATIVE CONTROL

Figure 5

Ideally we wish an error to be corrected as quickly as possible with no overshoot. To do this we need to have maximum gain at the beginning of the correction and then reduce the gain as the error approaches zero. This is achieved with derivative control. With derivative control the output of the processor is:

K3 dE/dt

The signal is proportional to the rate of change of the error and K3 is the derivative constant. It follows that at the start of the change dE/dt is greatest. At this point the power will be at its greatest value. As the error is reduced, dE/dt gets smaller and the motor is decelerated. With ideal derivative action, the response is as shown below.

Figure 4

3 TERM CONTROL The signal processor may incorporate all three control elements and it then becomes a Three Term Controller.

Figure 5

The three terms used by the controller are Proportional, Integral and Derivative. For this reason it is also called P.I.D. control. In order to obtain optimal response for a given system, all three control terms are used and the controller produces the following action.

Output = K1 E + K2 ∫ E dt + K3 dE/dt

Page 71: Plc Study Meterial

D.J.DUNN 4

This is called 3 Term control or PID control. In analogue systems the control unit will have the facility to adjust K1, K2 and K3 in order to obtain optimal settings for the given system. This is often called TUNING.

Page 72: Plc Study Meterial

D.J.DUNN 5

DIGITAL P.I.D CONTROL Consider the complete block diagram below. It shows how an electric motor might be controlled with a programmable Logic Controller.

Figure 6

The input to the system is a voltage in the range 0 – 10 V generated by a potentiometer. The output speed of the motor is also in the range 0 – 10 V generated by a tachometer. Both signals are converted into digital form with A/D converters and read into the PLC registers. The negative feed back is then achieved with a subtraction routine and the error resulting is digitally processed with P.I.D. The result is added to the original input and converted back into an analogue signal and fed out to the power amplifier. For those studying the PLC, we need to know how the P.I.D. action is achieved. Not many PLCs have the facility to conduct P.I.D. control but those that do have special commands to invoke the action. In its simplest form, it involves increasing or decreasing the value of the number stored in the register. A programming command such as PIDINC causes the processing to take place on the number stored. The following description is of an INCREMENTAL P.I.D. CONTROLLER which is a numerical method. NUMERICAL PROCESSING The processing is based on digitally sampling the error at regular time intervals of T seconds. From this we can deduce the following. The incremental change in the error for proportional control. The incremental change in the time integral for integral control. The incremental change in the rate of change of error for derivative control. Let the most recent sample be the nth sample. The one before that was n-1 and before that n-2.

Figure 7

Page 73: Plc Study Meterial

D.J.DUNN 6

PROPORTIONAL Let the error be x (it was E previously) and this is multiplied by the proportional constant k1 to give the output of the processor Qn. Qn = k1 xn. The output of the previous sample would be would be Qn-1 = k1 xn-1 The incremental change in the processor output is then the difference between the two values.

∆Q = k1 xn - k1 xn-1 = k1(xn - xn-1) INTEGRAL Consider the time – error graph as made up of thin strips of width T. The time integral of the error over time T seconds is the shaded part of the graph. The incremental output is obtained by multiplying this by the integral constant k2 so:

∆Q = k2T xn

Figure 8

DERIVATIVE In this we need to determine the incremental change in rate of change of the error so we need three samples to give us two successive rates of change. We calculate the rate of change between two adjacent samples by taking the change and dividing by the time taken. The rate of change between the sample n and sample n-1 is (xn - xn-1)/T The rate of change between the samples n-1 and n-2 is (xn-1 - xn-2)/T The difference between these two results is the incremental change (xn - xn-1)/T - (xn-1 - xn-2)/T To find the incremental change ∆Q we must multiply this by derivative constant k3.

∆Q = k3 [(xn - xn-1)/T - (xn-1 - xn-2)/T] ∆Q = k3 [(xn - xn-1) - (xn-1 - xn-2)]/T ∆Q = k3 [(xn - xn-1 - xn-1 + xn-2)]/T ∆Q = k3 [(xn - 2xn-1 + xn-2)]/T

Page 74: Plc Study Meterial

D.J.DUNN 7

3 TERMS For all three control terms, the incremental change to the output is

∆Q = k1(xn - xn-1) + k2T xn + k3 [(xn - 2xn-1 + xn-2)]/T This value may be computed and then added to the previous value to give the new output Q. Hence

Qn = Qn-1 + k1(xn - xn-1) + k2T xn + k3 [(xn - 2xn-1 + xn-2)]/T

This is the signal that is added to the original input and then put out to the A/D converter and the power amplifier. NOTE ON TYPES OF CONTROL SYSTEMS Note that in many control systems, we do not add the input to the processed error. In the case of systems such as an electric motors, we cannot drive the motor from the error alone because when there is no error, there will be no power. In position control systems (e.g. robots, satellite dishes and machine tools), when the actuators are in the correct position, we need no power to keep it there so we drive the system from the error alone. If there is any error power is provided to reduce it back to zero. PLC PROGRAMMING Some PLC's have a CPU operation to calculate the incremental change. Typically this command is PIDINC. The sampling time may be set also by adding the sampling time or rate to the PIDINC command. A typical system would have an analogue/digital I/O module. The set value and output values would be typically analogue (but could be digital). These values would be read into the PLC and stored. This would be repeated at intervals of T seconds. Three samples would be stored and then updated with each sample. The numerical operation as detailed previously is carried out. A further command to add the incremental change to the last value must also be used and the resulting value placed out on the I/O module as an analogue signal. A typical ladder diagram would contain the sub-routine shown below to do this. The exact diagram will depend upon the type of PLC used.