programmable logic controller.docx

21
Programmable Logic Controller (PLC) Lecture # 01 Basic Training Workshop Training on MITIBUSHI Instructor: Ejaz Ahmed Contact No. 0346-4432732

Upload: muhammadfaisal32717

Post on 20-Feb-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programmable Logic Controller.docx

Programmable Logic Controller (PLC)Lecture # 01

Basic Training WorkshopTraining on MITIBUSHI

Instructor: Ejaz AhmedContact No. 0346-4432732

Page 2: Programmable Logic Controller.docx

Q. What is PLC?Ans:

“PLC is a programmable logic controller (PLCs), also referred as Programmable Controllers, and is in the computer family. They are used in

commercial and industrial applications. A PLC monitors inputs, makes decisions based on its program, and controls outputs to automate a process

or machine.”

Or

“Programmable logic Controller is a hardware control system by using programming.”

Basic PLC Operation

PLCs consist of input modules or points, a Central Processing Unit (CPU), and output modules or points. An input accepts a variety of digital or analog signals from various field devices (Sensors) and converts them into a logic signal that can be used by the CPU. The CPU makes decisions and executes control instructions based on program instructions in memory. Output modules convert control instructions from CPU into a digital or analog signal that can be used to control various field devices (actuators). A programming device is used the desired instructions. These instructions determine what the PLC will do for a specific input. An operator interface device allows process information to be displayed and new control parameters to be entered.

Input Modul

e

CPU

Central Processing Unit

Output Modul

e

Programming device

Operator Interface

Page 3: Programmable Logic Controller.docx

Pushbuttons (Sensors), in this simple example, connected to PLC inputs, can be used to start and stop a motor connected to PLC through a motor starter (actuator).

Hared Wired Control

Prior to PLCs, many of these controls tasks were solved with contractor or relay controls. This is often referred to as Hard-wired control. Circuit diagram had to be designed, electrical components specified and installed, and wiring lists created. Electricians would then wire the components necessary to perform a specific task. If an error was made the wires had to be reconnected correctly. A change in function or system expansion required extensive component changes and rewiring.

Hard-Wire Control

Page 4: Programmable Logic Controller.docx

PLCs

The same, as well as more complex tasks can be done with a PLC. Wiring between devices and relay contacts is done in the PLC program. Hard wiring, though still required to connect field devices, is less intensive, modifying the application and correcting errors are easier to handle. It is easier to create and change a program in a PLC than it is to wire and rewire a circuit.

ADVANTAGES OF THE PLC

The following are some of the major advantages of using a programmable controller:

Flexibility

In the past, each different electronically controlled production machine required its own controller; 15 machines might require 15 different controllers. Now, it is possible to use just one model of PLC to run any one of the 15 machines. Furthermore, you would probably need fewer than 15 controllers, because one PLC can easily run many machines. Each of the 15 machines under PLC control would have its own distinct program.

Implementing Changes and Correcting Errors

With a wired relay panel, any program alterations required time for rewiring of panels and devices. When a PLC program circuit or sequence design change is mad, the PLC program can be changed from a keyboard sequence in a matter of minutes. No rewiring is required for a PLC-controlled system. Also, if a programming error has to be corrected in a PLC control ladder diagram, a change can be typed in quickly.

Large Quantities of Contacts

The PLC has a large number of contacts for each coil available in its programming. Suppose that a panel-wired relay has four contacts and all are in use when a design change requiring three more contacts is made. It would mean that time must be taken to.

Simplicity of Ordering Control System Components

A PLC is one device with one delivery date. When the PLC arrives, all the counters, relays and other components also arrive. In designing a relay panel, on the other hand, you may have dozens of different relays and timers from dozen different suppliers.

Page 5: Programmable Logic Controller.docx

Documentation

An immediate printout of the true PLC Circuit is available in minutes, if required. There is no need to look for the blueprint of the circuit and remote files. The PLC Prints out the actual circuit in operation at a given moment. Often, the file prints for relay panels are not properly kept up to date. A PLC printout is the circuit at the present time; no wire tracing is needed for verification.

