Module 3: Programmable Logic Devices (PLDS) Introduction To Micro-Processors and Micro-Controllers
Module 3: Programmable Logic Devices (PLDS) Introduction To Micro-Processors and Micro-Controllers
Module 3: Programmable Logic Devices (PLDs) Lecture 1 Introduction to Micro-processors and Micro-controllers
1. Introduction
Programmable Logic Devices (PLD) are programmable systems and are generally used in manufacturing automation to perform different control functions, according to the programs written in its memory, using low level languages of commands. There are following three types of PLDs are being employed in mechatronics systems. 1. Microprocessor It is a digital integrated circuit which carries out necessary digital functions to process the information obtained from measurement system. 2. Microcomputer It uses microprocessor as its central processing unit and contains all functions of a computer. 3. Programmable Logic Controller (PLC) It is used to control the operations of electro-mechanical devices especially in tough and hazardous industrial environments. A typical programmable machine has basic three components as shown in Figure 3.1.1: 1. Processor, which processes the information collected from measurement system and takes logical decisions based on the information. Then it sends this information to actuators or output devices. 2. Memory, it stores a. the input data collected from sensors b. the programs to process the information and to take necessary decisions or actions. Program is a set of instructions written for the processor to perform a task. A group of programs is called software.
Page 1 of 36
3. Input/output devices: these are used to communicate with the outside world/operator.
Page 2 of 36
2. Microprocessor
It is a multi-purpose, programmable device that reads binary instructions from a storage device called memory, processes the data according to the instructions, and then provides results as output. In common practice it is also known as CPU (central processing unit). CPU can be referred as complete computational engine on a single chip. First Microcontroller, Intel 4004 was launched in 1971. It was able to process just 4 bits. It started a new era in electronics engineering. Microprocessor chip was one of the important inventions of the 20th century. Table 3.1.1 shows the history of micro-processors.
Table 3.1.1 History of Micro-Processors
Name
Date
No. of Transistors
8080 8088 80286 80386 80486 Pentium Pentium II Pentium III Pentium 4 Pentium 4P
1974 1979 1982 1985 1989 1993 1997 1999 2000 2004
Clock Speed
Millions of Instructions per second(MIPS) 0.64 0.33 1 5 20 100 300 510 1700 7000
Applications of microprocessors are classified primarily in two categories: 1. Reprogrammable Systems : Micro computers 2. Embedded Systems : photocopying machine, Digital camera Microprocessor works or operates in binary digits i.e. 0 and 1, bits. These bits are nothing but electrical voltages in the machine, generally 0 - low voltage level, and 1 high voltage level. A group of bits form a word. In general, the word length is about 8 bits. This is called as a byte. A word with a length of 4 bits is called as a Nibble
Page 3 of 36
Microprocessor processes the commands in binary form to accomplish a task. These are called as instructions. Instructions are generally entered through input devices and can be stored in a storage device called memory.
Figure 3.1.2 and 3.1.3 show the configuration and basic blocks of a microprocessor. The functions of each element are as follows.
Page 4 of 36
1. ALU: ALU stands for Arithmetical Logical Unit. As name indicates it has two parts: a. Arithmetical unit which is responsible for mathematical operations like addition, subtraction, multiplication and division, b. Logical unit which is dedicated to take logical decisions like greater than, less than, equal to, not equal to etc. (Basically AND/OR/NOT Operations) 2. Register Array: Registers are small storage devices that are available to CPU or processors. They act as temporary storage for processing of intermediate data by mathematical or logical operations. 3. Control: This part of CPU is dedicated to coordinate data flow and signal flow through various types of buses i.e. Data Bus, Control Bus, and Address Bus etc. It directs data flow between CPU and storage and I/O devices. 4. Memory: There are two different types of memory segments being used by the CPU. First is the ROM which stands for Read Only Memory while other is R/W which stands for Read and Write Memory or Random Access Memory (RAM). a. ROM: From this memory unit, CPU can only read the stored data. No writing operations can be done in this part of memory. Thus it is used to store the programs that need no alteration or changes like Monitor Program or Keyboard driver etc. b. R/W: As name indicates it is opposite to ROM and used for both reading and writing operations. In general Users program and instruction are stored in this segment of memory unit. 5. Input Devices: Input devices are used to enter input data to microprocessor from Keyboard or from ADC which receives data from sensors/signal conditioning systems. 6. Output Devices: These devices display the results/conclusions coming out from ALUs either in soft copy (Monitor) or in Hard Copy (Printer).
Page 5 of 36
Instruct the program counter to reset to zero. Activate any of the six tri-state buffers (six separate lines). Instruct the ALU what operation to perform. Instruct the test register to latch the ALU's test bits. Activate the RD line. Activate the WR line
3. Microcomputer
Microcomputer is a microprocessor based system. It is a data processing system that employs a microprocessor as its central unit. Based on the input it takes decisions. These decisions are further used to control a system or to actuate an action or operation.
It is a microprocessor-based system. It implements the functions of a computer and a controller on a single chip. Generally microcontroller is programmed for one specific application and it is dedicated to a specific control function. Microcontrollers find applications in automobiles, aircraft, medical electronics and home appliances. They are small in size and can be embedded in an electromechanical system without taking up much space. Thus we can have a system with its functions completely designed into a chip. However microcontrollers have very little user programmable memory. Various types of microcontroller chips available in market are: Motorola 68HC11, Zilog Z8 and Intel MCS51 and 96 series.
Page 7 of 36
1. Number System
Number system is a way of representing the value of any number with respect to a base value. Number System can be classified on the basis of its base. Each number has a unique representation in a number system. Different number systems have different representation of the same number. In general Binary, Octal, Decimal and Hexadecimal Number systems are used in microprocessor programming. Table 3.2.1 shows different numbering systems and their details.
Table 3.2.1 Numbering systems
Base 2 8 10 16
Page 8 of 36
1.1.2
Any number in decimal system can be changed to any other number system by continuously dividing it by base of the required number system and then writing remainders after each step in reverse order. Let us take an example of converting a decimal number 235 to its binary equivalent. Following table shows the conversion process as stated above.
Table 3.2.2 Binary representation of (235)10
2 2 2 2 2 2 2 2
235 117 58 29 14 7 3 1
1 1 0 1 0 1 1 1
Page 9 of 36
1.1.3
Hexadecimal system:
This system is quite extensively used in microprocessor programming. It facilitates much shorter representation of number in comparison with that obtained by using the binary number system. Hexadecimal system has a base of 16 and it is easy to write and remember the numbers and alphabets viz. 0 to 9 and A to F. Table 3.2.3 shows numerals and alphabets used in hexadecimal system for representation of a number.
Table 3.2.3 Numerals and alphabets used in hexadecimal system
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Page 10 of 36
Example: Let us convert the number (235)10 to hexadecimal equivalent. Table 3.2.4 shows the conversion of this decimal number.
Table 3.2.4 Decimal to hexadecimal conversion
Number
Division
Remainder
235
11
14
14
Then by arranging the hexadecimals in reverse order i.e. (EB)16. Thus (235)10 = (EB)16. 1.1.4 Binary coded decimal (BCD) BCD code expresses each digit of a decimal system by its nibble equivalent. It uses 4 bit binary strings to represent the digits 0 to 9. Figure 3.2.1 shows the representation of number 523 as 010100100011 using BCD system. Due its longer representation scheme, it is now rarely used in micro-electronics programming.
Page 11 of 36
Page 12 of 36
Page 13 of 36
3.2 Accumulator
The accumulator is 8-bit register (can store 8 bit data). It is a part of arithmetic/logic unit (ALU). In general, after performing logical or arithmetical operations, result is stored in accumulator. Accumulator is also identified as Register A.
3.3 Flags
ALU of 8085 have five flip flops whose states (set/reset) are determined by the result data of other registers and accumulator. They are called as Zero, Carry, Sign, Parity and Auxiliary-Carry flags. Zero Flag (Z): When an arithmetic operation results in zero, the flip-flop called the Zero flag - which is set to one. Carry flag (CY): After an addition of two numbers, if the sum in the accumulator is larger than eight bits, then the flip-flop uses to indicate a carry called the Carry flag which is set to one. S-Sign (S): It is set to 1, if bit D7 of the result = 1; otherwise reset. D7 is the first digit of a binary number. D7 S D6 Z D5 D4 AC D3 D2 P D1 D0 CY
P-Parity (P): If the result has an even number of 1s, the flag is set to 1; for an odd number of 1s the flag is reset. AC-Auxiliary Carry (AC): In an arithmetic operation, when a carry is generated by digit D3 and passed to digit D4, the AC flag is set. Generally this flag is used internally for Binary Coded Decimals (BCD).
Figure 3.2.2 shows a 8-bit flag register, adjacent to the accumulator. It is not used as a register. Out of eight bit-positions, five positions are used to store the outputs of five flipflops. These flags play an important role in decision-making process of the microprocessor.
Page 14 of 36
4. Programming in 8085
As mentioned in above section, a simple and very effective substitution to binary codes could be use of standard English words to complete any task. For example addition of two numbers can be represented by ADD. Such codes are referred as mnemonic codes and that language is called assembly language. Most of the early processers including 8085, are programmed using mnemonics. However, assembly language codes should be converted into binary one so that microprocessor can identify the instructions given to it. This operation is done by Assembler. In assembly language, instructions are composed of two segments which are as follows: 1. Operation (Op) Code: It depends on which operation is to be performed. For example for OR operation, we have Op Code OR. 2. Operands: Operand is the object on which the required operation is to be done. Generally operations are done on data stored in registers.
Page 15 of 36
4.1.2 Arithmetic:
1. Add: It adds contents of a specified memory location to the data in some register. 2. Decrement: It subtracts 1 from contents of specified location. 3. Compare: It tells whether contents of a register are greater than, less than or same as content of specified memory location.
4.1.3 Logical:
1. AND: Instruction carries out Logical AND operation with the contents of specified memory location and data in some register. Numbers are ANDed bit by bit. 2. OR: Instruction carries out Logical OR operation with the contents of specified memory location and data in some register. Numbers are ORed bit by bit. 3. Logical Shift: Logical shift instruction involves moving a pattern of bits in the register one place to left or right by moving a zero in the end of number.
Page 16 of 36
4.2 Example: Though the basic concept remains same, however the Op codes may be
different for various microprocessors. A program example for 8085 is as follows. 1. Add a 8-bit number 16F to Accumulator 16F 2. Add contents of Register D to Accumulator D 3. Subtract a 8-bit number 32H from Accumulator 32H 4. Subtract contents of Register B from Accumulator 5. Increment the contents of Register D by 1 6. Decrement the contents of Register C by 1 7. Load a 8-bit number 15H in register D D, 15H 8. Copy from Register B to Register C C,B ADI ADD SUI SUB B INR D DCR C MVI MOV
Page 17 of 36
Page 18 of 36
Page 19 of 36
Figure 3.3.1 shows the basic elements of a PLC. It is basically a microproceeor based control system. Microprocessor communicates with the outside world with input/output devives via a circuitry. This circuitry protects the microprocessor and other elements of PLC from the high voltages and currents coming to the PLC. Microprocessor does its basic functions of taking decisions according to the instructions written in the programs which are stored in the memory. PLC scans a set of sensor inputs rapidly and repeatedly. Then it evaluates their logic relationships to defined outputs according to a logic program. At last it sets the outputs according to the programmed logic. Figure 3.3.2 shows an industrial PLC with input and output ports.
3. Programming a PLC:
PLCs are programmed through concept of ladder logic. In general there exists a graphical user interface (GUI) to program a PLC that makes it different from other processers. Ladder logic comprises of two columns. Left column shows input devices like switches, sensors while in output column is at right side which shows actuators like cylinders, motors.
Page 20 of 36
Meanings of symbols used in PLC Program: ][ This instruction is called as examine on or normally opened as input functions or storage bits. If the corresponding memory bit is a 1 then the respective rung will continuously be executed and the corresponding outputs will be energized. Rung is one of the multiple horizontal programming lines in a ladder logic diagram. NOTE: Other factors may also affect rung simultaneously. If the corresponding bit is 0 then the rung will not be executed continuously and outputs will be de-energized. If this instruction is used as input bit, its status should be according to the status of the real world input devices connected to the input table by identical addresses. Addressing Sample: I: 3/1 This indicates address of a sample. I indicates input image table, 3 indicates slot no. 3 of input port and 1 indicates bit three of 3rd slot of input port. ]/[ This instruction is called examine off or normally closed as input functions or storage bits. If the corresponding memory bit is a 1 then the respective rung will continuously be executed and the corresponding outputs will be energized. NOTE: Other factors may also affect this rung simultaneously. If the corresponding bit is 0 this instruction will not allow rung continuously and outputs will be energized. If used as input bit, its status should correspond to the status of the real world input devices tied to the input table by identical addresses. OTE ( ) This is called as output energize. This instruction sets the specified bit when rung continuity is achieved. Under normal operating conditions, if the set bit corresponds to an output device, output device will be energized when rung goes true. Addressing Example O:3/1 O -- output image table 3 -- slot three 1 -- bit one of slot three
Page 21 of 36
OTL -(L)This is called as output latch. This instruction functions similar to output energize except that once a bit is set with OTL, it is latched on. Once an OTL bit has been set ON (1 on the memory) it will remain ON even if the rung condition goes false. The bit must be reset. (U) This is called as output unlatch. This is used to unlatch (reset) a latched bit. Its address must be same as latched one. Timer This is also called as TON. Figure 3.3.3 shows the schematic of a Timer. It is used to turn an output ON or OFF after the timer has been ON for preset time interval. This output instruction begins timing when rung goes true. It waits the specified amount of time (As specified in Preset), keeps track of accumulated intervals which have occurred (ACCUM), and sets DN (Done) bit when ACCUM time equals preset time. As long as rung condition remains true, Timer adjusts its accumulated value to each evaluation until it reaches the preset value. The accumulated value is reset when rung condition go false, regardless of whether timer has timed out. TIME BASE is an amount of time after which accumulator increases its value by 1.
Page 22 of 36
4. Case study
In this segment, we will see how PLCs are incorporated to control various activities in an industry. In this illustration we have a conveyer belt run with two motors at its ends, three different stations to perform various activities like painting of vehicle body or fitting of any component in chassis etc along with two switches to run conveyer. Figure 3.3.4 shows the photograph of a conveyor belt system. The PLC is of Bull 1764 Micrologix 1500 LSP Series C which can be controlled by a Graphical User Interface RS Logic 500 Starter.
Page 23 of 36
To run the conveyer belt with the help of switches As discussed in earlier sections, PLCs are controlled through Ladder Logic. In input section of the ladder, name of the input device must be mentioned on the top of symbol, followed by primary input port. Secondary input port is mentioned just below symbol. In similar way, output symbol should be mentioned with name and output ports as shown in figure 3.3.5.
To control movement of pneumatic devices in an industry with PLCs Figure 3.3.6 shows a program code to control the motion of pneumatic cylinder with a switch.
Page 24 of 36
Page 25 of 36
In indutrial applications, it is required to use various sensors to control the operations of systems and proceses using PLCs. Figure 3.3.7 shows a typical program to operate an electric motor and a pnematic cylinder with the help of some sensors such pneumatic proximity switch. To control a mechatronics system we need to combine various mechanical and electrical input and output devices and to operate them in a sequential manner. Consider a prototype of industrial assembly line with 3 stations as shown in Figure 3.3.4. At first station ST1, the sensor identifies an object (finished product) on the conveyer belt and sends a signal to the controller. Controller processes this information and actuates the electric motor to run the conveyer belt. Second Station ST2: It is allotted for the inspection of the finished product or object. At ST2, conveyer belt stops. In case any fault diagnosed by the inspection system, the product will be taken away by the pneumatic actuators placed at Station 3, ST3.
Page 26 of 36
Page 27 of 36
There are various types of closed loop control systems being used in mechatronics. These are listed as follows. 1. 2. 3. 4. Single Input Single Output (SISO) Multiple Input Single Output (MISO) Multiple Input Multiple Output (MIMO) Single Input Multiple output (SIMO)
For a PID controller, the output can be expressed in terms of input as follows: () = [() +
()
1 ()] 0
(3.4.1)
(3.4.2)
Page 28 of 36
PID controller consists of Proportional, Integrator and Differentiator Controllers which can be understood by considering a first order system SISO whose transfer function can be written as,
() =
Now let us study the Proportional, Integrator and Differentiator Controllers one by one and then adding them together as PID controller.
1+
(3.4.3)
The proportional controller gives an output value that is proportional to the error value with a gain value of Kp. The proportional response can be adjusted by multiplying the error by a constant Kp, called the proportional gain constant (Eq. 3.4.1). Figure 3.4.3 shows the schematic of a proportional controller for a closed loop control system, the transfer function can be written as,
() ()
() ()
= =
1+ 1+ 1+
(3.4.4) .
1
Where =
1+ 1+ . 1+
(3.4.5)
Page 29 of 36
Effect of adding Proportional Controller in the system: On adding a proportional controller in system, Time response of system improves 1 by a factor of 1+ . Also on adding proportional controller, steady state offset arises between desired response and output response as shown in figure 3.4.4.
Without P controller With P Controller
() =
1+
(1 )
(3.4.6)
Page 30 of 36
In an integral controller, the manipulation equals the integral of the error over time, multipled by a gain KI (Eq. 3.4.1). Figure 3.4.5 shows the block diagram of Integral controller empolyed for a SISO system. The closed loop transfer function can be written as,
() ()
(1+) 1+ (1+)
() ()
= =
(3.4.7)
For a Step input, R(s) = 1/s, we get the steady state error as,
+ + 2 (1+)
(3.4.8)
() =
= lim0 . () = 0
(1+)+
(3.4.9) (3.4.10)
Page 31 of 36
Effect of adding Integral Controller in system: The step response of this closed loop system with integral action is shown in figure 3.4.6. The integral term enhances the movement of the process towards desired point. It also eliminates the residual steady-state error that produces with a pure proportional controller. From the transfer function, it is observed that use of integral controller leads to increasing order of closed loop system which may cause instability, slow and oscillatory response. However the system has a major advantage that integral controller produces zero steady state error. The drawbacks of integral controller can be rectified if we use Proportional controller along with Integral one.
Page 32 of 36
A derivative controller uses the derivative of the error instead of the integral. Figure 3.4.7 shows the building blocks of a differential controller. In this closed loop system, the transfer function can be written as,
() ()
() ()
= =
(1+) 1+ (1+)
(3.4.11)
For Step input R(s) = 1/s, the steady state error would be,
1++
(3.4.12)
Effect of adding Differential Controller in system: Derivative controller improves stability of the system and it also improves settling time. Derivative of the error can be calculated by determining slope of the error over time and multiplying this term with derivative gain . Figure 3.4.8 shows the response of a system to unit step Input. It shows an initial jump in the response. This is due to the effect of the derivative controller. Here derivative gain is very high which results in high settling time.
() =
1++
(3.4.13)
Page 33 of 36
After discussing various components of controller following conclusions can be drawn. 1. Proportional Controller improves system response time. It provides high proportional gain which results into very low rise time and thus improves the response system. 2. Integral Controller makes the system steady with error approaches zero. But Integral controller may increase instability of a system and may cause oscillations. However in Proportional system provides very low value of Integral gain resulting in very low amount of oscillations. 3. Derivative controller improves system settling time and also improves stability.
None P PI I
A comparison of systems with no controller, only proportional controller, only Integral controller and both proportional and integral controller can be seen in Figure 3.4.9. It can be seen that the response curve produced by PI controller is better in comparison with that obtained by only P, only I and without any controller. PI controller has the advantages of both the P as well as I controllers. Therefore in general, it is recommended not to employ integral and derivative controllers on their own. They are always to be used in conjunction with a proportional controller.
Page 34 of 36
Page 35 of 36
Detail analysis and study of these controllers is out of the scope of the present course. However readers are advised to read following books for further study: a) PID controllers 2nd ed., by Karl J. Astrom and Tore Hagglund, Research Triangle Park, ISA 1995. b) Structure and synthesis of PID controllers, by Aniruddha Dutta, Ming-Tzu Ho and Shankar P. Bhattacharyya, Springer-Verlag, Londoan 2000. PID controllers have wide variety of applications manufacturing industry. Some of them are listed as follows. 1. PID control is used in automatic car steering when it is integrated with Fuzzy Logic 2. In movement detection system of modern seismometer 3. In water/oil level monitoring in tanks 4. Head positioning of a disk drive 5. Automated inspection and quality control 6. Manufacturing process control: CNC machine tools 7. Chemical process control: flow control, temperature control 8. Automatic control of material handling equipments 9. Automatic packaging and dispatch 10. To ensure safety during manufacturing operations
Page 36 of 36