17ME753 Mechatronics
Module 2: Micro-processors and Micro-controllers
CONTENT:
1. Introduction
2. Microprocessor
3. Microcontroller
4. Basics of microprocessor programming
5. Architecture of Microprocessor
OBJECTIVES:
Is to know the knowledge of microprocessor and its functions.
Is to know the concept of number system with conversion.
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.
17ME753 Mechatronics
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
1 the input data collected from sensors
2 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.
1. Input/output devices: these are used to communicate with the outside
world/operator.
Figure 3.1.1 Components of a programmable logic device
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 Width of Clock Data Millions of
Transistors smallest Speed Width Instructions
wire on (In Bits) per
chip second(MIPS)
8080 1974 6000 6 2MHz 8 0.64
8088 1979 29000 3 5 MHz 16 0.33
80286 1982 134000 1.5 6MHz 16 1
80386 1985 275000 1.5 16 32 5
80486 1989 1200000 1 25 32 20
Pentium 1993 3100000 0.8 60 32 100
Pentium 1997 7500000 0.35 233 32 300
II
Pentium 1999 9500000 0.25 450 32 510
III
Pentium 4 2000 42000000 0.18 1.5 GHz 32 1700
Pentium 2004 125000000 0.09 3.6 GHz 32 7000
4P
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’
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 Schematic of configuration of a micro processor
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.
Figure 3.1.3 Working of a microprocessor
• ALU: ALU stands for Arithmetical Logical Unit. As name indicates it has two
parts:
← Arithmetical unit which is responsible for mathematical operations like
addition, subtraction, multiplication and division,
← 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)
• 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.
• 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.
• 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).
← 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.
← R/W: As name indicates it is opposite to ROM and used for both reading and
writing operations. In general User’s program and instruction are stored in this
segment of memory unit.
• 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.
• Output Devices: These devices display the results/conclusions coming out from
ALUs either in soft copy (Monitor) or in Hard Copy (Printer).
2.1 Functions of microprocessor
Various functions of microprocessor are as follows:
A Microprocessor performs a variety of logical and mathematical operations using
its ALU.
B It controls data flow in a system and hence can transfer data from one location to
another based on the instructions given to it.
C A microprocessor can take necessary decisions and jump to a new set of
instructions based on those decisions.
2.2 Elements of microprocessor
A simple microprocessor consists of following basic elements (see Figure 3.1.3):
A Data Bus: Through data bus, the data flow between
o various storage units
p ALU and memory units
B Address Bus: It controls the flow of memory addresses between ALU and
memory unit.
C RD (read) and WR (write) lines set or obtain the addressed locations in the
memory.
D Clock line transfers the clock pulse sequence to the processor.
E Reset Line is used to restart execution and reset the processor to zero.
F Address Latch is a register which stores the addresses in the memory.
G Program Counter: It is a register which can increment its value by 1 and keeps the
record of number of instructions executed. It can be set to zero when instructed.
H Test Register: It is a register which stores intermediate or in-process data of ALU
operations. For example it is required to hold the ‘carry’ while ALU is performing
‘addition’ operation. It also stores the data which can be accessed by Instruction
decoder to make any decision.
I 3-State Buffers: These are tri-state buffers. A tri-state buffer can go to a third state
in addition to the states of 1 and 0.
J The instruction register and instruction decoder are responsible for controlling the
operations of all other components of a microprocessor.
There are following control lines present in a microprocessor, which are used to
communicate instructions and data with the instruction decoder.
A Instruct the A register to latch the value currently on the data bus.
B Instruct the B register to latch the value currently on the data bus.
C Instruct the C register to latch the value currently output by the ALU.
D Instruct the program counter register to latch the value currently on the data bus.
E Instruct the address register to latch the value currently on the data bus.
F Instruct the instruction register to latch the value currently on the data bus.
G Instruct the program counter to increment.
o Instruct the program counter to reset to zero.
p Activate any of the six tri-state buffers (six separate lines).
q Instruct the ALU what operation to perform.
r Instruct the test register to latch the ALU's test bits.
s Activate the RD line.
t Activate the WR line
3. Microcontroller
Microcontroller 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.
3.1 Microprocessor based programmable controller
Figure 3.1.4 Schematic of microcontroller.
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.
NPTEL – Mechanical – Mechatronics and Manufacturing Automation
4. Basics of microprocessor programming
In this lecture we will study the various number systems, programming languages, and
internal architecture of the basic microprocessor, 8085.
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
Number Base Allowable Digits/Characters Examples
System
Binary 2 0,1 (11001010001010)2
Octal 8 0,1,2,3,4,5,6,7 (5671235246214)8
Decimal 10 0,1,2,3,4,5,6,7,8,9 (9823654178523)10
Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F (A852F6DB)16
1.1 Number representation
1.1.1 Conversion of any number system to decimal number system:
Let B be the base of number system and An, A n-1,............................. A1,A0 be the
digits of given number. Then to convert it into decimal equivalent we can use the
following formula:
N = [Link] + [Link]-1 + ……….+A1.B + A0.B0 (3.2.1)
Example: what is the decimal equivalent of (11101011)2 ?
B. Here, we have taken An = 1, An-1= 1, ……. An-3=0, while n=8 and B = 2.
Then the decimal equivalent is (235)10.
1.1.2 Decimal number system to any number system:
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 235 1
2 117 1
2 58 0
2 29 1
2 14 0
2 7 1
2 3 1
2 1 1
Hence Binary equivalent of (235)10 is (11101011)2.
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 Binary Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
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 Hexadecimal equivalent of remainder
as per table 3.2.3
235 235 divided by 11 B
16 = 14 (full)
14 14 divided by 16 14 E
= Cannot divide
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.
Figure 3.2.1 BCD representation system
Example: (235)10 can be represented by using PCD as 001000110101.
2. Low Level Programming Language
Microprocessors recognize the binary numbers and they operate in binary numbers. Each
microprocessor has its own binary words, meanings and languages. Each machine has its
own set of instructions based on the design of its CPU. Binary language is called as
machine language. English-like words are used to represent the binary instructions of a
machine. This is called as assembly language programs. The general purpose languages
such as BASIC, FORTRAN, C, etc. are called as high-level languages. The machine
language and assembly language are however specific to a microprocessor, therefore
these are termed as low-level languages.
2.1 Assembly language
In assembly language, a word length is of about eight bits. It is called as a byte. Assembly
language can have 256 combinations of bytes. Thus the language has 256 words. There
can be a various patterns of bytes. With the help of electronic logic gates, these patterns
give a specific meaning to each combination of bytes. These are called as an
‘instruction’. Instructions are made up of one word or several words. The set of
instructions designed into the machine makes up the machine language that is specific to
each microprocessor based system viz. micro-computer.
Thus we can say,
‘Machine language is the binary medium of communication through a designed set of
instructions specific to each computer.’
‘Assembly level language is a medium of communication with a computer in which
programs are written in mnemonics. An assembly language is specific to a given
computer.’
2.2 Assembly language programming
Assembly language programming is generally written by using hexadecimal codes.
Programs can be written by using special keyboard equipped with using hex keys.
Programs also have instructions to translate these keys into their equivalent binary
patterns. The data and instructions are stored in prescribed locations in memory. An
operation code is written which accomplishes the intended task(s). These tasks are carried
out on ‘operand(s)’ by the operation code. 8085 is a typical general purpose
microprocessor and has 8-bit word length. Now, let us learn its architecture, working and
programming.
5. Internal Architecture of 8085 Microprocessor
5.1 Register Array
8085 Microprocessor consists of six registers, one accumulator and a flag register. The
typical architecture is shown in figure 3.2.2. There are six general-purpose registers B, C,
D, E, H, and L, each having capacity to store 8 bit data. They are combined as BC, DE,
HL to perform 16 bit operations. In addition to this Register array, two 16 bit registers
viz. stack register and program counter are provided. As discussed in the earlier lecture,
the ‘program counter’ is employed to sequence the execution of instructions. It always
points to the memory address from which the next byte is to be fetched. Stack Pointer
points to the memory location in R/W (Read and/or write) memory. It is also termed as a
‘stack’.
Figure 3.2.2 Architecture of 8085 microprocessor
5.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.
5.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.
A Zero Flag (Z): When an arithmetic operation results in zero, the flip-flop called
the Zero flag - which is set to one.
B 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.
C 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 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
A 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.
B 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 flip-
flops. These flags play an important role in decision-making process of the
microprocessor.
5.4 Instruction Register/Decoder
Before execution of an instruction, it is sent to the Instruction Register. Instruction
register stores current instruction of any program. Decoder takes the instruction from
memory, decodes it and then passes it to the next stage.
5.5 Memory Address Register
Memory Address Register (MAR) holds the address of next instruction to be executed.
5.6 Control Generator
In microprocessor, the Control Generator generates a signal that executes the operations
in accordance to the decoded instructions. In fact it creates a signal (information) which
have details about connections between different blocks of the microprocessor so that
data reaches to the respective place.
5.7 Register Selector
Register selector is basically a logical controller which directs switching between
different registers of microprocessor.
5.8 General Purpose Registers
Microprocessor has few extra registers which can be used to store additional data during
a program.
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:
C. Operation (Op) Code: It depends on which operation is to be performed. For
example for OR operation, we have Op Code “OR”.
D. Operands: Operand is the object on which the required operation is to be done.
Generally operations are done on data stored in registers.
4.1 Classification of Instructions:
A Data Transfer
B Arithmetic
C Logical
D Program Control
4.1.1 Data Transfer
1. Load: It reads content from specified memory location and copies it to specified
register location in CPU.
2. Store: It copies content of a specified register into specified memory location.
4.1.2 Arithmetic:
A Add: It adds contents of a specified memory location to the data in some register.
B Decrement: It subtracts 1 from contents of specified location.
C 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:
6. 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.
7. 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.
8. 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.
4.1.4 Program Control:
• Jump: This instruction changes the sequence in which program steps are carried
out. Normally program counter causes the program to be carried out sequentially
in strict numerical sequence. However, JUMP causes program counter to some
other specified location in the program.
• Branch: This is a conditional instruction which might ‘branch’ if ‘zero’ results or
‘branch’ if ‘plus’ results of an operation. Branch also followed if right conditions
occur in the decision making process.
• Halt: This instruction stops all further microprocessor activity.