Security

A PLC program change cannot be made unless the PLC is properly unlocked and programmed. Relay panels tend to undergo undocumented changes. People on late shifts don`t always record panel alternation made when the office area is locked up for the night.

Ease of Changes by Reprogramming

Since the PLC can be reprogrammed quickly, mixed production processing can be accomplished. For example, if part B comes down the assembly line while part A is still being processed, a program for part B`s processing can be reprogrammed into the production machinery in a matter of seconds.

These are some of the advantages of using a Programmable Logic Controller. There will, of course, be other advantages in individual applications and industries.

DISADVANTAGES OF THE PLC

Following are some of the disadvantages of, or perhaps precaution for, using PLCs:

Newer Technology

It is difficult to change some personnel`s thinking from ladder and relays to PLC computer concepts.

Fixed Program/Circuit Operations

If some applications and circuits are single function. It doesn`t pay to use a PLC that includes multiple programming capabilities if they are not needed. The PLC is most effective when periodic changes in operation are made.

Environmental Consideration

Page 6: Programmable Logic Controller.docx

Certain process environments, such as high heat and vibration, interfere with the electronic devices in PLCs, which limits their use.

Number SystemsSince a PLC is a computer, it stores information in the form of On or Off conditions (1 or 0), referred to as binary digits (bits). Sometimes binary digits are used individually and sometimes they are used to represent numerical values.

Decimal System

Various number systems are used by PLCs. All number systems have the same three characteristics: digits, base, weight. The decimal system, which is commonly used in everyday life, has the following characteristics:

Ten Digits: 0,1,2,3,4,5,6,7,8,9

Base: 10

Weights: 1, 10, 100, 1000 . . .

Binary System

The binary system is used by programmable controllers. The binary system has the following characteristics:

Ten Digits: 0, 1

Base: 2

Weights: Powers of base 2 (1, 2, 4, 8, 16, . . )

Page 7: Programmable Logic Controller.docx

In the binary system 1s and 0s are arranged into columns. Each column is weighted. The first column has a binary weight of 2o. This is equivalent to a decimal 1. This is referred to as the least significant bit. The binary weight is doubled with each succeeding column. The next column, for example, has a weight of 21, which is equivalent to a decimal 2. The decimal value is doubles in each successive column. The number in the far left hand column is referred to as the most significant bit. In this example, the most significant bit. In this example, the most significant bit has a binary weight of 27. This is equivalent to a decimal 128.

Most Significant Bit

27

128

Converting Binary to Decimal

The following steps can be used to interpret a decimal number from a binary value.

1) Search from left to right (least significant to most significant bit) for 1s.2) Write down the decimal representation of each column containing 1.3) Add the column values

In the following example, the fourth and fifth columns from right contain a 1. The decimal value of the forth column from the right is 8, and the decimal value of the fifth column from the right is 16. The decimal equivalent of this binary number is 24. The sum of all the weighted columns that contain a 1 is the decimal number that the PLC has stored.

0 0 0 1 1 0 0 0

0 0 0 1 1 0 0 0

128 64 32 16 8 4 2 1

8

+16

24

Page 8: Programmable Logic Controller.docx

In the following example the fourth and sixth column from the right contain a 1. The decimal value of the fourth column from the right is 8, and decimal value of the sixth column from right is 32. The decimal equivalent of this binary number is 40.

Bits, Bytes & Words

Each binary piece of data is a bit. Eight bits make up one byte. Two bytes, or 16 bits, make up one word.

Logic 0, Logic 1

Programmable controllers can easily

0 0 1 0 1 0 0 0

128 64 32 16 8 4 2 1

8

+32

40

0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0

Bit

Page 9: Programmable Logic Controller.docx

What are microcontrollers and what are they for?

As with everything that is good, this powerful component is actually very simple in its essence. It was built using the tested solutions and ingredients by the following recipe:

