Prepared by
Sl.
Name of the Faculty Designation Affiliating College
No.
1 Mr. V. Parvathinathan AP/ ECE SCADCET
Verified by DLI, CLI and Approved by the Centralized Monitoring Team dated
_________________.
1
EC6013 ADVANCED MICROPROCESSORS AND MICROCONTROLLERS L T P C
3003
OBJECTIVES:
TOTAL: 45 PERIODS
OUTCOMES:
The student will be able to work with suitable microprocessor / microcontroller
for a specific real world application.
TEXT BOOK:
1. Andrew N.Sloss, Dominic Symes and Chris Wright “ ARM System Developer’s
Guide : Designing and Optimizing System Software” , First edition, Morgan
Kaufmann Publishers, 2004.
2
REFERENCES:
1. Steve Furber , “ARM System –On –Chip architecture”, Addision Wesley, 2000.
2. Daniel Tabak , “Advanced Microprocessors”, Mc Graw Hill. Inc., 1995
3. James L. Antonakos , “ The Pentium Microprocessor”, Pearson Education, 1997.
4. Gene .H.Miller, “Micro Computer Engineering”, Pearson Education , 2003.
5. John .B.Peatman , “Design with PIC Microcontroller”, Prentice Hall, 1997.
6. James L.Antonakos, “An Introduction to the Intel family of Microprocessors”,
Pearson
Education, 1999.
7. Barry.B.Brey,“The Intel Microprocessors Architecture, Programming and
Interfacing”,
PHI,2002.
8. Valvano, "Embedded Microcomputer Systems", Thomson Asia PVT LTD first
reprint 2001.
Readings: Web links www.ocw.nit.edu www.arm.com
3
EC6013 ADVANCED MICROPROCESSORS AND MICROCONTROLLERS L T P C
3003
1. Aim and Objective of the Subject
The student should be made
To expose the students to the fundamentals of microprocessor architecture.
To enable the students to understand various microcontroller architectures.
To introduce the advanced features in microprocessors and
microcontrollers.
To enable the students to understand various microcontroller architectures.
To expose the students to the applications of microprocessors and
microcontrollers.
Industry Connectivity:
The following companies (Industries) are linked to Advanced Microprocessor
and Microcontroller:
C-DAC, NIELIT and Bharat Electronics Ltd (BEL),
Latest Developments:
Application class processors are finding their way into the embedded sector
as system complexity increases
The launch of the AMD Opteron 6200 and 4200 Series Embedded Processors
has delivers better performance, efficiency and scalability.
4
SCAD GROUP OF INSTITUTIONS
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
TEXT BOOK:
1. Andrew N.Sloss, Dominic Symes and Chris Wright “ ARM System Developer’s
Guide : Designing and Optimizing System Software” , First edition, Morgan
Kaufmann Publishers, 2004.
REFERENCES:
1. Steve Furber , “ARM System –On –Chip architecture”, Addision Wesley, 2000.
2. Daniel Tabak , “Advanced Microprocessors”, Mc Graw Hill. Inc., 1995
3. James L. Antonakos , “ The Pentium Microprocessor”, Pearson Education, 1997.
4. Gene .H.Miller, “Micro Computer Engineering”, Pearson Education , 2003.
5. John .B.Peatman , “Design with PIC Microcontroller”, Prentice Hall, 1997.
6. James L.Antonakos, “An Introduction to the Intel family of Microprocessors”,
Pearson Education, 1999.
7. Barry.B.Brey,“The Intel Microprocessors Architecture, Programming and
Interfacing”,
PHI,2002.
8. Valvano, "Embedded Microcomputer Systems", Thomson Asia PVT LTD first
reprint 2001. Readings: Web links www.ocw.nit.edu www.arm.com
5
S. WEEK TOPIC NAME NO. OF TEXT BOOK PAGE NO.
NO. HOURS
6
18 IIR filter – Discrete fourier 294
transform 1 T1
19 Exception handling – 317
Interrupts – Interrupt 1 T1
20 Firmware and boot loader –
handling schemes 367
Embedded Operating 1 T1
21 WEEK 8 Integrated
systems Development
Environment- STDIO 1 Notes
22 Peripheral
Libraries Interface
1 Notes
23 ARM Processor - Caches 403
2 T1
24 WEEK 9 Memory protection Units 461
1 T1
25 Memory Management units 491
2 T1
26 Future ARM Technologies. 1 T1 549
27
WEEK Instruction set 2 Notes
10
28 addressing modes 2
Notes
29 operating modes- Interrupt 1
system Notes
30 RTC-Serial Communication 1
Interface Notes
31
WEEK A/D Converter 1
11 Notes
32 PWM 1
Notes
33 UART. 1
Notes
UNIT V PIC MICROCONTROLLER
7
38 WEEK UART- A/D Converter 1 206,195
R5
13
39 PWM 1 126
R5
40 introduction to C-Compilers 2
Notes
8
TABLE OF CONTENT
S.No TITLE PAGE NO
UNIT 1 - HIGH PERFORMANCE CISC ARCHITECTURE – PENTIUM
PART A 1
PART B
1 Pentium Processor architecture 3
2 Pentium Special registers 6
3 Paging mechanism in Pentium Processor 7
4 Addressing modes of Pentium Processor 10
5 Instruction set of Pentium processor 15
UNIT 2 - HIGH PERFORMANCE RISC ARCHITECTURE – ARM
PART A 18
PART B
1 Arm instruction set 20
2 Thumb instruction set 25
3 Architecture of arm processors 28
4 Pipe line 31
5 Interrupts 32
UNIT 3 - ARM APPLICATION DEVELOPMENT
PART A 34
PART B
1 Interrupt handling schemes 36
2 FIR and IIR filters on ARM 38
3 Memory Management Unit (MMU) of Arm 41
4 Embedded operating system 44
5 Cache Memory of ARM Processor 46
UNIT 4 - MOTOROLA 68HC11 MICROCONTROLLERS
PART A 50
PART B
1 Block diagram of 68HC11. MODEL 52
2 Addressing modes of 68 HC 11 micro controllers 55
3 UART interface with Motorola micro controller 58
4 A/D conversion process in 68HC11 microcontrollers 62
5 Instruction set of 68HC11 microcontroller 64
UNIT 5 - PIC MICROCONTROLLER
PART A 70
PART B
1 Interrupts handing in PIC micro controller 72
2 Architecture of PIC micro controllers. 75
Features of UART and A/D converter in PIC micro
3 78
controller
5 I2C interfacing with PIC micro controller 81
6 Program and data memory of PIC microcontrollers 84
9
UNIT 1 HIGH PERFORMANCE CISC ARCHITECTURE – PENTIUM
PART A
1
machine. For example, while one instruction is being executed, the computer is
decoding the next instruction.
2
12. Define: Paging
paging is a memory management scheme by which a computer stores and retrieves
data from secondary storage. In this scheme, the operating system retrieves data from
secondary storage in same-size blocks called pages. Paging is an important part
of virtual memory implementations in modern operating systems
14. What are the components used for page address translation?
Three components are used in page address translation:
- the page directory
- the page table
- the actual physical memory page
RISC CISC
Small Number of instructions(not exceed More no. of instructions
128)
Single cycle execution of all instructions. Instructions may require more than one cycle
for execution
Small no. of instruction formats (not exceed More no. of instruction formats
about 4)
Small no. of addressing modes (not exceed More addressing modes are available
about 4)
PART B
1. Explain in detail about Pentium Processor architecture (or) Explain the features
of Pentium Processor.
Features of Pentium Processor:
• The Pentium microprocessor is almost identical to the earlier 80386 and 80486
microprocessors.
• The main difference is that the Pentium has been modified in-ternally to contain a
dual cache (instruction and data) and a dual integer unit.
• The Pentium also operates at a higher clock speed of 66 MHz.
• The data bus on the Pentium is 64 bits wide and contains eight byte-wide memory
banks selected with bank enable signals.
3
• The superscalar structure of the Pentium contains three independent process-ing
units: a floating-point processor and two integer processing units labeled U and V by
Intel.
• The cache structure of the Pentium is modified to include two caches.
• A new mode of operation called the system memory-management (SMM) mode has
been added to the Pentium.
• The built-in self-test (BIST) allows the Pentium to be tested when power is first
applied to the system.
• The pin-out of the Pentium processor, packaged in a huge 237-pin PGA (pin grid
array)
• Pentium is available in two versions:
i. the full-blown Pentium
ii. P24T version called the Pentium Overdrive
• P24T version contains a 32-bit data bus, for insertion into 80486 machines which
contain the P24T socket
Memory system for the Pentium is 4G bytes.
b. just as in 80386DX and 80486 processors
It has Built In Self Test (BIST) feature.
4
Fig. Superscalar Architecture of Pentium
5
2. Explain in detail about Pentium Special registers (or) Explain in detail about
Pentium control registers
Pentium is essentially the same as 80386 and 80486
a. except some additional features and changes to the control register set have
occurred.
Control Registers :
– a new control register, CR4, has been added to the control register array .
PG Selects page table translation of linear addresses into physical addresses when
PG = 1. Page table translation allows any linear address to be assigned any physical
memory location.
ET Selects the 80287 coprocessor when ET _ 0 or the 80387 coprocessor when
ET.
TS switched tasks (in protected mode, changing the contents of TR places a 1 into
TS). If TS 1, a numeric coprocessor instruction causes a type 7 (coprocessor not
available) interrupt.
EM The emulate bit is set to cause a type 7 interrupt for each ESC instruction.
MP is set to indicate that the arithmetic coprocessor is present in the system.
6
NE Numeric error enables standard numeric coprocessor error detection. If NE = 1,
the pin FERR becomes active for a numeric coprocessor error. If NE = 0, any
coprocessor error is ignored.
VME Virtual mode extension enables support for the virtual interrupt flag in
protected mode. If VME = 0, virtual interrupt support is disabled.
PVI Protected mode virtual interrupt enables support for the virtual interrupt
flag in protected mode.
TSD Time stamp disable controls the RDTSC instruction.
DE Debugging extension enables I/O breakpoint debugging extensions when set.
PSE Page size extension enables 4M-byte memory pages when set.
MCE Machine check enable enables the machine checking interrupt.
EFLAG Register
- The extended flag (EFLAG) register has been changed in the Pentium
microprocessor
– four new flag bits have been added to control or indicate conditions about
some of the new features in the Pentium
ID The identification flag is used to test for the CPUID instruction. If a program can set
and clear the ID flag, the processor supports the CPUID instruction.
VIF Virtual interrupt is the image of the interrupt flag IF used with VIP.
The memory paging mechanism located within the 80386 and above allows any
physical memory location to be assigned to any linear address.
The linear address is defined as the address generated by a program. The physical
address is the actual memory location accessed by a program.
7
With the memory paging unit, the linear address is invisibly translated to any
physical address, which allows an application written to function at a specific address to be
relocated through the paging mechanism. It also allows memory to be placed into areas
where no memory exists.
Paging Registers
The paging unit is controlled by the contents of the microprocessor’s control registers.
Beginning with the Pentium, an additional control register labeled CR4 controls
extensions to the basic architecture provided in the Pentium or newer microprocessor.
One of these features is a 2M- or a 4M-byte page that is enabled by controlling CR4.
The registers important to the paging unit are CR0 and CR3. The leftmost bit (PG)
position of CR0 selects paging when placed at a logic 1 level. If the PG bit is cleared (0),
the linear address generated by the program becomes the physical address used to
access memory.
If the PG bit is set (1), the linear address is converted to a physical address through the
paging mechanism.
The paging mechanism functions in both the real and protected modes.
CR3 contains the page directory base or root address, and the PCD and PWT bits.
The linear address, as it is generated by the software, is broken into three sections that are
used to access the page directory entry, page table entry, and memory page offset
address. Figure 2–12 shows the linear address and its makeup for paging.
8
The Page Directory and Page Table
Figure 2–13 shows the page directory, a few page tables, and some memory pages. There is
only one page directory in the system. The page directory contains 1024 double word
addresses that locate up to 1024 page tables. The page directory and each page table are 4K
bytes in length.
9
Paging in Pentium
Memory-Management Mode
The system memory-management mode (SMM) is on the same level as protected
mode, real mode, and virtual mode, but it is provided to function as a manager.
Access to the SMM is accomplished via a new external hardware interrupt applied to
the SMI’ pin on the Pentium. When the SMM interrupt is activated, the processor begins
executing system-level software in an area of memory called the system management RAM,
or SMMRAM, called the SMM state dump record.
The SMI’ interrupt disables all other interrupts that are normally handled by user
applications and the operating system. A return from the SMM interrupt is accomplished
with a new instruction called RSM.
Addressing Modes
10
* Register mode
* Immediate mode
* Memory mode
• Specification of operands located in memory can be done in a variety of ways
* Mainly to support high-level language constructs and data structures
Addressing Modes
Direct Indirect
[disp]
Based-Indexed Based-Indexed
with no scale factor with scale factor
[Base + Index + disp] [Base + (Index * scale) + disp]
11
push exist)
* Can be used to specify only the source operands (not the destination operand)
* Another addressing mode is required for specifying the destination operand
• Efficient as the data comes with the instructions (instructions are generally pre
fetched)
--Memory Addressing Modes--
• Pentium offers several addressing modes to access operands located in memory
» Primary reason: To efficiently support high-level language constructs and data
structures.
• Available addressing modes depend on the address size used
16-bit modes (shown before)
» same as those supported by 8086
* 32-bit modes (shown before)
» supported by Pentium
» more flexible set
12
16-bit or 32-bit Addressing Mode?
• Uses the D bit in the CS segment descriptor
D=0
» default size of operands and addresses is 16 bits
D=1
» default size of operands and addresses is 32 bits
• We can override these defaults
Pentium provides two size override prefixes
66H operand size override prefix
67H address size override prefix
• Using these prefixes, we can mix 16- and 32-bit data and addresses
--Direct Addressing--
• 32-bit addresses
13
* EAX, EBX, ECX, EDX, ESI, EDI: data segment
* EBP, ESP : stack segment
--Based Addressing--
--Indexed Addressing--
--Based-Indexed Addressing--
Based-indexed addressing with no scale factor
• Effective address is computed as
Base + Index + signed displacement
• Useful in accessing two-dimensional arrays
» Displacement ==> points to the beginning of the array
» Base and index registers point to a row and an element within that row
14
• Useful in accessing arrays of records
» Displacement ==> represents the offset of a field in a record
» Base and index registers hold a pointer to the base of the array and the offset of
an element relative to the base of the array.
-- PC relative mode –-
The effective address is the sum of the contents of the PC and a constant contained within
the instruction.
Example instruction:
jmp a_label
The contents of the program counter is added to an offset that is within the machine
code for the instruction. The resulting sum is placed back into the program counter. Note
that from the assembly language it is not clear that a PC relative addressing mode is used.
It is the assembler that generates the offset to place in the instruction.
Integer Instructions
Integer instructions perform the integer arithmetic, logic, and program flow control
operations
15
IMUL Signed multiply
MUL Unsigned multiply
DIV Unsigned divide
INC Increment
DEC Decrement
NEG Negate
3. Decimal Arithmetic
Decimal arithmetic can be performed by combining the binary arithmetic
instructions ADD, SUB, MUL, and DIV (discussed in “Binary Arithmetic Instructions”)
with the decimal arithmetic instructions.
DAA Decimal adjust after addition
DAS Decimal adjust after subtraction
AAA ASCII adjust after addition
4. Logic Instructions
The logical instructions AND, OR, XOR (exclusive or), and NOT perform the standard
Boolean operations for which they are named. The AND, OR, and XOR instructions
require two operands; the NOT instruction operates on a single operand.
AND And
OR Or
XOR Exclusive or
NOT Not
5. Shift and Rotate Instructions
The shift and rotate instructions rearrange the bits within an operand. These
instructions fall into the following classes: • Shift. • Double shift • Rotate
SAR Shift arithmetic right
SHR Shift logical right
SAL/SHL Shift arithmetic left/Shift logical left
6. Bit and Byte Instructions
The bit and byte instructions operate on bit or byte strings. They are divided into
four groups: • Bit test and modify instructions. • Bit scan instructions. • Byte set on
condition. • Test.
BT Bit test
BTS Bit test and set
BTR Bit test and reset
SETS Set byte if sign (negative)
SETNS Set byte if not sign (non-negative)
SETO Set byte if overflow
SETNO Set byte if not overflow
7. Control Transfer Instructions
The processor provides both conditional and unconditional control transfer
instructions to direct the flow of program execution. Conditional transfers are taken
only for specified states of the status flags in the EFLAGS register. Unconditional
control transfers are always executed.
JMP Jump
JE/JZ Jump if equal/Jump if zero
JNE/JNZ Jump if not equal/Jump if not zero
16
JC Jump if carry
JNC Jump if not carry
JO Jump if overflow
MMX Technology Instructions
1. MMX Data Transfer Instructions
MOVD Move doubleword
MOVQ Move quadword
2. MMX Packed Arithmetic Instructions
PADDB Add packed bytes
PADDW Add packed words
PADDD Add packed doublewords
PSUBB Subtract packed bytes
PSUBW Subtract packed words
PSUBD Subtract packed doublewords
3. MMX Comparison Instructions
PCMPEQB Compare packed bytes for equal
PCMPEQW Compare packed words for equal
PCMPEQD Compare packed doublewords for equal
4. MMX Logic Instructions
PAND Bitwise logical and
PANDN Bitwise logical and not
POR Bitwise logical or
PXOR Bitwise logical exclusive or
5. MMX State Management
EMMS Empty MMX state
Floating-Point Instructions
1. Data Transfer
FLD Load real
FST Store real
FILD Load integer
FIST Store integer
2. Basic Arithmetic
FADD Add real
FIADD Add integer
FSUB Subtract real
FISUB Subtract integer FSUBR Subtract real reverse
3. Comparison
FCOM Compare real
FCOMP Compare real and pop
FICOM Compare integer
FICOMP Compare integer and pop
4. FPU Control
FFREE Free floating-point register
FNINIT Initialize FPU without checking error conditions
FFREE Free floating-point register
FINCSTP Increment FPU register stack pointer
17
UNIT 2 HIGH PERFORMANCE RISC ARCHITECTURE – ARM
1. Define Pipelining.
Starting the execution of next instruction before the current instructionexecution is
finished with the available hardware resources is calledpipelining. This is achieved by
splitting the execution of each instruction formore than one stage and allocating
appropriate hardware for each stage. Toimprove the utilization of hardware resources, and
also the processorthroughput, pipelining organization is implemented.
6. Mention the features of RISC which are used and rejected in ARMprocessors.
Features used:
Load store architecture2. Fixed-length 32-bit instructions3. 3-address instruction
formats.
Features rejected:
Register windows2. Delayed branches3. Single cycle execution of all instructions.
18
7. List the types of ARM instructions.
All ARM instructions fall into one of the following three categories:1.
Data processing instructions.2. Data transfer instructions3. Control flow instructions
8. Define supervisor mode.
The ARM processor supports a protected supervisor mode. The
protectionmechanism ensures that user code cannot gain supervisor privileges
withoutappropriate checks being carried out to ensure that the code is notattempting
illegal operations. These functions generally include any accessesto hardware peripheral
registers, and to widely used operations such ascharacter input and output.
12. What are the factors considered to view breaks in ARM pipeline.
The simplest way to view breaks in the ARM pipeline is to observe that:
• All instructions occupy the data-path for one or more adjacent cycles.
• For each cycle that an instruction occupies the data-path, it occupies thedecode
logic in the immediately preceding cycle.
• During the first data-path cycle each instruction issues a fetch for thenext
instruction but one.
• Branch instructions flush and refill the instruction pipeline
PART B
Barrel Shifter:
Data processing instructions are processed within the arithmetic logic unit (ALU). A
unique and powerful feature of the ARM processor is the ability to shift the 32-bit binary
pattern in one of the source registers left or right by a specific number of positions before it
20
enters the ALU. This shift increases the power and flexibility of many data processing
operations.
There are data processing instructions that do not use the barrel shift, for example,
the MUL (multiply), CLZ (count leading zeros), and QADD (signed saturated 32-bit add)
instructions.
i) Move Instructions : Move instruction copies R into a destination register Rd, where R
is a register or immediate value. This instruction is useful for setting initial values and
transferring data between registers.
Example1 : PRE r5 = 5
r7 = 8
MOV r7, r5 ;
POST r5 = 5
r7 = 5
The MOV instruction takes the contents of register r5 and copies them into register r7.
Arithmetic Instructions : The arithmetic instructions implement addition and subtraction
of 32-bit signed and unsigned values. the various addition and subtraction instructions are
given in table below.
SUB r0, r1, r2 ; This subtract instruction subtracts a value stored in register r2 from a
value stored in register r1. The result is stored in register r0.
RSB r0, r1, #0 ; This reverse subtract instruction (RSB) subtracts r1 from the constant
value #0, writing. the result to r0. You can use this instruction to negate numbers.
SUBS r1, r1, #1 ; The SUBS instruction is useful for decrementing loop counters. In this
example we subtract the immediate value one from the value one stored in
register r1. The result value zero is written to register r1.
Logical Instructions : These Logical instructions perform bitwise logical operations on the
wo source registers.
21
BIC r0, r1, r2 ; BIC, carries out a logical bit clear. register r2 contains a binary pattern
where every binary 1 in r2 clears a corresponding bit location in register r1. This
instruction is particularly useful when clearing status bits and is frequently used to change
interrupt masks in the cpsr.
Branch Instructions: A branch instruction changes the normal flow of execution of a main
program or is used to call a subroutine routine. This type of instruction allows programs
to have subroutines, if-then-else structures, and loops. The change of execution flow forces
the program counter pc to point to a new address.
The branch with link, or BL, instruction is similar to the B instruction but overwrites
the link register lr with a return address. It performs a subroutine call.
22
BL subroutine ; branch to subroutine
CMP r1, #5 ; compare r1 with 5
MOVEQ r1, #0 ; if (r1==5) then r1 = 0 :
Subroutine
MOV pc, lr ; return by moving pc = lr
The Branch Exchange (BX) and Branch Exchange with Link (BLX) are the third type of
branch instruction. The BX instruction uses an absolute address stored in register Rm. It is
primarily used to branch to and from Thumb code. The T bit in the cpsr is updated by the
least significant bit of the branch register. Similarly the BLX instruction updates the T bit of
the cpsr with the least significant bit and additionally sets the link register with the return
address.
The details of the branch instructions are given in the table above.
Single-register transfer
Multiple-register transfer, and
Swap.
Single-Register Transfer : These instructions are used for moving a single data item in
and out of a register. The data types supported are signed and unsigned words (32-bit),
half-words (16-bit), and bytes. Ex1: STR r0, [r1] ; = STR r0, [r1, #0] ; store the contents
of register r0 to the memory address pointed to by register r1.
Example 1: LDMIA r0!, {r1-r3} ; In this example, register r0 is the base register Rn and is
followed by !, indicating that the register is updated after the instruction is executed. In this
case the range is from register r1 to r3.
Stack Operations : The ARM architecture uses the load-store multiple instructions to
carry out stack operations. The pop operation (removing data from a stack) uses a load
multiple instruction; similarly, the push operation (placing data onto the stack) uses a store
multiple instruction.
A stack is either ascending (A) or descending (D). Ascending stacks grow towards
higher memory addresses; in contrast, descending stacks which grow towards lower
memory addresses. When a full stack (F)is used , the stack pointer sp points to an address
that is the last used or full location (i.e., sp points to the last item on the stack). In contrast,
if an empty stack (E) is used , the sp points to an address that is the first unused or empty
location (i.e., it points after the last item on the stack).
Swap Instruction :
24
Program Status Register Instructions : There are two instructions available to directly
control a program status register (PSR). The MRS instruction transfers the contents of
either the CPSR or SPSR into a register.Similarly the MSR instruction transfers the contents
of a register into the CPSR or SPSR .These instructions together are used to read and
write the CPSR and SPSR.
MRS : copy program status register to a general-purpose register , Rd= PSR
MSR : move a general-purpose register to a program status register, PSR[field]=Rm
MSR : move an immediate value to a program status register, PSR[field]=immediate
Loading Constants : In ARM instruction set there are no instructions to move the 32-bit
constant into a register. Since ARM instructions are 32 bits in size, they obviously cannot
specify a general 32-bit constant. To overcome this problem .two pseudo instructions are
provided to move a 32-bit value into a register.
LDR : load constant pseudo instruction Rd= 32-bit constant.
ADR : load address pseudo instruction Rd=32-bit relative address.
The first pseudo instruction writes a 32-bit constant to a register using whatever
instructions are available.
The second pseudo instruction writes a relative address into a register, which will be
encoded using a PC -relative expression.
25
From the above example it is clear that the Thumb code is more denser than the
ARM code.
Exceptions generated during Thumb execution switch to ARM execution before
executing the exception handler . The state of the T bit is preserved in the SPSR, and the LR
of the exception mode is set so that the normal return instruction performs correctly,
regardless of whether the exception occurred during ARM or Thumb execution.
In Thumb state, all the registers can not be accessed . Only the low registers r0 to r7 can be
accessed. The higher registers r8 to r12 are only accessible with MOV, ADD, or CMP
instructions. CMP and all the data processing instructions that operate on low registers
update the condition flags in the CPSR.The list of registers and their accessibility in Thumb
mode are shown in the following table..
Form the above discussion, it is clear that there are no MSR and MRS equivalent
Thumb instructions. To alter the CPSR or SPSR , one must switch into ARM state to use
MSR and MRS. Similarly, there are no coprocessor instructions in Thumb state. You need to
be in ARM state to access the coprocessor for configuring cache and memory management.
ARM-Thumb interworking is the method of linking ARM and Thumb code together
for both assembly and C/C++. It handles the transition between the two states. To call a
Thumb routine from an ARM routine, the core has to change state. This is done with the T
bit of CPSR . The BX and BLX branch instructions cause a switch between ARM and Thumb
26
state while branching to a routine. The BX lr instruction returns from a routine, also with a
state switch if necessary.
The data processing instructions manipulate data within registers. They include
move instructions, arithmetic instructions, shifts, logical instructions, comparison
instructions, and multiply instructions. The Thumb data processing instructions are a
subset of the ARM data processing instructions.
Note : Thumb deviates from the ARM style in that the barrel shift operations (ASR, LSL,
LSR, and ROR) are separate instructions.
ARM Registers : ARM has a total of 37 registers .In which - 31 are general-purpose
registers of 32-bits, and six status registers .But all these registers are not seen at once.
The processor state and operating mode decide which registers are available to the
programmer. At any time, among the 31 general purpose registers only 16 registers are
available to the user. The remaining 15 registers are used to speed up exception
processing. there are two program status registers: CPSR and SPSR (the current and saved
program status registers, respectively
In ARM state the registers r0 to r13 are orthogonal—any instruction that you can apply to
r0 you can equally well apply to any of the other registers.The main bank of 16 registers is
used by all unprivileged code. These are the User mode registers. User mode is different
from all other modes as it is unprivileged. In addition to this register bank ,there is also one
32-bit Current Program status Register(CPSR)
28
In the 15 registers ,the r13 acts as a stack pointer register and r14 acts as a link
register and r15 acts as a program counter register.
Register r13 is the sp register ,and it is used to store the address of the stack top.
R13 is used by the PUSH and POP instructions in T variants, and by the SRS and RFE
instructions from ARMv6.
Register 14 is the Link Register (LR). This register holds the address of the next
instruction after a Branch and Link (BL or BLX) instruction, which is the instruction used to
make a subroutine call. It is also used for return address information on entry to exception
modes. At all other times, R14 can be used as a general-purpose register.
Register 15 is the Program Counter (PC). It can be used in most instructions as a pointer to
the instruction which is two instructions after the instruction being executed.
29
The remaining 13 registers have no special hardware purpose.
CPSR : The ARM core uses the CPSR register to monitor and control internal operations.
The CPSR is a dedicated 32-bit register and resides in the register file. The CPSR is divided
into four fields, each of 8 bits wide : flags, status, extension, and control. The extension and
status fields are reserved for future use. The control field contains the processor mode,
state, and interrupt mask bits. The flags field contains the condition flags. The 32-bit CPSR
register is shown below.
Processor Modes: There are seven processor modes .Six privileged modes abort, fast
interrupt request, interrupt request, supervisor, system, and undefined and one non-
privileged mode called user mode.The processor enters abort mode when there is a failed
attempt to access memory. Fast interrupt request and interrupt request modes correspond
to the two interrupt levels available on the ARM processor. Supervisor mode is the mode
that the processor is in after reset and is generally the mode that an operating system
kernel operates in. System mode is a special version of user mode that allows full read-
write access to the CPSR. Undefined mode is used when the processor encounters an
instruction that is undefined or not supported by the implementation. User mode is used
for programs and applications.
Banked Registers : Out of the 32 registers , 20 registers are hidden from a program at
different times. These registers are called banked registers and are identified by the
shading in the diagram. They are available only when the processor is in a particular
mode; for example, abort mode has banked registers r13_abt , r14_abt and spsr _abt.
Banked registers of a particular mode are denoted by an underline character post-fixed to
the mode mnemonic or _mode.
When the T bit is 1, then the processor is in Thumb state. To change states the core
executes a specialized branch instruction and when T= 0 the processor is in ARM state and
executes ARM instructions. There are two interrupt request levels available on the ARM
processor core—interrupt request (IRQ) and fast interrupt request (FIQ).
30
used to indicate equality
N (Negative) : This bit is set when the bit 31 of the result is a binary 1.
The ARM7 processor has a three stage pipelining architecture namely Fetch , Decode and
Execute.And the ARM 9 has five stage Pipe line architecture.The three stage pipelining is
explained as below.
To explain the pipelining ,let us consider that there are three instructions Compare,
Subtract and Add.The ARM7 processor fetches the first instruction CMP in the first cycle
and during the second cycle it decodes the CMP instruction and at the same time it will
fetch the SUB instruction. During the third cycle it executes the CMP instruction , while
decoding the SUB instruction and also at the same time will fetch the third instruction ADD.
This will improve the speed of operation. This leads to the concept of parallel processing
.This pipeline example is shown in the following diagram.
31
As the pipeline length increases, the amount of work done at each stage is reduced, which
allows the processor to attain a higher operating frequency. This in turn increases the
performance. One important feature of this pipeline is the execution of a branch
instruction or branching by the direct modification of the PC causes the ARM core to flush
its pipeline.
32
Software Interrupt SWI 0X00000008 0Xffff0008
Pre-fetch Abort PABT 0X0000000C 0Xffff000c
Data Abort DABT 0X00000010 0Xffff0010
Reserved --- 0X00000014 0Xffff0014
Interrupt Request IRQ 0X00000018 0Xffff0018
Fast Interrupt Request FIQ 0X0000001C 0Xffff001c
The exception Vector table shown above gives the address of the subroutine
program to be executed when the exception or interrupt occurs. Each vector table entry
contains a form of branch instruction pointing to the start of a specific routine.Reset vector
is the location of the first instruction executed by the processor when power is applied.
This instruction branches to the initialization code.Undefined instruction vector is used
when the processor cannot decode an instruction.
Software interrupt vector is called when you execute a SWI instruction. The SWI
instruction is frequently used as the mechanism to invoke an operating system routine.Pre-
fetch abort vector occurs when the processor attempts to fetch an instruction from an
address without the correct access permissions. The actual abort occurs in the decode
stage.
Data abort vector is similar to a prefetch abort but is raised when an instruction
attempts to access data memory without the correct access permissions.Interrupt request
vector is used by external hardware to interrupt the normal execution flow of the
processor. It can only be raised if IRQs are not masked in the CPSR
33
UNIT III ARM APPLICATION DEVELOPMENT
PART A
1. What is Firmware?
The firmware is the deeply embedded, low-level software that provides an interface
between the hardware and the application/operating system level software. It resides in
the ROM and executes when power is applied to the embedded hardware system.
2. What is Bootloader?
The bootloader is a small application that installs the operating system or application
onto a hardware target. The bootloader only exists up to the point that the operating
system or application is executing, and it is commonly incorporated into the firmware.
6. What is an Exception?
An exception is any condition that needs to halt the normal sequential execution of
instructions.
34
9. Define: Virtual Memory?
virtual memory is a memory management technique that is implemented using
both hardware and software. It maps memory addresses used by a program, called virtual
addresses, into physical addresses in computer memory.
13. State the difference between logical and physical cache memories.
A logical cache stores data in a virtual address space. A logical cache is located
between the processor and the MMU. The processor can access data from a logical cache
directly without going through the MMU. A logical cache is also known as a virtual cache.
A physical cache stores memory using physical addresses. A physical cache is
located between the MMU and main memory. For the processor to access memory, the
MMU must first translate the virtual address to a physical address before the cache
memory can provide data to the core.
• ARM C compiler.
• ARM assembler.
• The linker.
• ARM symbolic debugger.
• ARMulator.
35
• Highly dense 16-bit compressed representation of the instruction setin the Thumb
architecture.
PART B
An event external to the currently executing process that causes a change in the normal
flow of instruction execution; usually generated by hardware devices external to the CPU is
known as interrupt.
Disable interrupt/s—When the IRQ exception is raised, the ARM processor will disable
further IRQ exceptions from occurring.
Save context—On entry the handler code saves a subset of the current processor mode
nonbanked registers.
Interrupt handler—The handler then identifies the external interrupt source and executes
the appropriate interrupt service routine (ISR).
36
Interrupt service routine—The ISR services the external interrupt source and resets the
interrupt.
Restore context—The ISR returns back to the interrupt handler, which restores the
context.
Enable interrupts—Finally, to return from the interrupt handler, the spsr_{interrupt
request mode} is restored back into the cpsr.
37
Nested interrupt handling summery:
• Handle multiple interrupts without a priority assignment.
• Medium or high interrupt latency.
• Enable interrupts before the servicing of an individual interrupt is complete.
• No prioritization, so low priority interrupts can block higher priority interrupts.
38
the coefficients ci are referred as the impulse response. If you feed the impulse signal x =
(1, 0, 0, 0, . . .) into the filter, then the output is the signal of filter coefficients y = (c0, c1, c2, .
. .).
Generally X[t ] and C[i] are k-bit integers and A[t ] is a 2k-bit integer, where k = 8, 16, or 32.
For a long filter, each result A[t ] depends on M data values and M coefficients that we must
read from memory. These loads are time consuming, and it is inefficient to calculate just a
single result A[t ]. While we are loading the data and coefficients, we can calculate A[t + 1]
and possibly A[t + 2] at the same time.
An R ×S block filter is an R-way block filter where we read S data and coefficient
values at a time for each iteration of the inner loop. On each loop we accumulate R × S
products onto the R accumulators.
Figure 8.3 shows a typical 4 × 3 block filter implementation. Each accumulator on
the left is the sum of products of the coefficients on the right multiplied by the signal value
heading each column. The diagram starts with the oldest sample Xt−M+1 since the filter
routine will load samples in increasing order of memory address. Each inner loop of a 4 × 3
filter accumulates the 12 products in a 4 × 3 parallelogram. We’ve shaded the first
parallelogram and the first sample of the third parallelogram.
39
Summary Writing FIR Filters on the ARM
If the number of FIR coefficients is small enough, then hold the coefficients and history
samples in registers. Often coefficients are repeated. This will save on the number of
registers you need.
If the FIR filter length is long, then use a block filter algorithm of size R × (R − 1) or R ×R.
Choose the largest R possible given the 14 available general purpose registers on the
ARM.
Ensure that the input arrays are aligned to the access size. This will be 64-bit when
using LDRD. Ensure that the array length is a multiple of the block size.
Schedule to avoid all load-use and multiply-use interlocks.
IIR Filters
An infinite impulse response (IIR) filter is a digital filter that depends linearly on a finite
number of input samples and a finite number of previous filter outputs. In other words, it
combines a FIR filter with feedback from previous filter outputs. Mathematically, for some
coefficients bi and aj :
If you feed in the impulse signal x = (1, 0, 0, 0, . . .), then yt may oscillate forever. This is why
it has an infinite impulse response. However, for a stable filter, yt will decay to zero.
an IIR filter with M = L = 2:
We can implement any IIR filter by repeatedly filtering the data by a number of biquads. To
see this, we use the z-transform. This transform associates with each signal xt ,
a polynomial x(z) defined as
Equivalently,
In other words, we perform the feedback part of the filter before the FIR part of the filter.
Equivalently we apply the denominator of H(z) before the numerator. Now each biquad
filter requires a state of only two values, st−1 and st−2. we have reduced an IIR to filtering
by a series of biquads of the form
40
Summary Implementing 16-bit IIR Filters
Factorize the IIR into a series of biquads. Choose the data precision so there can be no
overflow during the IIR calculation. To compute the maximum gain of an IIR, apply the
IIR to an impulse to generate the impulse response.
Use a block IIR algorithm, dividing the signal to be filtered into large frames.
On each pass of the sample frame, filter by M biquads. Choose M to be the largest
number of biquads so that you can hold the state and coefficients in the 14 available
registers on the ARM. Ensure that the total number of biquads is a multiple of M.
As always, schedule code to avoid load and multiply use interlocks.
Page Tables
The ARM MMU hardware has a multilevel page table architecture. There are two
levels of page table: level 1 (L1) and level 2 (L2).
41
misses in hardware by searching the page tables in main memory for valid translations and
loading them into one of the 64 lines in the TLB. The search for valid translations in the
page tables is known as a page table walk.
42
Domains control basic access to virtual memory by isolating one area of memory from
another when sharing a common virtual memory map. There are 16 different domains that
can be assigned to 1 MB sections of virtual memory and are assigned to a section by setting
the domain bit field in the master L1 PTE
43
free the processor core and cache memory from the slow write time associated with
writing to main memory.
44
SLOS is designed to execute on an ARM7TDMI core with no memory management
unit or protection unit. It is assumed that the memory map has already been configured by
the initialization code. SRAM is required to be located between 0x00000000 to
0x00080000, and the base configuration registers must be set to address 0x03ff0000. SLOS
is loaded at address 0x00000000, where the vector table is located. This is the same
address as the entry point into SLOS.
In this current configuration, SLOS includes three tasks and two service routines.
Tasks 1 and 2 provide an example of mutual exclusion using a binary semaphore. The two
service routines implemented are the periodic timer (which is essential) and a push-button
interrupt (which is optional). Task 3 provides a simple command line interface through one
of the ARM Evaluator-7T’s serial ports.
Initialization
There are three main stages of initializing SLOS—startup, executing process control
block (PCB) setup code, and executing the C initialization code. The startup code sets up the
FIQ registers and the system, SVC, and IRQ mode stacks. In the next stage, the PCB, which
contains the state of each task, is set up, including all the ARM registers. It is used to store
and restore task state during a context switch. The setup code sets the process control
block to an initial start state. The final C initialization stage calls the device driver, event
handler, and periodic timer initialization routines. Once complete, the first task can be
invoked.
Memory Model
We have adopted a simple memory model for SLOS. Figure 11.2 shows that the code
portion of SLOS, including the tasks, are located in low memory, and the stacks for the IRQ
and for each task are located in higher memory.
45
Interrupts and Exceptions Handling
In this implementation of the operating system only three exceptions are actually
used. The other exceptions are ignored by going to specific dummy handlers, which for
safety reasons are implemented as infinite loops.
Scheduler
The low-level scheduler, or dispatcher, used in SLOS is a simple static round-robin
algorithm as illustrated in the following pseudocode. “Static” in this case means that the
tasks are only created when the operating system is initialized.
Context Switch
Using the updated information produced by the scheduler, the context switch then
swaps the active task t with the next task t _. To achieve this, a context switch splits the
activity into two stages, as shown in Figure 11.4. The first stage involves saving the
processor registers into the current task t PCB pointed by PCB_PtrCurrentTask. The second
stage loads the registers with data from the next t_ PCB pointed by PCB_PtrNextTask.
46
Relationship that a cache has with main memory system and the processor core
47
If a cached core supports virtual memory, it can be located between the core and the
memory management unit (MMU), or between the MMU and physical memory.
A logical cache stores data in a virtual address space. A logical cache is located
between the processor and the MMU. The processor can access data from a logical cache
directly without going through the MMU. A logical cache is also known as a virtual cache.
A physical cache stores memory using physical addresses. A physical cache is
located between the MMU and main memory. For the processor to access memory, the
MMU must first translate the virtual address to a physical address before the cache
memory can provide data to the core.
Cache Architecture
ARM uses two bus architectures in its cached cores, the Von Neumann and the
Harvard. The Von Neumann and Harvard bus architectures differ in the separation of the
instruction and data paths between the core and memory.
In processor cores using the Von Neumann architecture, there is a single cache used
for instruction and data. This type of cache is known as a unified cache. A unified cache
memory contains both instruction and data values.
The Harvard architecture has separate instruction and data buses to improve
overall system performance, but supporting the two buses requires two caches.
In processor cores using the Harvard architecture, there are two caches: an
instruction cache (I-cache) and a data cache (D-cache). This type of cache is known as a
split cache.
We introduce the basic architecture of caches by showing a unified cache in Figure
12.4. The two main elements of a cache are the cache controller and the cache memory.
The cache memory is a dedicated memory array accessed in units called cache lines.
48
A simple cache memory is shown on the right side of Figure 12.4. It has three main
parts: a directory store, a data section, and status information. All three parts of the cache
memory are present for each cache line.
The cache must know where the information stored in a cache line originates from
in main memory. It uses a directory store to hold the address identifying where the cache
line was copied from main memory. The directory entry is known as a cache-tag.
The cache must know where the information stored in a cache line originates from
in main memory. It uses a directory store to hold the address identifying where the cache
line was copied from main memory. The directory entry is known as a cache-tag.
The size of a cache is defined as the actual code or data the cache can store from
main memory. Not included in the cache size is the cache memory required to support
cache-tags or status bits.
There are also status bits in cache memory to maintain state information. Two
common status bits are the valid bit and dirty bit.
A valid bit marks a cache line as active, meaning it contains live data originally taken
from main memory and is currently available to the processor core on demand.
A dirty bit defines whether or not a cache line contains data that is different from
the value it represents in main memory.
49
UNIT IV MOTOROLA 68HC11 MICROCONTROLLERS
PART A
50
5. Define Special test mode.
The special variation of the expanded mode is called special test mode. The special
test mode, which is intended primarily for factory testing, is seldom chosen by the
user except for emulation, development, or in other rare circumstances.
51
12. What is the function of IRQ’?
The IRQ input provides a means for requesting asynchronous interrupts to the
MC68HC11. IRQ’ is program selectable (OPTION register), having a choice of either
level-sensitive or falling-edge-sensitive triggering.
PART B
Features:
• It is a CISC microcontroller, optimized for low power consumption and high-
performance operation.
• The 68HC11 chip has built-in EEPROM/ROM, RAM, digital I/O, timers, A/D converter,
PWM (Pulse width modulator) generator, and synchronous and asynchronous
communications channels.
• The HCMOS MC68HC11 is an advanced 8-bit MCU with numerous on-chip peripheral
capabilities.
• Up to 10MIPS Throughput at 10MHz
• 256 Bytes of RAM , 512 Bytes of In-System Programmable EEPROM.
• Eight channel 8-bit Analog to Digital Convertor
• One serial peripheral interface, with a speed up to 1M (baud rate)
• The MC68HC11 is available in two packages .
• One is 48-pin dual inline package (DIP) and the other is the 52 Pin Plastic Leaded Chip
Carrier(PLCC) known as Lead quad pack.
52
• In the 48 pin DIP package 38 pins are available for I/O functions.(34 I/O lines+ 2
interrupt lines + 2 hand shake control lines).
• Similarly in a 52 PLCC pack 42 pins are meant for different I/O functions, and the
remaining are used for interrupt and handshake signals.
• MC68HC11 has one universal Asynchronous Serial Communications Interface (UART)
• Six powerful addressing modes (Immediate, Extended, Indexed, Inherent and Relative)
• Power saving STOP and WAIT modes
• Memory mapped I/O and special functions
From the figure , we see that the 68HC11 has a number of pins. Some of these pins are used
to control the micro-controller's operating mode, clock logic, special interrupts, or power.
The majority of the pins, however, have been organized into four 8-bit input/output ports.
These ports have the logical names PORTA, PORTB , PORTC, and PORTD. It is through these
four ports that the 68HC11 channels most of its interactions with the outside world.
The I/O ports and other device pins are connected to special subsystems in the 68HC11.
53
EPROM: Some versions of the 68HC11 have as much as 4 kilo-bytes of internal
EEPROM. If your program is sufficiently small, then your micro-controller system would
not need external memory chips and could be operated in single-chip mode.
RAM: The version of the 68HC11 in your MicroStamp11 has 256 bytes of internal RAM.
As mentioned above, some of these bytes are mapped into hardware registers that are
used to control the micro-controller. In reality the MicroStamp11 programmer only has
192 bytes of RAM that can be used for program variables.
Serial Peripheral Interface (SPI): This subsystem allows the 68HC11 to communicate
with synchronous serial devices such as serial/parallel slave devices.
Serial Communication Interface (SCI): This subsystem allows the 68HC11 to
communicate with asynchronous serial devices. The SCI interface is used to
communicate with laptop computers.
Parallel I/O Interface: There are 5 on chip I/O ports. They are: Port A , Port B , Port C,
Port D and Port E
Port A (8 bits): 1 bidirectional pin, 4 output pins, 3 input pins , Also used for timer.
Port B (8 bits): 8 output pins with optional handshaking , Also used as address in
expanded mode (replaced by PRU).
Port C (8 bits): 8 bidirectional pins with optional handshaking and wired-or mode
Also used as data/address in expanded mode (replaced by PRU).
Port D (6 bits): 6 bidirectional pins (controlled by direction register), Also used for
asynchronous (SCI) and synchronous serial (SPI) I/O.
Port E (8 bits): 8 input pins, Also used for A/D converter.
This subsystem selects whether the 68HC11 runs in expanded or single-chip mode.
Clock logic: An important feature of micro-controllers is that they work in real-time.
The clock logic subsystem provides the real-time clock for the 68HC11. The rate of the
clock is determined by a crystal that is connected to the clock logic pins. Interrupt
Logic: The interrupt logic subsystems provides three pins that can be used to trigger
hardware interrupts. A hardware interrupt automatically transfers software execution
to a specified memory address in response to the hardware event (such as the pin's
logic state going low).
Timer Interrupts: This subsystem generates interrupts that are associated with an
internal timer. Remember that the 68HC11 executes instructions in step with a clock
tick provided by the clock logic subsystem. With each tick of the clock, an internal
register called a timer is incremented. This timer is memory mapped to an address in
54
RAM with the logical name TCNT. SO at any instant you can fetch the current count
(time) on the timer by simply reading TCNT.
There are two types of interrupts associated with TCNT. An input-compare (IC)
interrupt is generated with a specified input pin changes state. When the IC interrupt
occurs, then the value in TCNT is stored in an input-compare register.
The other type of timer interrupt is called an output compare (OC) interrupt. The
output compare event occurs when TCNT matches the value stored in an output compare
register.
In the M68HC11 CPU, six addressing modes can be used to reference memory:
Immediate
Direct
Extended
Indexed (With Either Of Two 16-Bit Index Registers And An 8-Bit Offset),
Inherent
Relative
For example:
Load Immediate
LDAA #10 Loading a decimal value Loads the binary for 10, i.e., a value of
$0A into accumulator A
LDAA #$1C Loads the hexadecimal value $1C in A
LDAA #@03 Loads the octal value 3 into A
LDAA #%11101100 Loads a binary value
LDAA #’C’ Loads the ASCII code for the letter C
EXTENDED ADDRESSING MODE (EXT):
This addressing mode introduces the concept of the effective address of an
operand.
The effective address of an operand is the address in memory of the operand and
is usually a calculated value.
This mode also introduces the use of an instruction prebyte in the machine code
of the 68HC11. Instructions that require a prebyte take 4 bytes of memory.
Prebytes are either $18, $1A, or $CD Machine code and effect
55
DIRECT ADDRESSING (DIR):
In direct addressing the least significant byte of the 16-bit address of the operand is
in the instruction. The high order byte is taken to be $00. This is how you access the
256 bytes of RAM.
56
INHERENT (INH) ADDRESSING MODE:
In this addressing mode all the information required for execution is contained in
the instruction. No other operand is required.
Examples:
Increment an Accumulator (either A or B)
Accumulator A+Accumulator B Accumulator A
RELATIVE ADDRESSING MODE (REL):
Relative addressing is much like it sounds. The address is relative to something else.
In the case of the 68HC11 relative addressing mode is used only for branch instructions.
It is a 2 byte instruction with the second byte being the offset (-128 to +127) to take if
the condition is TRUE. When the condition is not met, execution continues with the next
instruction.
57
The value in the indexed register is added to an offset contained in the instruction to
obtain the effective address of the operand.
This is best seen by an example
58
Fig: SCI Transmitter Block Diagram
59
Whenever data is transferred into the shifter from the transmit buffer, a 0 is loaded into
the least significant bit (LSB) of the shifter to act as a start bit, and a logic 1 is loaded into
the last bit position to act as a stop bit. In the case of a preamble, the shifter is jammed to all
1s, including the bit position usually holding the logic 0 start bit.
A preamble is jammed each time the transmit enable bit is written from 0 to 1. In the
case of a send break command,the shifter is jammed to all 0s, including the last bit position
usually holding the logic 1 stop bit. enable bit is written from 0 to 1. In the case of a send
break command, the shifter is jammed to all 0s, including the last bit position usually
holding the logic 1 stop bit.
The T8 bit in SCI control register 1 (SCCR1) acts like an extra high-order bit (ninth bit)
of the transmit buffer register. This ninth bit is only used if the M bit in SCCR1 is 1 to select
the 9-bit data character format. The M bit also controls the length of idle and break
characters. The R8 and WAKE bits in SCCR1 are associated with the SCI receiver.
The TDRE and TC status flags in the SCI status register (SCSR) are automatically set by
the transmitter logic. These two bits can be read at any time by software. The transmit
interrupt enable (TIE) and transmit complete interrupt enable (TCIE) interrupt control bits
enable the TDRE and TC bits, respectively, to generate SCI interrupt requests.
SCI Receiver
The block diagram of the receiver section of the SCI subsystem is shown in the
figure below. SCI receive data comes in the RxD pin, is buffered, and drives the data
recovery block. The data recovery block is actually a high-speed shifter operating at 16
times the bit rate; whereas, the main-receive serial shifter operates at one times the bit
rate. This higher speed sample rate allows the start-bit leading edge to be located more
accurately than a 1×clock would allow. The high-speed clock also allows several samples to
be taken within a bit time so logic can make an intelligent decision about the logic sense of
a bit (even in the presence of noise). The data recovery block provides the bit level to the
main receiver shift register and also provides a noise flag status indication.
The heart of the receiver is the receive serial shift register. This shifter is enabled by
the receive enable (RE) bit from the SCI control register 2 (SCCR2). The M bit from the
SCCR1 register determines whether the shifter will be 10 or 11 bits long. After detecting
the stop bit of a character, the received data is transferred from the shifter to the SCDR, and
the receive data register full (RDRF) status flag is set. When a character is ready to be
transferred to the receive buffer but the previous character has not yet been read, an
overrun condition occurs. In the overrun condition, data is not transferred and the overrun
(OR) status flag is set to indicate the error.
The wakeup block uses the WAKE control bit from SCCR1 to decide whether to use
the most significant bit (MSB) signal (address mark) or the ALL 1s signal (idle line) to wake
up the receiver. When the selected condition is detected, the wakeup logic clears the
receiver wake-up (RWU) bit in SCCR2, which wakes up the receiver.
60
Fig: SCI Receiver Block Diagram
There are three receiver-related interrupt sources in the SCI. These flags can be
polled by software or optionally cause an SCI interrupt request. The receive interrupt
enable (RIE) control bit enables the RDRF and the OR status flags to generate hardware
interrupt requests. The idle line interrupt enable (ILIE) control bit allows the IDLE status
flag to generate SCI interrupt requests.
61
SCI Registers and Control Bits
The SCI system is configured and controlled by five registers (BAUD, SCCR1, SCCR2,
SCSR, and SCDR). In addition, the port D register, data direction register for port D (DDRD),
and the port D wired-OR mode bit in the SPI control register (SPCR) are secondarily related
to the SCI system.
62
The ideal transfer function of a 3-bit ADC
Full-scale (input voltage) range (FSR)
Analog signal is continuous
Digital – finite and discrete
In general n-bit converter
Total of 2n output codes
ADCTL register:
CCF: Conversions Complete Flag- This read-only status indicator is set when all four A/D
result registers contain valid conversion results. Each time the ADCTL register is written,
this bit is automatically cleared, and a new conversion sequence is started immediately.
Bit 6: Not implemented; always reads 0
SCAN: Continuous Scan Control Bit- When this bit is 0, the four requested conversions are
performed, once each, to fill the four result registers. When this bit is 1, conversions
continue in a round-robin fashion with the result registers being updated as new data
becomes available.
MULT: Multiple-Channel/Single-Channel Control Bit- When this bit is 0, the A/D system is
configured to perform four consecutive conversions on the single channel specified by the
four channel-select bits (CD:CA of the ADCTL register). When this control bit is 1, the A/D
system is configured to perform conversions on each
63
channel in the group of four channels specified by the CD and CC channel-select bits. In this
multiple-channel mode, each channel is associated with a specific result register.
CD, CC, CB, and CA — Channel Select Bits.
A/D PIN:
The below figure shows a model of an A/D input pin, which is useful in planning
external circuitry and connections.
64
loads, stores, and transfer instruction:
Arithmetic operations:
65
Multiply and divide:
66
Data testing and bit manipulation:
67
PROGRAM CONTROL INSTRUCTIONS:
Branches
Jumps
Subroutine calls and returns
Interrupt handling
Miscellaneous
Branch instructions:
Jump instructions:
68
Subroutine calls and returns:
Miscellaneous instructions:
69
UNIT V PIC MICROCONTROLLER
PART A
C = Carry bit
DC = Digit carry
Z = Zero bit NOT_TO and NOT_PD - Used in conjunction with PIC's sleep mode
RP0 = Register bank select bit used in conjunction with direct addressing mode.
70
6. Define Real Time Clock (RTC)?
Real time clock is a clock which once the system stats does not stop and can’t be
reset and its count value can’t be reloaded.
ADCON:
71
8. What does UART contain?
· A clock generator.
· Input and Output start Registers
· Buffers.
· Transmitter/Receiver control.
9. What is PIC?
PIC refers to Programmable Intelligent Computer. PIC is microprocessor lies inside a
personal computer but significantly simpler, smaller and cheaper. It can be used for
operating relays, measuring sensors etc.
PART B
1. Explain interrupts handing in PIC micro controller. (or) Describe the interrupt
structure of PIC microcontrollers.
If an interrupt occurs, it sets an S-R bistable. The occurrence of the interrupt,
even if it is only momentary, is thus recorded. The output of the bistable, the latched
version of the interrupt, is called the interrupt flag. This is then gated with an enable
signal, Interrupt X Enable. If this is high, then the interrupt signal progresses to an OR
gate. If it is low, the interrupt signal gets no further. If enabled, it is ORed with other
enabled interrupt inputs of the microcontroller. The OR gate output will go high if any
interrupt input is high. There is then a further gating of the OR gate output, this time
with a Global Interrupt Enable. Only if that value is high can any interrupt signal reach
the CPU. The action of disabling an interrupt is sometimes called masking.
72
• External interrupt. This is the only external interrupt input. It shares a pin with Port B, bit
0.
It is edge triggered.
• Timer overflow. This is an interrupt caused by the Timer 0 module. It occurs when the
timer’s 8-bit counter overflows.
• Port B interrupt on change. This interrupts when a change is detected on any of the
higher 4 bits of Port B.
• EEPROM write complete. This interrupts when a write instruction to the EEPROM
memory is completed and the SFR that controls it, INTCON.
73
Thus, the lines TOIF, INTF and so on are actually the interrupt flags, rather than the
interrupt inputs themselves. All can be seen as bits in the INTCON register, with the
exception of the EEPROM write complete flag and enable. The external interrupt is edge
triggered. The edge it responds to is controlled by the setting of the INTEDG bit of the
OPTION register.In general interrupt structure each flag is ANDed with a corresponding
Enable input (TOIE, INTE, RBIE and EEIE).
The enable bits are located in the INTCON register and can be set by the
programmer. The outputs of the four AND gates are then ORed together, before passing on
to the Global Enable gate. Interrupt flags must be cleared by manipulating their INTCON
bits in the program. The 16F84A has no non-maskable interrupt input.
The interrupt is therefore detected by the CPU and it executes a special section of
program called the Interrupt Service Routine (ISR). The ISR must start at the interrupt
vector, program memory location 0004.Therefore, when an interrupt occurs, this value is
loaded into the Program Counter and program execution then continues from the reset
vector.
In any processor, the ISR must end with a special ‘return from interrupt’ instruction.
In the 16 Series this is the retfie instruction. When this is detected, the CPU sets the GIE to
1, loads the Program Counter from the top of the Stack and then resumes program
execution. Thus, it returns to the instruction which follows the instruction during which the
interrupt was detected.
74
2. Describe the architecture of PIC micro controllers. (Or) Discuss the core
architectural features of PIC microcontrollers.
PIC stands for Peripheral Interface Controller given by Microchip Technology to
identify its single-chip microcontrollers.
Features:
1. Speed: Harvard Architecture, RISC Architecture
1 instruction Cycle = 4 clock cycles.
For 20 MHz clock, most of the instructions are executed in 0.2μs or
five instructions per microsecond.
2. Instruction Set Simplicity:
The instruction set consists of just 35 instructions (as opposed to 111
instructions for 8051)
3. Power on reset
Power-out reset
Watch-dog timer
Oscillator Options
• low-power Crystal
• Mid-range Crystal
• High-range Crystal
• RC Oscillator
4. Programmable timer options on chip ADC
5. Up to 12 independent interrupt sources
6. Powerful output pin control
25mA (max.) current sourcing capability.
7. EPROM/OTP/ROM/Flash memory options.
8. Free assembler and simulator support from microchip
CPU Architecture:
75
The block diagram mainly consists of CPU (Central Processing Unit), containing the
8-bit ALU (Arithmetic Logic Unit), the Working register ‘WREG’(sometimes called the
accumulator) and an 8-bit × 8-bit hardware multiply unit. CPU action is determined by the
instruction received from program memory, which is transferred through the Instruction
register.
The basic architecture of PIC16C74A is shown in the above figure. The architecture
consists of Program memory, file registers and RAM, ALU and CPU registers. The program
Counter is 13 - bit and the program memory is organized as 14 - bit word. Hence the
program Memory capacity is 8k x 14 bit. Each instruction of PIC 16C74A is 14 - bit long.
CPU registers (registers commonly used by the CPU)
W, the working register, is used by many instructions as the source of an operand. This is
similar to accumulator in 8051. It may also serve as the destination for the result of the
instruction execution. It is an 8 - bit register.
STATUS Register
The STATUS register is a 8-bit register that stores the status of the processor. This also
stores carry, zero and digit carry bits.
STATUS - address 03H, 83H
76
Fig: STATUS Register
C = Carry bit
DC = Digit carry
Z = Zero bit NOT_TO and NOT_PD - Used in conjunction with PIC's sleep mode
RP0 = Register bank select bit used in conjunction with direct addressing
mode.
FSR Register
(File Selection Register, address = 04H, 84H) FSR is an 8-bit register used as data memory
address pointer. This is used in indirect addressing mode.
INDF Register
(INDirect through FSR, address = 00H, 80H) INDF is not a physical register. Accessing INDF
access is the location pointed to by FSR in indirect addressing mode.
PCL Register
(Program Counter Low Byte, address = 02H, 82H) PCL is actually the lower 8-bits of the 13-
bit program counter. This is a both readable and writable register.
PCLATH Register
(Program Counter Latch, address = 0AH, 8AH) PCLATH is a 8-bit register which can
be used to decide the upper 5bits of the program counter. PCLATH is not the upper 5bits of
the program counter. PCLATH can be read from or written to without affecting the program
counter. The upper 3bits of PCLATH remain zero and they serve no purpose. When PCL is
written to, the lower 5bits of PCLATH are automatically loaded to the upper 5bits of the
program counter, as shown in the following figure.
77
interrupts remain disabled. Hence, other 7 registers of the stack can be used for subroutine
calls within an interrupt service routine or within the mainline program.
Register File Map
Some of the special purpose registers are available both in Bank-0 and Bank-1.
These registers have the same value in both banks. Changing the register content in one
bank automatically changes its content in the other bank.
3. Describe the features of UART and A/D converter in PIC micro controller. Analog-
to-Digital Converter
Features (16C7X)
78
Port A and Port E pins are used for analog inputs/ Reference voltage for ADC.
Port A pins
RA0/AN0 - Can be used as analog input-0
RA1/AN1 - Can be used as analog input-1
RA2/AN2 - Can be used as analog input-2
RA3/AN3/VREF - RA3 can be used as analog input 3 or analog reference voltage
RA4/TOCKI - RA4 can be used as clock input to Timer-0
RA5/SS/AN4 - RA5 can be used as analog input 4 or the slave select for the sync serial port
Port E pins
RE0/RD/AN5 - Can be used as analog input 5
RE1/WR/AN6 - Can be used as analog input 6
RE2/CS/AN7 - Can be used as analog input 7
PIC microcontroller has internal sample and hold circuit. The input signal should be
stable across the capacitor before the conversion is initiated.
After waiting out the sampling time, a conversion can be initiated. The ADC circuit will
open the sampling switch and carry out the conversion of the input voltage as it was at the
79
moment of opening of the switch. Upon completion of the conversion, the sampling switch
is closed and VHOLD again tracks VSOURCE.
Registers ADCON1, TRISA, and TRISE must be initialized to select the reference
voltage and the input channels. The first step selects the ADC clock source from among four
choices (OSC/2, OSC/8, OSC/32, and RC).
The A/D modules has three registers. These registers are
• A/D Result Register (ADRES)
• A/D Control Register 0 (ADCONO)
• A/D Control Register 1 (ADCON1)
The ADCONO register as shown here, controls the operation of A/D module.
80
Fig.: ADCON1 Register
4. Explain I2C interfacing with PIC micro controller (or) Explain the data
communication protocol of I2C bus.
I2C is Inter Integrated Circuit which requires two open-drain I/O pins. Port-C of PIC
IC can be used for I2C communication.
SCL (Serial Clock) RC3/SCK/SCL
SDA (Serial Data) RC4/SDI/SDA
Low output on SCL or SDA I/O pin set to be an output with ”0” written to it.
High output on SCL or SDA I/O pin set to be an input.
Transfers on the I2C bus take place a bit at a time.
81
The clock line, SCL, is driven by the PIC chip, which server as bus master. The open drain
feature of every chip’s bus driver can be used by the receiver to hold the clock line low,
there by signaling the transmitter to pause until the clock line is released by the receiver.
The open drain feature is also needed if this PIC will ever become an I2C slave to another
PIC, in which it must relinquish control of the SCL line. The last figure illustrates that the
first eight bits on the SDA line are sent by the transmitter whereas the ninth bit is the
acknowledgment bit which is sent by the receiver in response to the byte sent by the
transmitter.
When the PIC sends out a chip address, it is the transmitter, while every other chip
on the I2C bus is a receiver. During the acknowledgment bit time, the addressed chip is the
only one that drives the SDA line, pulling it low in response to the masters pulse on SCL,
acknowledging the reception of its chip address.
When the data transfer direction is reversed that is form a peripheral chip to the
PIC, which is the master, the peripheral chip drives the eight data bits in response to the
clock pulse from PIC.
In this case, the acknowledge bit is driven in a special way by the PIC, which is
serving as receive but also as bus master. If the peripheral chip is one that can send the
contents of successive internal address back to the PIC, then PIC completes the reception of
each byte and signals a request for the next byte by pulling SDA line low in
acknowledgment.
After any number of bytes have been received by the master from the peripheral,
the PIC can signal the peripheral to stop any further transfers by not pulling the SDA line
low in acknowledgment.
SDA line should be stable during high period of the clock (SCL). When the slave
peripheral is driving SDA line , either as transmiter or acknowledge, it initiates the new bit
in response to the falling edge of SCL, after a specified time. It maintains that bit on SDA line
until the next falling edge of SCL, again after a specified hold time.
I2C bus transfers consist of a number of byte transfers framed between a START
condition and either another START condition or a STOP condition. Both SDA and SCL lines
are released by all drives and float high when bus transfers are not taking place. The PIC
(I2C bus controller) initiates a transfer with a START condition by first pulling SDA low and
then pulling SCL as shown in the figure.
82
The PIC terminates a multiple byte transfer with the STOP condition. With both SDA
and SCL initially low, it first releases SCL and then SDA. Both then occurrences are easily
recognized by I2C hardware in each peripheral chip since they both consist of a chage in
SDA line which SCL is high, a condition that never happens in the middle of a byte transfer.
83
5. ii. Discuss in detail the organization of program and data memory of PIC
microcontrollers? PIC Memory Organisation:
Program Memory:
PIC microcontroller has 13 bits of program memory address. Hence it can address
up to 8k of program memory. The program counter is 13-bit. PIC 16C6X or 16C7X program
memory is 2k or 4k. While addressing 2k of program memory, only 11- bits are required.
Hence two most significant bits of the program counter are ignored. Similarly, while
addressing 4k of memory, 12 bits are required. Hence the MSB of the program counter is
ignored.
The program memory map of PIC16C74A is shown in Fig.2. On reset, the program
counter is cleared and the program starts at 00H. Here a 'go to' instruction is required that
takes the processor to the mainline program.
When a peripheral interrupt, that is enabled, is received, the processor goes to
004H. A suitable branching to the interrupt service routine (ISR) is written at 004H.
84
Data memory (Register Files):
Data Memory is also known as Register File. Register File consists of two components.
The special purpose register file consists of input/output ports and control
registers. Addressing from 00H to FFH requires 8 bits of address. However, the instructions
that use direct addressing modes in PIC to address these register files use 7 bits of
instruction only. Therefore the register bank select (RP0) bit in the STATUS register is used
to select one of the register banks.
In indirect addressing FSR register is used as a pointer to anywhere from 00H to FFH in the
data memory.
85