Embedded CH 2 final
Embedded CH 2 final
Embedded Microcontrollers
Outline
• Structure of a basic computer system,
• CPU families used in microcontrollers,
• Basic I/O devices and technologies,
• Interrupts and Memories.
• Introduction to PIC16F877A
2
MICROCONTROLLER BASICS
• Microcontrollers comprise the main elements of a small computer
system on a single chip.
• Contain the memory, and IO as well as the CPU on the same chip.
This considerably reduces the size.
• Compromises in terms of performance and flexibility.
• Microcontrollers are often intended for low power and low processing
applications
• Microcontroller are particularly used in embedded system for real time
control application with on-chip program memory and devices.
3
Microcontroller and Microprocessors
4
STRUCTURE OF BASIC COMPUTER SYSTEM
• Structure indicates the way in which the components are interrelated.
The simplest possible depiction of a computer is given below.
• The computer interacts with its external environment using peripheral
devices or communication lines.
5
Continued..
• The internal structure of the computer contains four main structural
components. They are,
• Central processing unit (CPU): Controls the operation of the computer and
performs its data processing functions; often simply referred to as processor.
• Main memory: Stores data.
• I/O: Moves data between the computer and its external environment.
• System interconnection: Some mechanism that provides for communication among
CPU, main memory, and I/O.
• And the major structural components of CPU are,
• Control unit: Controls the operation of the CPU and hence the computer.
• Arithmetic and logic unit (ALU): Performs the computer’s data processing
functions.
• Registers: Provides storage internal to the CPU.
• CPU interconnection: Some mechanism that provides for communication among the
control unit, ALU, and registers.
6
Continued..
7
Computer architecture
1. Based on number of instruction set
• RISC Vs CISC architecture
I. RISC architecture (Reduced Instruction Set Computer)
Advantage
• Small number of instruction to learn
• Small number of cycle per instruction (most PIC instruction set have one clock per instruction
set)
Disadvantage
• Only basic operation is supported
• Complex operation is performed by the software programmer
II. CISC architectures(Complex Instruction Set Computer)
Advantage
• Easy of programming
• Large number of addressing modes
Disadvantage
• Low speed
• Difficult to study all instructions
• Lot of memory access (because of small number of registers)
8
Continued..
2. Based on memory CPU organization
• Harvard Vs von Neumann
I. Von Neumann
• Data and code lie in the same memory block.
• Two set of clock cycle is required.
• Pipelining is not possible.
• Simple in design.
II. Harvard
• Data and code lie in different memory block.
• Single set of clock cycle is sufficient.
• Pipelining is possible.
• Complex in design
9
Harvard Vs von Neumann
10
MICROCONTROLLER BASICS
• CPU- Microcontrollers brain.
• CPU is the device which is employed to fetch data, decode it and at the end
complete the assigned task successfully.
• With the help of CPU all the components of microcontroller is connected into
a single system.
• Memory-
• In a microcontroller memory chip works same as microprocessor.
• Memory chip stores all programs & data.
• Microcontrollers are built with certain amount of ROM or RAM or flash
memory for the storage of program source codes.
• Input/output ports–
• I/O ports are basically employed to interface or drive different appliances
such as - printers, LCD’s, LED’s, etc.
11
Continued..
• Serial Ports–
• These ports give serial interfaces amid microcontroller & various other
peripherals such as parallel port.
• Timers– A microcontroller may be in-built with one or more
timer or counters.
• The timers & counters control all counting & timing operations within a
microcontroller.
• Timers are employed to count external pulses.
• The main operations performed by timers’ are-pulse generations, clock
functions, frequency measuring, modulations, making oscillations, etc.
• ADC (Analog to digital converter)–ADC is employed to convert
analog signals to digital ones.
• The input signals need to be analog for ADC.
• The digital signal production can be employed for different digital applications
(such as measurement gadgets).
12
Continued..
• DAC (digital to analog converter)–this converter executes
opposite functions that ADC perform.
• This device is generally employed to supervise analog appliances like-DC
motors, etc.
• Interpret Control- This controller is employed for giving delayed
control for a working program.
• The interpret can be internal or external.
• Special Functioning Block–
• Some special microcontrollers manufactured for special appliances like space
systems, robots, etc.., comprise of this special function block.
• This special block has additional ports so as to carry out some special
operations.
13
CPU FAMILIES USED IN MICRONTROLLERS
• There are more than 140 microcontrollers and more than 40 companies that
produce them.
Some example includes
• 8051 families
• Produced by more than 50 companies
• AVR microcontrollers
• ARM microcontrollers
• PIC microcontrollers
• Etc
• The families differ mostly in instruction sets and architecture.
• In this course we will only see one of the PIC families.
• Within each family there are many different CPUs. While each CPU may
have the same core the feature set can vary a lot.
• Common differences within a single family are:
• On-Board ROM size
• On-Board RAM size
• Reprogram ability
• ADCs
• Timers 14
BASIC INPUT OUTPUT DEVICES AND TECHNOLOGY
• One of the most important feature of the microcontroller is a number of
input/ output pins used for connection with peripherals. In this case, there
are in total of thirty-five general purpose I/O pins available, which is quite
enough for the most applications.
• They grouped into five so called ports:
• PORT A
• PORT B
• PORT C
• PORT D
• PORT E
• For practical reason, many I/o pins have two or three functions.
• Every port has its ‘satellite’, i.e. the corresponding TRIS register: TRISA,
TRISB, TRISC etc. which determines the performance of port bits, but not
their contents.
• TRIS register (bit=0), the corresponding port pin is configured as an output.
• Similarly, by setting any bit of TRIS register (bit=1), pin is an input.
15
INTERRUPTS AND MEMORIES
Interrupt provides a method for handling unpredictable input.
1. Polling is one method of handling unpredictable input.
• Polling is the process of periodically checking for external events (e.g. check for
keyboard input).
Polling disadvantages:
• Event handling is not done in real-time
• Determining how often to check for input is a challenge
• Waste of CPU cycles to check for the existence of input
2. Interrupt provides the following advantages over polling:
• Real-time of event handling
• Free the CPU from waiting for events to occur
• No waste of CPU cycles to check for events
• Interrupt require CPU immediate attention (e.g. keyboard input, power failure, completion
of I/O, etc.).
• The normal flow of an executing program on the CPU is interrupted to react to the
interrupt.
• Modern computers provide interrupt capability through special control lines connected
directly to the CPU, known as interrupt lines.
• An interrupt on any of the interrupt lines causes the CPU to suspend the executing
program and jump to special interrupt handling program. 16
INTERRUPTS
• Two different methods are commonly used to identify the interrupting
device:
1. Vectored interrupt
The address of the interrupting device is included as part of the interrupt
Advantages
•Fast
Disadvantages
•Complex and requires extra hardware
2. General interrupt
A single interrupt is shared by all devices.
Polling each device when interrupt occur to identify the interrupting device.
Advantages
• Slow
Disadvantages
•Simple to design and implement
17
MEMORIES
Ordered sequence of bytes.
• The sequence number is called the memory address.
• Byte addressable memory:
• Each byte has a unique address
• Almost all processors support this
Memory address space:
• Determined by the address bus width
Memory unit:
• Address
• Data
• Control signals:
• Read
• Write
18
Types of Memory
1. Program Memory
19
Continued…
2. Data Memory
• The data memory is partitioned into multiple banks.
• Each bank contain General purpose Registers and Special function
Registers.
• It is volatile memory.
• Each bank extends up to 7Fh (128 bytes).
fig. banks of data memory
• The lower locations of each bank are reserved for the Special Function
Registers. Above the Special Function Regis-ters are General Purpose
Registers, implemented as static RAM.
3. Data EEPROM
• This is a non-volatile memory where values can be saved.
20
Data Memory banks detail
21
ORGANIZATION AND ARCHITECTURE OF PIC16F877
HOW ARE MICROCONTROLLERS CLASSIFIED?
• The microcontrollers are characterized regarding bus-width,
instruction set, and memory structure. For the same family, there may
be different forms with different sources.
• They are characterized by their bits, memory architecture,
memory/devices and instruction set.
22
CLASSIFICATION ACCORDING TO NUMBER OF BITS
• The bits in microcontroller are 8-bits, 16-bits and 32-bits.
• In 8-bit microcontroller, the point when the internal bus is 8-bit then
the ALU is performs the arithmetic and logic operations.
• E.g Intel 8031/8051, PIC1x and Motorola MC68HC11
• The 16-bit microcontroller performs greater precision and
performance as compared to 8-bit.
• Some examples of 16-bit microcontroller are 16-bit MCUs are extended
8051XA, PIC2x, Intel 8096 and Motorola MC68HC12 families
• The 32-bit microcontroller uses the 32-bit instructions to perform the
arithmetic and logic operations.
• Used in automatically controlled devices including implantable medical
devices, engine control systems, office machines...
• Some examples are Intel/Atmel 251 family, PIC3x
23
Why PIC?
• Popular in academic institution projects
• Relatively accessible (widely available) in small quantities
• Has high clock speed
• Has a rich set of development tools
• IDE and compilers
• E.g. Mplab (free), MicroC, MicroC Pro, PIC C, CCS for PIC etc
• Hardware development tools
• Evaluation board and programmers, debuggers etc
• It has a Harvard architecture
• High speed (pipelining)
• One instruction in one instruction cycles
• Large number of registers (RAM)
• It has a RISC architecture
• Only small number of instruction set to remember (35 instructions in the case of pic16f877(A) )
• Small addressing moods
• Have a rich set of families for different applications
• In circuit programming
24
PIC Device Structure
Each part of a device can be placed into one of three groups:
1. Core
2. Peripherals
3. Special Features
I. The Core
The core pertains to the basic features that are required to make the device
operate. These include:
1. Device Oscillator
2. Reset logic
3. CPU (Central Processing Unit) operation
4. ALU (Arithmetic Logical Unit) operation
5. Device memory map organization
6. Interrupt operation
7. Instruction set
25
Continued…
II. Peripherals
Peripherals are the features that add a differentiation from a microprocessor. These ease in
inter-facing to the external world (such as general purpose I/O, LCD drivers, A/D inputs, and
PWM outputs), and internal tasks such as keeping different time bases (such as timers). The
peripherals include:
1. General purpose I/O
2. Timer0
3. Timer1
4. Timer2
5. Capture, Compare, and PWM (CCP)
6. Synchronous Serial Port (SSP)
7. Basic Synchronous Serial Port (SSP)
8. Master Synchronous Serial Port (MSSP)
9. USART (SCI) 26
Continued…
III. Special Features
Special features are the unique features that help to do one or more of the
following things:
• Decrease system cost
• Increase system reliability
• Increase design flexibility
The Mid-Range PICmicro MCUs offer several features that help achieve
these goals. The special features discussed are:
1. Device Configuration bits
2. On-chip Power-on Reset (POR)
3. Brown-out Reset (BOR) logic
4. Watchdog Timer
5. Low power mode (Sleep)
6. Internal RC device oscillator
7. In-Circuit Serial Programming™ (ICSP™)
27
PIC MICROCONTROLLER Key Features
• High-performance RISC CPU
• Up to 8K x 14 words of FLASH program memory
• 35 Instructions (fixed length encoding-14-bit)
• 368×8 static RAM based data memory
• Up to 256 x 8 bytes of EEPROM data memory
• Interrupt capability (up to 15 sources)
• Three addressing modes (direct, indirect, relative)
• RESETS (and Delays): POR, BOR (PWRT, OST)
• Harvard architecture memory
• Power saving SLEEP mode
• Wide operating voltage range: 2.0V to 5.5V
• Operating Frequency: DC - 20 MHz
• High sink / source current: 25mA 28
PIC16F877A BLOCK DIAGRAM
29
PIN DESCRIPTION OF PIC16F877A
30
PIC 16F877A PERIPHERALS
• 15 Interrupts
• 5 I/O ports (Ports A,B,C,D,E)
• 3 Timers
• 2 capture/compare/PMW module
• MSSP,USART (serial communication )
• PSP (Parallel communication )
• 8 input channel of 10 bit Analog to Digital module
• 2 Analog comparator
31
I/O PIN
32
Thank you !
33