1. Processor was removed from the simplest of computers to be used as the "brain" for the upcoming system.

2. Depending on the manufacturers' taste, some memory was added, a few A/D converters, timers, I/O communication lines, etc.

3. It was all placed in a standard casing.4. Simple software that everybody could learn was developed for

controlling the thing.

A variety of microcontrollers has been constructed in this manner, becoming a man's subtle yet indispensable companion in everyday life. Their incredible simplicity and flexibility has earned our trust awhile ago - if you have an idea of utilizing a microcontroller for the most trivial of tasks, know that somebody has already been there...

There are three decisive facts responsible for such a success of microcontrollers:

Their powerful, cleverly chosen electronics is able to control a variety of processes and devices (industrial automatics, voltage, temperature, engines, etc) independently or by means of I/O instruments such as switches, buttons, sensors, LCD screens, relays...

Their low cost makes them suitable for installing in places which attracted no such interest in the past. This is the fact accountable for today's market being swamped with cheap automatons and "intelligent" toys.

Writing and loading a program into microcontroller requires practically no previous schooling. All that is required is: any PC (software is very friendly and intuitive) and one simple device (programmer) for loading a written program into microcontroller.

So if you are into electronics, you will undoubtedly want to master the great potential of microcontrollers and put it to good use.

Microcontrollers versus Microprocessors

Microcontroller differs from a microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and

Page 10: Programmable Logic Controller.docx

sending data must be added to it. In short that means that microprocessor is the very heart of the computer. On the other hand, microcontroller is designed to be all of that in one. No other external components are needed for its application because all necessary peripherals are already built into it. Thus, we save the time and space needed to construct devices.

How does microcontroller work

Although there are plenty of different microcontrollers and programs available, they all share a lot in common between them. This means that if you master one model, you will be able to handle them all eventually.

Typical scenario goes something like this:

1. Power is off and all is still... Program is loaded, everything is set, with no indications of what is about to take place...

2. As soon as the power is on, it all happens too quickly to follow! First one to register the change is the control logic. It halts all the circuits except the quartz oscillator. First few milliseconds pass in hurried preparations and loading of parasitic capacitances...

3. As voltage reaches its maximum, oscillator frequency stabilizes. SFR registers are loaded with bits indicating the states of the subsystems, and all the pins are designated as input. Impulse sequence starts

Page 11: Programmable Logic Controller.docx

dictating the pace and the electronics is now fully operational. From this point on, time is measured in microseconds and nanoseconds.

4. Program counter is reset to zero address of the program memory. Instruction is sent from this address to the instruction decoder where it is interpreted and executed promptly.

5. Program counter is incremented by one as the whole process plays out again... (several millions of times per second)

Obviously, it all works at tremendous speeds, and is also pretty simple. But it would not be especially useful if it was not for additional systems which round out the MCU:

Read Only Memory (ROM)

ROM is the memory which stores the program to be executed. Apparently, its size dictates the maximal program length. It can be internal or external with respect to the microcontroller. Both options have their pros and cons; external memory chip makes the microcontroller cheaper and allows for longer programs. At the same time, number of available free pins is reduced as external ROM uses MCU's I/O ports. Internal ROM is usually smaller and more costly but it provides more possibilities for connecting to the outside world. ROM spans from 512 bytes to 64kB, which is an equivalent to the number of possible program instructions.

Page 12: Programmable Logic Controller.docx

Random Access Memory (RAM)

RAM is used for temporary storage of data during runtime. RAM memory does not retain its stored information when the power is interrupted. RAM spans from tens of bytes to several kilobytes.

EEPROM Memory

EEPROM is a special kind of memory not available with all MCUs. Its contents can be changed during runtime (as with RAM), but is also saved after the power is off (as with ROM).

SFR Registers

