Unit 2 - Study Material
Unit 2 - Study Material
Prof. M. N. Kakatkar
Sinhgad College of Engineering
Syllabus
2
ARM7TDMI-S processor:
The ARM7TDMI-S is general purpose 32-bit microprocessor,
Due to their tiny size and low power consumption, ideal for
applications where miniaturization is a key requirement.
Architecture
5/18/2021
Buses
10
5/18/2021
ARM7 Based Microcontroller LPC2148:
system control block functions
11
PLL
Power Control
Reset
APB Divider
Wakeup Timer
5/18/2021
system control block functions…
12
The PLL1 has to supply the clock for the USB at the fixed
rate of 48 MHz.
PLL interrupts are only available for PLL0 and not for PLL1.
5/18/2021
system control block functions…
PLL…
13
5/18/2021
system control block functions…
PLL…
14
5/18/2021
system control block functions…
PLL…
15
Activation
Multiplier &
divider values
Control and
Configuration
Loading
Control and
Configuration
16
PLL Control register: (PLL0CON & PLL1CON)
bit description
7 6 5 4 3 2 1 0
R R R R R R PLLC PLLE
Values
written
to this
register
do not
take
effect
until a
valid PLL
feed
Sequence
has taken
place.
17
PLL Control register (PLL0CON - 0xE01F C080,
PLL1CON - 0xE01F C0A0)
18
5/18/2021
PLL Configuration register ( PLL0CFG & PLL1CHG ]
bit description
7 6 5 4 3 2 1 0
R19 PSEL PSEL MSEL MSEL MSEL MSEL MSEL
Values
written to
this
register
do not
take effect
until a valid
PLL feed
Sequence
has taken
place.
PLL Configuration register (PLL0CFG - 0xE01F C084,
PLL1CFG - 0xE01F C0A4)
20
5/18/2021
PLL Status register (PLL0STAT & PLL1STAT)
bit description
21
PLL Status register (PLL0STAT - 0xE01F C088, PLL1STAT -
0xE01F C0A8)
22
5/18/2021
PLL Feed register (PLL0FEED - 0xE01F C08C, PLL1FEED -
0xE01F C0AC)
23
5/18/2021
Elements Determining PLL’s frequency
M PLL Multiplier value from the MSEL bits in the PLLCFG register
P PLL Divider value from the PSEL bits in the PLLCFG register
7 6 5 4 3 2 1 0
R PSEL PSEL MSEL MSEL MSEL MSEL MSEL
0 0 1 0 0 1 0 0
31
32
PLL Interrupt
33
5/18/2021
GPIO…
34
5/18/2021
ARM7 Based Microcontroller LPC2148:
Pin connect block
35
5/18/2021
Pin connect block…
36
5/18/2021
Pin connect block…
37
5/18/2021
Pin connect block…
38
5/18/2021
Pin connect block…
39
5/18/2021
LPC 2148: System Memory Map
It has 4 GB address space (PC is 32
bit). LPC2148 has 32kB on chip SRAM
and 512 kB on chip FLASH memory. It
has inbuilt support up to 2kB end point
USB RAM also.
2. On chip SRAM
The LPC2148 provides 32 kB of static
RAM which may be used for code and/or
data storage. It may be accessed as 8-
bits, 16-bits, and 32-bits.
APB and AHB Peripherals
1. Both the AHB and APB peripheral
areas are 2 megabyte spaces which
are divided up into 128 peripherals
2. Each peripheral space is 16 kilobytes
Fig: System Memory Map in size 41
2 MB space
for AHP
Peripherals.
Divided into
128
peripherals
2 MB space
for AHB
Peripherals.
Divided into
128
peripherals
16 KB 42
ARM7 Based
Microcontroller
LPC2148:
43
Memory maps
5/18/2021
Memory maps…
44
5/18/2021
45
5/18/2021
ARM7 Based Microcontroller LPC2148:
Timer
46
Features:
A 32-bit Timer/Counter with a programmable 32-bit Prescaler.
5/18/2021
PCLK and VPDIV Register
• All of the timers are driven by PCLK which is the
Peripheral Clock. The system is generally driven by the
CCLK or Crystal Clock.
• PCLK is derived from CCLK which is the processor
clock.
• If CCLK = 60MHz, VPBDIV register determines the
rate of PCLK. VPBDIV is not the same as the prescaler
register although its action is similar.
• VPBDIV is an 8-bit register and only the lower two bits
of it are used as follows:
0x00; (PCLK) = ¼th (CCLK)
0x01; (PCLK) = (CCLK)
0x02; (PCLK) = ½th (CCLK)
VPBDIV register values 0x03; Reserved.
PCLK goes into a prescaler which further scales the clock going to the
timer. The output of the prescaler actually drives the timer register. 47
Timer
• No of Timers : 2 (Timer 0 & Timer 1)
• The Timer/Counter is designed to count cycles of the
peripheral clock (PCLK) or externally-supplied clock, and
• Can optionally generate interrupts or perform other
actions at specified timer values
49
Timer Registers Description
1) PR : Prescale Register (32 bit) – Stores the maximum value
of Prescale counter after which it is reset.
51
Timer Features
Four 32-bit match registers that allow:
– Continuous operation with optional interrupt
generation on match.
– Stop timer on match with optional interrupt
generation.
– Reset timer on match with optional interrupt
generation
Four external outputs corresponding to match
registers,
with the following capabilities:
– Set low on match.
– Set high on match.
– Toggle on match.
– Do nothing on match. 52
Match Registers
• What is a Match Register anyways ?
• Ans: A Match Register is a Register which
contains a specific value set by the user.
• When the Timer starts – every time after TC
is incremented the value in TC is compared
with match register.
• If it matches then it can Reset the Timer or
can generate an interrupt as defined by the
user.
• Match Registers can be used to:
– Stop Timer on Match and trigger an optional
interrupt.
– Reset Timer on Match and trigger an optional
interrupt.
– To count continuously and trigger an interrupt on
match.
53
Match Register
For MR0:
– Bit 0 : Interrupt on MR0 i.e trigger an interrupt when MR0 matches
TC. Interrupts are enabled when set to 1 and disabled when set to 0.
– Bit 1 : Reset on MR0. When set to 1 , TC will be reset when it
matched MR0. Disabled when set to 0.
– Bit 2 : Stop on MR0. When set to 1 , TC & PC will stop when MR0
matches TC.
– Similarly bits 3-5 , 6-8 , 9-11 are for MR1 , MR2 ,
MR3 respectively.
55
Timer…
Pin description…
56
Capture Registers
• What are Capture Registers ?
Ans: As the name suggests it is used to Capture
Input signal.
When a transition event occurs on a Capture pin
, it can be used to copy the value of TC into any
of the 4 Capture Register or to generate an
Interrupt.
• . CAP0.3..0 & CAP1.3..0 (Input)
Capture Signals- A transition on a this
(capture) pin is found, it loads one of the
Capture Registers with the value in the Timer
Counter and optionally generate an interrupt.
57
Capture Register
59
Timer Register Description
7) IR : Interrupt Register – It contains the interrupt flags for 4 match
and 4 capture interrupts.
a. Bit0 to bit3 are for MR0 to MR3 interrupts respectively.
b. And similarly the next 4 for CR0-3 interrupts.
c. when an interrupt is raised the corresponding bit in IR will be set to
1 and 0 otherwise.
d. Writing a 1 to the corresponding bit location will reset the interrupt
– which is used to acknowledge the completion of the corresponding
ISR execution.
Setting up & Use the following sequence for Setting up
configuring Timers : Timers:
1. To use timers we 1. Set appropriate value in TxCTCR
need to first configure 2. Define the Prescale value in TxPR
them. 3. Set Value(s) in Match Register(s) if
2. We need to set required
appropriate values in 4. Set appropriate value in TxMCR if using
TxCTCR, TxIR, TxPR Match registers / Interrupts
and reset TxPC, TxTC. 5. Reset Timer – Which resets PR and TC
Finally we assign 6. Set TxTCR to 0×01 to Enable the Timer
TxTCR = 0×01 which when required
enables the timer. 7. Reset TxTCR to 0×00 to Disable the
60
Timer when required
Timer Registers Basics
61
Implement of basic function required
for Timer Operation:
void initTimer0(void); Attention Plz! :
1. This function is used to
void initTimer0(void) setup and initialize the
{ Timer block.
/*Assuming that PLL0 has been 2. Timer blocks use
setup with CCLK = 60Mhz and peripheral clock as their
PCLK also = 60Mhz.*/ input and hence
peripheral clock must be
T0CTCR = 0x0; // Timer Mode initialized before Timer
Selected is initialized.
3. In our case it is
T0PR = PRESCALE-1;
assumed that LPC2148
//(Value in Decimal!) –
is connected to 12Mhz
// Increment T0TC at every 60000
XTAL and both CPU and
clock cycles//Count begins from zero
Peripheral Clocks have
hence subtracting 1//60000 clock
been setup to tick at
cycles @60Mhz = 1 mS
60Mhz.
T0TCR = 0x02; //Reset Timer & prescaler;
disable prescaler count; 0b0000 0010 62
}
Timer Calculations
1. The delay or time required for 1 clock cycle at ‘X’ MHz is
given by :
63
Delay program using timers
delayMS(unsigned int milliseconds);
Main Program 64
ARM instruction set
65 5/18/2021
ARM Instruction Set
66
Data processing
instructions
Data transfer
instructions
Block transfer
instructions
Branching instructions
Multiply instructions
Software interrupt
instructions
5/18/2021
The ARM Register Set
Current Visible Registers
r0
Abort
Undef
SVC
IRQ
FIQ
User Mode
Mode
Mode
Mode r1
r2
r3 Banked out Registers
r4
r5
r6 User FIQ IRQ SVC Undef Abort
r7
r8 r8 r8
r9 r9 r9
r10 r10 r10
r11 r11 r11
r12 r12 r12
r13 (sp) r13 (sp) r13 (sp) r13 (sp) r13 (sp) r13 (sp) r13 (sp)
r14 (lr) r14 (lr) r14 (lr) r14 (lr) r14 (lr) r14 (lr) r14 (lr)
r15 (pc)
cpsr
spsr spsr spsr spsr spsr spsr
Conditional Execution
68 5/18/2021
Data Processing Instruction
70 5/18/2021
Using and Updating the condition Field
71 5/18/2021
Using and Updating the condition Field
For
example to add two numbers and set the
condition flags:
ADDS r0, r1, r2 ; r0 = r1 + r2 and set flags
ADDEQS r1, r2,r3;
; r1 = r2 +r3 if equality condition satisfy
72 ; otherwise nop 5/18/2021
Data Processing Instruction
Arithmetic Operations
75 5/18/2021
Use of Barrel Shifter
76
5/18/2021
Barrel Shifter
77
5/18/2021
Shift Register Operands
78
5/18/2021
Register Transfer Instruction
81 5/18/2021
Comparison Instruction
Comparison Operations
Not produce result in registers; subtract the
destination from the source
Just set the condition code bits (N, Z, C and V) in
CPSR
CMP r1,r2 ; set cc on r1 - r2, compare
CMN r1,r2 ; set cc on r1 + r2, compare negated
TST r1,r2 ; set cc on r1 AND r2, bit test
TEQ r1,r2 ; set cc on r1 XOR r2, test equal
82 5/18/2021
Branch Instructions
Syntax
Branch: B{<cond>} Label
Branch is like jump unconditional.
Branch with Link: BL{<cond>}
subroutine_label
BL is like a call to subroutine.
84 5/18/2021
Examples of Branch Instructions
Call a subroutine
Unconditional jump BL SUB
B LABEL …
… SUB …
LABEL … MOV PC,r14
CMP r0,#5
CMP r0,#5
BEQ Bypass ;if (r0!=5)
ADDNE r1,r1,r0
ADD r1,r1,r0 ;{r1=r1+r0}
SUBNE r1,r1,r2
SUB r1,r1,r2
Bypass …
86 5/18/2021
Example of conditional execution
87 5/18/2021
Branch with Link and exchange
B{L}X{<cond>} Rm
90 5/18/2021
Loading Constants
91 5/18/2021
Loading 32-bit Constants
For example
MOV r0,=&FF ;MOV r0,#0xFF
92 5/18/2021
Load and Store Instructions
93 5/18/2021
Load and Store Instructions
94 5/18/2021
Indexing methods
95 5/18/2021
Indexing methods
96 5/18/2021
Multiple Register Data Transfer
97
5/18/2021
Load/ Store multiple
98
5/18/2021
Block Transfer Instructions with example
99
Mi
LDM Mi+1
R0 Mi+2
R1
R2
Mi+14
Mi+15
R14 STM
R15
5/18/2021
Multiple Register Data Transfer
100 5/18/2021
Stack operations
101 5/18/2021
Stack operations
102 5/18/2021
Swap Memory and Register Instructions
Syntax
SWP{<cond>}{B} Rd,Rm,[Rn]
Example
ADR r0,SEMAPHORE
SWPB r1,r1,[r0] ;exchange byte
103 5/18/2021
Status Register to General Register
Transfer instructions
Syntax
MRS{<cond>} Rd, CPSR|SPSR
Example
MRS r0,CPSR
MRS r3,SPSR
104 5/18/2021
General Register to Status Register
Transfer instructions
Syntax
MSR{<cond>} CPSR_<field>|SPSR_<field>,#<32-bit
immediate>
MSR{<cond>} CPSR_<field>|SPSR_<field>,Rm
<field> is one of
c – the control field PSR[7:0]
x – the extension field PSR[15:8]
s – the status field PSR[23:16]
f – the flag field PSR[31:24]
Example
Set N, X, C, V flags
MSR CPSR_f, #&f0000000
105 5/18/2021
Coprocessor Instructions
106 5/18/2021
Software Interrupt (SWI)
SWI{<cond>}<24-bit immediate>
Used for calls to the operating system and is often called a “supervisor
call”
The supervisor is a program which operates at a privileged level, which
means that it can do things that a use-level program cannot do directly
It puts the processor into supervisor mode and begins executing
instruction from address 0x08 (refer to P.21)
Save the address of the instruction after SWI in r14_svc
Save the CPSR in SPSR_svc
Enter supervisor mode and disable IRQs
Set PC to 0816 and begin executing the instruction there
107 5/18/2021
Addition Program
108/70 5/18/2021
Subtraction Program
• Subtraction
• AREA Program, CODE, READONLY
ENTRY
MOV R1, #0X000000008; /GET 1st VALUE
END
109/70 5/18/2021
Loading numbers from memory
END
110/70 5/18/2021
• Multiplication of numbers
• Multiplication :
AREA SIMPLE_PROGRAM, CODE, READONLY
ENTRY
MOV R1, #0X05
MOV R2, #0X03
MUL R1, R1, R2
HERE B HERE
END
111/70 5/18/2021
SERIES ADDITION OF 'N' 32 BIT NUMBERS
113/70 5/18/2021
Program to find the Negative numbers from series of numbers
115