MECHATRONICS
(Course Code:18ME744)
Department of Mechanical Engineering
JSS Academy of Technical Education, Bangalore-560060
MECHATRONICS
CHAPTER 2: Microprocessor & Microcontroller
TEXT BOOKS
• Mechatronics Electronic control system in Mechanical and Electrical Engineering, W Bolton,
Pearson Education, 1st Ed., 2005.
REFERENCE BOOKS:
• Mechatronics by HMT Ltd. - Tata McGrawHill, 1st Edition, 2000
Further Reference:
National Programme on Technology Enhanced Learning (NPTEL)
https://nptel.ac.in/courses/112103174/1 by Dr. S. N. Joshi (IITG)
Learning Objectives
• Describe the structure and architecture of a microprocessor system.
• Describe the structure of a microcontrollers.
Module 3
Introduction: Microprocessor systems, Basic elements of control systems,
Microcontrollers, Difference between Microprocessor and Microcontrollers.
Microprocessor Architecture: Microprocessor architecture and terminology-CPU,
memory and address, I/O and Peripheral devices, ALU, Instruction and Program,
Assembler, Data, Registers, Program Counter, Flags, Fetch cycle, write cycle, state,
bus interrupts. Intel's 8085A Microprocessor.
Microprocessor systems
Microprocessor
• It is a CPU on a single integrated circuit chip containing millions of small
components including transistors, resistors, and diodes that work together.
• The microprocessor contains the arithmetic, logic, and control circuits required
to perform the functions.
Microprocessor systems
Microprocessor
• A microprocessor is a single VLSI chip having a CPU.
• The microprocessor is a multipurpose, programmable device that
accepts digital data as input, processes it according to instructions stored in its
memory, and provides the output.
• Processor system processes the data, fetching the instructions from memory,
decoding and executing them.
Microprocessor systems
Microprocessor operation
• Microprocessors use three steps: Fetch, Decode, and Execute.
• In Fetch cycle, an instruction is copied from the memory into the
microprocessor.
• In Decode cycle, the microprocessor figures out what operation the instruction
is meant to do.
• In Execution cycle, the operation is performed.
Microprocessor systems
Microprocessor Block Diagram and it’s Interfacing
Microprocessor systems
Microprocessors basically have three elements:
1. Central processing unit (CPU): To recognise and carry out program instructions.
2. Input and output: Interfaces to handle communications between the
microprocessor and the outside world (port).
3. Memory: To hold the program instructions and data.
General arrangement of a microprocessor system
• General form of a microprocessor system and its buses.
• All the components share the same data bus and address bus.
• Buses employ parallel transmission.
Microprocessor systems
Buses
• Digital signals move from one section to another, along paths called buses.
• A bus, is a number of parallel conductors (wires), carries electrical signals and the paths are
shared by all the chips in the system.
• A bus has 16 or 32 parallel connections, each carry 1 bit of a data word.
• Parallel connections gives faster transmission than serial connection, in which an entire word is
sent in a sequence of bits along a single conductor.
Architecture of a microprocessor
The following are the functions of the constituent parts of a microprocessor
• Arithmetic and Logic unit (ALU): Responsible for performing the data
manipulation.
• Registers: Memory locations within the microprocessor, used to store information
involved in program execution.
Architecture of a microprocessor
• Control unit: Determines the timing and sequence of operations.
• It generates the timing signals, to fetch a program instruction from memory and
execute it.
E.g.: Motorola 6800 uses a clock with a maximum frequency of 1 MHz
i.e. Operations within the microprocessor are referred in terms of No. of cycles they
take.
Architecture of Microprocessor systems
General internal architecture of a microprocessor
Microprocessor systems
The following are the functions of the constituent parts of a microprocessor
1. Instruction Set
• Set of instructions a microprocessor can understand.
• It is an interface between hardware and software (program).
2. Bus
A bus is a set of conductors / wires intended to transmit data, address or control
information to different elements in a microprocessor.
• 3 types of buses: Data Bus, Control Bus and Address Bus.
Terms Used in a Microprocessor
1. Data Bus (8 bit)
• Carries the data associated with processing function of CPU.
• Each wire in a bus carries a binary signal a 0 or a 1.
• More the wires in the bus longer the word length.
• Word length of 4 bits is 24 = 16. (4 bit Processor)
2. Control Bus
• Carries the signals relating to control actions / control signals.
E.g. : Microprocessor to inform memory devices, whether to read data from an
input device or write data to an output device.
Terms Used in a Microprocessor
3. Address Bus (16 bit)
• Carries signals which indicate where data is to be found.
• Each storage location within a memory device has a unique identification.
• Each input/output interface also has an address.
• When a address is selected, it is placed on the address bus, only that location is
open to the communications from the CPU.
E.g.: 8-bit data bus has a 16-bit-wide address bus, i.e. 16 wires.
• This size of address bus enables 216 locations to be addressed; 216 = 65536
locations (64KB).
Terms Used in a Microprocessor
3. Bandwidth: No. of bits processed in a single instruction.
4. Clock Speed: No. of operations per second a processor can perform, MHz / GHz.
5. Word Length: Width of internal data bus, registers, ALU, etc.
E.g. An 8-bit microprocessor can process 8-bit data at a time. ( 4 bits - 64 bits)
Microprocessor systems
Registers
• There are a number of types of registers.
• The number, size and types of registers vary from one µp to another.
• The following are common types of registers.
1. Accumulator register (A)
2. Status Register or Flag Register
3. Program Counter Register (PC)
4. Memory Address Register (MAR)
5. Instruction Register (IR)
6. General Purpose Register
7. Stack Pointer Register (SP)
Microprocessor systems
Accumulator register (A)
• Input data / instructions to the ALU is temporarily stored.
• For CPU to read, instructions or data in the memory, it has to supply the address
of the instructions, using the address bus.
• Since one memory location can be addressed at once, temporary storage has to
be used.
E.g. Addition of two numbers.
• One of the number is fetched from one address and placed in the accumulator register, the
CPU fetches the other number from the other memory address (registers) .
Microprocessor systems
Accumulator register (A)
• The two numbers can be processed by the ALU, result is transferred back into
the accumulator register.
• The accumulator register is a temporary holding register for data to be operated
by the ALU.
• It is involved in all data transfers associated with the execution of ALU
Microprocessor systems
Status register or Flag register (8 bit)
• It contains individual bits, each bit having special significance.
• Each bit is called as Flag.
• These Flag indicates the status of the latest operation/process.
• Each flag being set or reset to indicate a specific status.
• Every time ALU executes an operation, two things will happen; one is the result,
and the other is the status of the operation, which goes into the flag register.
• Flags can be changed by the µp
Status register or Flag register (8 bit)
The following are common flags.
Microprocessor systems
Status register or Flag register (8 bit)
Example
• Consider the state of the Z, N, C and V flags for the operation of adding the hex numbers 02 and
06.
• The result is 08. Since it is not zero, then Z is 0.
• The result is positive, so N is 0. There is no carry, so C is 0.
• The unsigned result is within the range -128 to +127 and so there is no overflow and V is 0.
Microprocessor systems
Program counter register (PC) or Instruction pointer (IP) (16 bit)
• PC register keep track of the program / operation being executed by CPU.
• This register contains the address of the memory location, for the next program
instruction.
• The program counter is incremented each time so that the CPU executes
instructions sequentially. Unless an instruction, such as JUMP or BRANCH,
changes the program counter out of that sequence.
Microprocessor systems
Memory address register (MAR): This contains the address of data.
E.g.
Addition of two numbers, the MAR is loaded with the address of the first number.
• The data at the address is moved to the accumulator.
• The address of the second number is then loaded into the MAR.
• The data at this address is then added to the data in the accumulator.
• The result is then stored in a memory location addressed by the MAR.
Microprocessor systems
Instruction register (IR)
• This stores an instruction.
• After fetching an instruction from the memory via data bus, the CPU stores the
instructions in the IR.
• After each fetch cycle, the CPU increments the PC by one, resulting that the
PC points to the next instruction waiting to be fetched.
• The instruction can then be decoded and used to execute an operation.
• This sequence is known as the fetch–execute cycle.
Microprocessor systems
General-purpose registers
• Serve as temporary storage for data or addresses, used in operations
involving transfers between other registers.
• In 8085, there are 6 types of special registers called general purpose registers.
• They are B, C, D, E, H & L.
B(8) C(8)
• Each register can hold 8 bit data. D(8) E(8)
• They can work in pairs such as B-C, D-E, H-L to store 16 bit data.
H(8) L(8)
• The H-L pair work as a memory pointer.
• A memory pointer holds the address of a particular memory location.
Microprocessor systems
Stack pointer register (SP)
• A stack is the portion of RAM
• LIFO (last in first out) is the principle.
• Stacks are data structures used by the programmer to store data.
• The data is stored in stacks (layer by layer).
• The last data to enter the stack is the first to be read / comes out.
• The program counter values can be stored, when a subroutine part of a program
is being used.
• Stack pointer maintains the address of the last byte that is entered into stack.
• Each time when the data is loaded into stack, Stack pointer gets decremented.
Microprocessor systems
Increment/Decrement counter
• The microprocessor uses this counter register to increment or decrement
the contents of the various register available in the register unit.
Example
Every time µp accesses a memory, its PC register increments by one.
Microprocessor systems
Control Unit
• This unit generates signals within microprocessor to carry out the instruction,
which has been decoded.
• Practically it causes certain connections between blocks of the microprocessor to
be opened or closed. so that the data goes where it is required and the ALU
operations occur.
• The control unit itself consists of three parts; the instructions register (IR).
Instruction decoder and control and timing unit.
Microprocessor systems
Memory
• The memory unit stores binary data (program instruction codes or numbers)
• Size of the memory = Number of wires in the address bus.
• The memory elements consist of large numbers of storage cells, each cell capable
of storing 0 or 1 bit.
• The storage cells are grouped in locations, each location capable of storing one
word.
• To access the stored word, each location is identified by a unique address.
E.g.
• A 4-bit address bus can have 16 different addresses with each capable of storing 1
byte (8 bits)
Microprocessor systems
Forms of Memory
There are a number of forms of memory unit.
ROM (Read Only Memory)
• ROMs are programmed by the manufacture.
• No data can then be written into this memory.
• The data can only be read, used for fixed programs like OS and
programs.
• They do not lose their memory when power is turned off.
Microprocessor systems
Forms of Memory
PROM: Programmable ROM
• Can be programmed by the user.
• Used for ROM chips.
• Every memory cell has a fusible link which keeps its memory at 0.
• The 0 is permanently changed to 1 by sending a current through the fuse to open
it permanently.
• Once the fusible link has been opened the data is permanently stored in the
memory and cannot be further changed.
Microprocessor systems
Forms of Memory
EPROM: Erasable and Programmable ROM
Used for ROMs, can be programmed and their contents can be altered
• Consists of series of small electronic circuits, cells, which can store charge.
• Programmed by applying voltages to the IC pins, producing a pattern of charged
and uncharged cells.
• The pattern remains permanently in the chip until erased by ultraviolet light
through a quartz window, on top of the device.
Microprocessor systems
Forms of Memory
EEPROM
• Electrically erasable PROM (EEPROM) is similar to EPROM.
• Erasing is by applying relatively high voltage rather than using ultraviolet light.
Microprocessor systems
Forms of Memory
RAM (Random-access memory): Temporary data is stored in a read/write memory.
• Its volatile
• Information stored is temporary
• Used for current operation / runtime operations
(a) ROM chip, (b) RAM chip.
Intel 8085A architecture
Introduction to 8085
• Introduced in 1977.
• It is 8-bit Microprocessor.
• It is a 40 pin dual-in-line chip.
• It uses a single +5V supply for its operations.
• Its clock speed is about 3MHz .
Components of 8085 Microprocessor
The 8085 microprocessor architecture consists of five parts;
1. Register unit
2. Control unit
3. Arithmetic and logical unit
4. Interrupt unit
5. Serial IO unit
Functioning of 8085 Microprocessor
Programs / instructions
Simplified diagram of Microprocessor
8
8 8 8
5/8
8 8
8 8
8 8
8 16
16
16
8085 Architecture
Microprocessor works on Fetch, Decode and Execute cycle.
Fetch cycle
• Before fetching the instruction, µp wants to know the address of the
instructions that is stored.
• This address is present in a register called PC (program counter register).
• PC is a special purpose register, as it is used by µp.
• PC records the last state of the operation/process/program being executed by
the µp.
• Also, PC holds the address of the next instruction.
8085 Architecture
Fetch cycle
• PC will have address of the instruction that is stored in the register or memory
• This address will be now put on the address bus, as µp will send RD signal on
the control bus, the instruction will be fetched from the memory through the
data bus.
• Once the instructions come into the data bus, the µp cannot float the
instruction, these instructions has to be stored in another register called as IR
(instruction register)
• Once instruction is stored in IR the fetch cycle is complete.
8085 Architecture
Decode cycle
• Decoding means analysing the binary data.
Example: when we write an instruction MOV B, C (Assembly language)
• This instructions cannot be understood by µp.
• The above instruction is stored in memory in a binary pattern.
• This binary code which indicates the operation are referred as operation code
(OP Code).
• Every instruction will have an OP code.
• Once µp understands the OP code, this code will be sent to the timing and
control signal.
8085 Architecture
Decode cycle
• After reading the OP code, the µp will understand which OP code belongs
which instruction, i.e. called decoding.
• Once the instruction is decoded by the Instruction decoder (ID), then is the
execution cycle.
8085 Architecture
Decode cycle
• Now exactly the same process will happen, for the next/second instruction.
• To fetch the second instruction the µp has to know its address, then the
address is given by the PC, and PC will go on increment, after every instruction
being executed by µp, hence pc is of 16 bit and µp is of 8 bit.
• The other general purpose register are of 8 bit.
• Data bus is of 8 bit.
• Address bus is of 16 bit.
8085 Architecture
Timing & Control signal
• The purpose of the timing & control signal is not to execute.
• Execution will happen in the whole architecture.
• Different parts of the architecture are involved in the execution of the
instruction.
• It releases the control signals.
• These signals are sent to every parts of the architecture.
• There are 74 set of instructions in an 8085 µp.
8085 Architecture
Example
Consider an operation 2+3=5
• 2 is the first operand
• 3 is the second operand
• Out of the two operand, the first operand is stored in the Accumulator (8 bit).
• The other registers (general purpose) available to the programmer are B, C, D,
E, H & L.
• The second operand is stored in stored in B register.
8085 Architecture
Example
• The Accumulator (A) gets the value 02 & the B register gets the value 03.
• The instructions for µp to add these numbers will be ADD B.
• The two things that the µp knows are who is the first operand & where it is
stored.
• Every µp has its own characteristics.
• In any arithmetic or logical operation, the Accumulator (A) will hold the first
operand and also gets the result
• The second operand will be on any other general purpose register.
8085 Architecture
Example
• If we write ADD B, ADD C, ADD D, assuming some value stored in Accumulator.
• The result / output / total comes in A.
• There is accumulated value inside A, hence it is called Accumulator (A).
• If the series of arithmetic operations continues, the Accumulator will hold the
accumulated value.
8085 Architecture
Example
• The Accumulator (A) has the value 02 & the B register has the value 03.
• The instructions for µp to add these numbers will be ADD B.
• This instruction stored in the memory is fetched, i.e.
• PC will get the address.
• The instruction will be fetched from the data bus.
• This instructions comes to the IR, & then ID decodes, i.e. the ID converts the
INST ADD B to binary.
• This instruction goes to the timing & control signal, will release the timing &
control signal to tell other components to what to do.
8085 Architecture
Example
• The timing & control signal, will release signal to Accumulator (A), so the A will
send the value 02 to the ALU.
• Similarly the timing & control signal will send the signal to the other register B,
which hold the value 03.
• This value 03 is put on the internal data bus and comes to the temporary
register.
8085 Architecture
Example
Temporary register
• This register hold the second operand / value momentarily, as it is used by µp.
• The timing & control signal will send the signal to ALU to add the values.
• The ALU will add the values i.e. 02+03 = 05 and the result is put back into the
accumulator through the data bus.
• The timing & control signal will send the signal to Accumulator, it will stores the
value / result i.e. 05.
Microprocessor systems
I/O and Peripheral Devices
Input/output: enables data transfer between the CPU and the external world.
Peripheral Devices / Auxiliary Devices
• Are equipment that exchange data with a microprocessor system.
• Connected via interface chips.
• A major function of an interface chip is to synchronise data transfers.
8085 Microprocessor – Functional Units
General purpose register / Register Array
• There are 6 general purpose registers i.e. B, C, D, E, H & L.
• Used only during the execution of the instructions.
• Each register can hold 8-bit data.
• WZ cant be used by the programmer, Temporary register
• Registers work in pair to hold 16-bit data.
• Pairing combination is like BC16, DE16 & HL16.
• These registers are programmed by user.
8085 Microprocessor – Functional Units
Program counter (PC)
• It is a 16-bit register.
• Used to store memory address location of the next instruction to be executed.
• Microprocessor increments the program counter, when an instruction is being
executed, the program counter points to the memory address of the next
instruction to be executed.
8085 Microprocessor – Functional Units
Instruction register and decoder
• It is an 8-bit register.
• The instruction provided is stored in the Instruction register.
• Instruction decoder decodes the information present in the Instruction register.
8085 Microprocessor – Functional Units
Timing and control unit
• It provides timing and control signal to the microprocessor to perform operations.
• It has three control signal.
• It controls all external and internal circuits.
• It operates with reference to clock signal.
• It synchronizes all the data transfers.
The timing and control signals are;
• Control Signals: Read (RD), Write (WR), ALE (Address Latch Enable)
• Status Signals: S0, S1, IO/M (IO & Memory)
8085 Microprocessor – Functional Units
There are three control signal:
1. ALE (Address Latch Enable): Provides control signal to synchronize the
components of microprocessor.
2. RD: Used for reading operation.
3. WR: Used for writing operation.
8085 Microprocessor – Functional Units
There are three Status signal:
• It changes its status according the input provided to these pins.
8085 Microprocessor – Functional Units
Interrupt control
• it controls the interrupts during a process.
• Generally an external hardware is connected to these pins.
Example:
• As the microprocessor is executing a process and an interrupt occurs, the microprocessor shifts
the control from the process to process the incoming request.
• After the request is completed, the control goes back to the main program.
• Generally INTA is used to acknowledge the incoming request / interrupt.
8085 Microprocessor – Functional Units
Serial Input/output control
• Two pins in this unit, used for serial data communication
• Controls the serial data communication by using two instructions:
1. SID (Serial input data)
2. SOD (Serial output data).
Microprocessor systems
Classification of Microprocessor
The microprocessor are identified with the word size of data.
E.g. ALU can perform a 4- bit data operation at a time, called as 4-bit microprocessor.
• 4-Bit Processors: Intel 404, 4040
• 8-Bit Processors: 8088, 8080, 8085, M6800
• 16-Bit Processors: 8086, Zilog 800, 80186, 80286
• 32-Bit Processors: 80386, 80387, 80486, Pentium, Pentium Pro
• 64 bit Processor: Pentium 4
Microprocessor systems
Classification of Microprocessor
Microcontroller
Microcontroller
A microcontroller is a single-chip VLSI unit (microcomputer), have limited
computational capabilities, possesses enhanced input/output capability and a
number of on-chip functional units.
Microcontrollers are used in embedded systems for real-time control applications
with on-chip program memory and devices.
Microcontroller
• Microcontroller is the integration of a microprocessor with memory,
input/output interfaces, and other peripherals such as timers, on a single chip.
• Microcontrollers have limited amounts of ROM and RAM.
E.g.
• Motorola 68HC11, Intel 8051 and PIC16C6x/7x are 8-bit microcontrollers.
• Motorola 68HC16 is an example of a 16-bit microcontroller.
• Motorola 68300 a 32-bit microcontroller.
Microcontroller
Microcontroller
• The microcontroller has pins for external connections of inputs, outputs, power,
clock and control signals.
• The pins for the I/P & O/P are grouped into units called input/output ports.
• Ports have 8 lines in order to be able to transfer an 8-bit word of data.
• Two ports may be used for a 16-bit word, one to transmit the lower 8 bits and the
other the upper 8 bits.
• The ports can be input only, output only or programmable to be either I/P or O/P.
Microprocessor vs Microcontroller
Microprocessor Microcontroller
Microprocessors are multitasking in Single task oriented.
nature. E.g.: Washing machine
RAM, ROM, I/O Ports, and Timers are to
RAM, ROM, I/O Ports, and Timers can be
be embedded together on a chip and are
added externally and can vary in nos.
fixed in nos.
Designers can decide the nos. of Fixed number for memory or I/O makes a
memory or I/O ports needed. it ideal for a limited but specific task.
External support for the system makes it Lightweight and cheaper than a
heavier and costlier. microprocessor.
More space and high power It consumes less power and takes less
consumption space.
Microprocessor vs Microcontroller
Microcontroller
Microcontroller
Selecting a microcontroller
• Number of input/output pins
How many input/output pins are going to be needed for the task concerned?
• Interfaces required
What interfaces are going to be required?
• Memory requirements
What size memory is required for the task?
• The number of interrupts required
How many events will need interrupts?
• Processing speed required
The microprocessor takes time to execute instructions this time being determined by the
processor clock.
Applications
1. Consumer Electronics Products: Toys, Cameras, Robots, Washing Machine, Microwave Ovens
etc. [any automatic home appliance]
2. Instrumentation and Process Control: Oscilloscopes, Multi-meter, Leakage Current Tester, Data
Acquisition and Control etc.
3. Medical Instruments: ECG Machine, Accu-Check etc.
4. Communication: Cell Phones, Telephone Sets, Answering Machines etc.
5. Office Equipment: Fax, Printers etc.
6. Multimedia Application: Mp3 Player, PDAs etc.
7. Automobile: Speedometer, Auto-breaking system etc.
End of Module