Special Function Registers are special elements of RAM, their purpose predefined by the manufacturer. Each of these registers is named and controls a certain subsystem of MCU. For example: by writing zeros and ones to the SFR register which controls an I/O port, each of these pins can be designated as input or output (each register bit corresponds to one of the port pins).

Program Counter

This is the "engine" which starts the program and points to the memory address of the instruction to be executed. Immediately upon its execution, value of counter increments by 1. Due to this automatic increase, program executes one instruction at a time, just the way it was written. However... value of a counter can be changed anytime with a "jump" to a new program memory location as a result. This is how routines and branch instructions are carried out. Upon performing a jump to the specified destination, Program Counter increase carries on steadily, +1, +1, +1...

In case you forgot...

Bit

Bit is the term often found to be confusing by those starting out in electronics. In practice (and in practice only) bit determines if voltage exists between two points of a circuit. If it does, we say that logic level is 1, i.e. bit is 1. If not, logic level is 0, i.e. bit is 0.

Page 13: Programmable Logic Controller.docx

In theory, things are a little bit more complicated - bit actually represents a digit of binary system. As such, it can still have only one of two values - zero or one, set or clear (unlike the decimal system we are used to).

Control Logic

As the name implies, this is the "Big Brother" which supervises and controls every aspect of operations within MCU, and it cannot be manipulated. It comprises several parts, the most important ones including:

Instructions Decoder –

Part of the electronics which "recognizes" different program instructions and directs the other circuits accordingly.

Arithmetical Logical Unit (ALU) –

Is in charge of all mathematical and logical operations over data. Capabilities of this circuit are represented through the so called "instruction set" which is different for every MCU.

Accumulator –

A special SFR register highly interconnected with ALU. It can be described as a working desk for performing operations on data (adding, shifting, etc). Also, this is the register which holds the result of the operation. Of SFR registers, Status Register is specifically associated with the accumulator. It monitors the status of the accumulator's content at all times (is zero, is greater than zero, etc).

In case you forgot...

Byte

Byte is a set of 8 adjacent bits. As bit represents a digit, it is logical to assume that byte represents a number. All standard mathematical operations that can be applied to decimal numbers can be applied to bytes. These are carried out by ALU.

Page 14: Programmable Logic Controller.docx

It is important to note that byte has "two sides", i.e. not all positions are of the same significance. The leftmost bit is the Most Significant Bit (MSb). The rightmost bit is the Least Significant Bit (LSb). As there are 256 possible variations of 8 bits, the greatest decimal number byte can represent is 255 (zero is included!) .

A/D Converter

Another convenient instrument not available with all MCUs. Usually there are several separate channels so that multiple analog values can be measured simultaneously. Commonly, converters are 8, 10, or 12-bit and this is sufficient for most tasks.

As shown on the image below, A/D conversion (converting analog value to a numeral) starts with changing the bit in the appropriate SFR register. Hence, voltage on input pin is measured (this sampling takes a few microseconds) and stored in another SFR register as a numeral.

In our example, 8-bit A/D converter is used and the default voltage is 5V. This divides the scale in 256 units, with the smallest voltage range that can be represented of 19.53mV (5V / 256 = 19.53mV). On such a "crude" scale, voltage of 2.204V is represented by numeral 113 (113 x 19.53mV = 2.207V).

Converters of higher resolutions (10 and 12-bit) have much finer scales of 1024 or 4096 units, respectively. Using one of these instruments under the same conditions from the previous example would significantly reduce the inaccuracy (as shown on the image below).

Register

Is a byte physically realized as electronic component, and represents a basic memory cell. Beside the 8 bits available to the user, there is also an address part not readily accessible.

ROM and RAM registers are nameless and are usually peers. SFR registers are named (differently with different MCUs) and each has

its role.

When writing a code for MCU in one of the higher programming languages, each register can be given an arbitrary name, which proved to be useful.

I/O Ports

Page 15: Programmable Logic Controller.docx

To be of any practical use, microcontroller needs to be connected to other electronics and to the environs. For this purpose, every MCU has one or more registers (also known as ports) which are connected to the pins on its case. Why I/O? Because every pin can be designated as eiher input or output to suit user's needs.

Oscillator

This is the rhythm section of the miniature orchestra. Stable pace provided by this instrument allows harmonious and synchronous functioning of all other parts of MCU. Commonly, oscillator frequency is stabilized using a quartz-crystal or a ceramic resonator. It can also work without an element for stabilizing frequency (as RC oscillator). Note that instructions are executed at a rate several times slower than the pace dictated by the oscillator. This happens because instructions take several steps to be accomplished (execution period of different instructions may vary on different MCUs). Therefore, if your system uses 20MHz quartz-crystal, execution period of one program instruction will not be 50 ns, but more likely 200, 400 or a "whole" 800 ns.

Timers

Majority of programs utilizes these miniature electronic "stopwatches". Commonly, timers are 8 or 16-bit registers whose value automatically increases upon an impulse. If timer is stimulated by an internal MCU oscillator, it can be used for measuring time between two occurrences (register value at the start of measuring = T1, register value at the end of measuring = T2, elapsed time = T2-T1). If timer is triggered by impulses from an external source, instrument behaves like a counter.

In both cases, filling the register resets the counter and the occurrence is recorded in a particular bit of SFR register (Overflow flag). This makes possible to measure longer time periods. Also, if enabled, this flag can cause an interrupt for breaking the program and carrying out a designated routine (see the image).

Page 16: Programmable Logic Controller.docx

Watchdog Timer

The name itself implies the role of this instrument. It is a timer with input connected to an independent MCU RC oscillator. If Watchdog is enabled, MCU is reset every time it overflows, and the program execution starts anew (much as if the power had just been turned on). The idea is to prevent that from happening by means of special instruction. Whole concept is based upon a fact that every program technically "goes around", i.e. executes within a number of simpler or more complex loops. If, beside the regular instructions, key places in the program were added an instruction for resetting the Watchdog, its safeguard function would pass unnoticed. If, for some reason, (in industrial environment, electrical interference is common) Program Counter "gets stuck" at a memory location with no return, the ever-increasing Watchdog Timer eventually overflows and voila - MCU is reset.

Interrupt

Electronics is generally way faster than physical processes in the environment it controls. Therefore, microcontroller spends most of its time in expecting an occurrence or waiting for tasks to be accomplished. To avoid the repeated checks of input pins and internal registers, interrupt was introduced. It is a signal which breaks the standard order of program execution. In case of an interrupt, MCU comes to a halt, and determines the source of interrupt. If certain action is required, current value of Program Counter is set aside to Stack and the appropriate routine (interrupt routine) is executed.

Page 17: Programmable Logic Controller.docx

Stack is a special part of RAM for storing the current value of Program Counter, so that program could "know" where to pick up after the interrupt routine. It can be multi-leveled, i.e. routines can be executed within other routines.

Power Supply Circuit

Two features of the MCU power supply circuit deserve your attention:

Brown out – this is a potentially dangerous state which occurs during the shutdown or in situations when voltage "oscillates" on the edge of the allowed range due to strong interference. Since microcontroller comprises a number of elements with various voltage ranges, this can cause their uncontrolled behavior. To prevent this from happening, brown out reset circuit is included within MCU. If voltage drops below the specified value for high-voltage elements of MCU, brown out promptly resets the entire electronics.

Reset pin – frequently marked as MCLR (Master Clear Reset) is used for "external" reset of microcontroller by bringing the logical zero or one (depending on the MCU). If not preinstalled, a simple external brown out reset circuit can be connected to this pin.

Memory1. RAM Random Access Memory2. ROM Read Only Memory3. EPROM Erasable Programmable Read Only Memory4. EEPROM Electrical Erasable Programmable Read Only Memory

Page 18: Programmable Logic Controller.docx

Installation of PLC

SINK & SOURCE OPTION

1. SINKWhen a Negative Sign is Present on Sensor, then it is called SINK.