Unit 2 - ARM7 Based Microcontroller
Unit 2 - ARM7 Based Microcontroller
Prof. M. N. Kakatkar
Sinhgad College of Engineering
Syllabus
2
Unit II: System Control Block ( PLL and VPB divider) R1 Chapter 4.8, 4.11
14/12/2017
Architecture…
4
ARM7TDMI-S processor:
The ARM7TDMI-S is general purpose 32-bit microprocessor,
which offers high performance and very low power
consumption.
Pipeline techniques are employed so that all parts of the
14/12/2017
ARM7 Based Microcontroller LPC2148: Features
6
ARM7 Based Microcontroller LPC2148: Features
7
ARM7 Based Microcontroller LPC2148: Features
8
Applications
9
Due to their tiny size and low power consumption, ideal for
applications where miniaturization is a key requirement.
Architecture
14/12/2017
11
Buses
12
14/12/2017
ARM7 Based Microcontroller LPC2148:
system control block functions
13
PLL
Power Control
Reset
APB Divider
Wakeup Timer
14/12/2017
system control block functions…
14
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.
14/12/2017
system control block functions…
PLL…
15
14/12/2017
system control block functions…
PLL…
16
14/12/2017
system control block functions…
PLL…
17
Activation
Multiplier &
divider values
Control and
Configuration
Loading
Control and
Configuration
18
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.
19
PLL Control register (PLL0CON - 0xE01F C080,
PLL1CON - 0xE01F C0A0)
20
14/12/2017
PLL Configuration register ( PLL0CFG & PLL1CHG ]
bit description
7 6 5 4 3 2 1 0
R21 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)
22
14/12/2017
PLL Status register (PLL0STAT & PLL1STAT)
bit description
23
PLL Status register (PLL0STAT - 0xE01F C088, PLL1STAT -
0xE01F C0A8)
24
14/12/2017
PLL Feed register (PLL0FEED - 0xE01F C08C, PLL1FEED -
0xE01F C0AC)
25
14/12/2017
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
33
34
PLL Interrupt
35
14/12/2017
ARM7 Based Microcontroller LPC2148:
Pin connect block
36
14/12/2017
Pin connect block…
37
14/12/2017
Pin connect block…
38
14/12/2017
Pin connect block…
39
14/12/2017
Pin connect block…
40
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
14/12/2017
Memory maps…
44
14/12/2017
ARM7 Based Microcontroller LPC2148:
GPIO
45
Features
Every physical GPIO port is accessible via either the group of
registers providing an enhanced features and accelerated port
access or the legacy group of registers
Accelerated GPIO functions:
– GPIO registers are relocated to the ARM local bus so that the
fastest possible I/O timing can be achieved
– Mask registers allow treating sets of port bits as a group,
leaving other bits unchanged
– All registers are byte and half-word addressable.
– Entire port value can be written in one instruction.
14/12/2017
GPIO…
46
14/12/2017
GPIO…
47
14/12/2017
48
GPIO…
49
14/12/2017
50
14/12/2017
ARM7 Based Microcontroller LPC2148:
Timer
51
Features:
A 32-bit Timer/Counter with a programmable 32-bit Prescaler.
14/12/2017
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. 52
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
54
Timer Registers Description
1) PR : Prescale Register (32 bit) – Stores the maximum value
of Prescale counter after which it is reset.
56
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. 57
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.
58
Timer Registers
MCR : Match Control register – This register is used to
control which all operations can be done when the value in
MR matches the value in TC. Bits 0,1,2 are for MR0 , Bits
3,4,5 for MR1 and so on. Heres a quick table which shows
the usage:
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.
59
Timer…
Pin description…
60
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.
61
Timer…
Pin description…
62
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
63
Timer when required
Timer Registers Basics
64
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 65
}
Timer Calculations
1. The delay or time required for 1 clock cycle at ‘X’ MHz is
given by :
66
Delay program using timers
delayMS(unsigned int milliseconds);
Main Program
67
ARM instruction set
68 14/12/2017
ARM Instruction Set
69
Data processing
instructions
Data transfer
instructions
Block transfer
instructions
Branching instructions
Multiply instructions
Software interrupt
instructions
14/12/2017
Conditional Execution
70 14/12/2017
Data Processing Instruction
Arithmetic Operations
ADD r0,r1,r2 ;r0:= r1+r2
ADC r0,r1,r2 ;r0:= r1+r2+C
SUB r0,r1,r2 ;r0:= r1–r2
SBC r0,r1,r2 ;r0:= r1–r2+C
RSB r0,r1,r2 ;r0:= r2–r1, reverse subtraction
RSC r0,r1,r2 ;r0:= r2–r1+C
72 14/12/2017
Using and Updating the condition Field
73 14/12/2017
Use of Barrel Shifter
74
14/12/2017
Barrel Shifter
75
14/12/2017
Shift Register Operands
76
LSR, ASL (Arithmetic Shift Left), ASR, ROR (Rotate Right), RRX (Rotate
14/12/2017
Register Transfer and Comparison Instruction
77 14/12/2017
Branch Instructions
Syntax
Branch: B{<cond>} Label
Branch with Link: BL{<cond>} subroutine_label
31 28 27 25 24 23 0
cond 101 L 24-bit signed word offset
Link bit
0 = Branch
1 = Branch with Link
Condition field
78 14/12/2017
Conditional Branch
79 14/12/2017
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 …
81 14/12/2017
Example of conditional execution
82 14/12/2017
Multiply Instructions
83
– MLA{<cond>}{S} Rd,Rm,Rs,Rn
• 64-bit Product
– <mul>{<cond>}{S} RdHi,RdLo,Rm,Rs
– <mul> is UMULL,UMLAL,SMULL,SMLAL
14/12/2017
Multiply Instructions
84
14/12/2017
Branch with Link and exchange
B{L}X{<cond>} Rm
87 14/12/2017
Loading Constants
88 14/12/2017
Loading 32-bit Constants
For example
MOV r0,=&FF ;MOV r0,#0xFF
89 14/12/2017
Load and Store Instructions
90 14/12/2017
Load and Store Instructions
91 14/12/2017
Indexing methods
92 14/12/2017
Indexing methods
93 14/12/2017
Multiple Register Data Transfer
94
14/12/2017
Load/ Store multiple
95
14/12/2017
Block Transfer Instructions with example
96
Mi
LDM Mi+1
R0 Mi+2
R1
R2
Mi+14
Mi+15
R14 STM
R15
14/12/2017
Multiple Register Data Transfer
97 14/12/2017
Stack operations
98 14/12/2017
Stack operations
99 14/12/2017
Swap Memory and Register Instructions
Syntax
SWP{<cond>}{B} Rd,Rm,[Rn]
Example
ADR r0,SEMAPHORE
SWPB r1,r1,[r0] ;exchange byte
100 14/12/2017
Status Register to General Register
Transfer instructions
Syntax
MRS{<cond>} Rd, CPSR|SPSR
Example
MRS r0,CPSR
MRS r3,SPSR
101 14/12/2017
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
102 14/12/2017
Coprocessor Instructions
103 14/12/2017
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
104 14/12/2017
Addition Program
105/70 14/12/2017
Subtraction Program
• Subtraction
• AREA Program, CODE, READONLY
ENTRY
MOV R1, #0X000000008; /GET 1st VALUE
END
106/70 14/12/2017
Loading numbers from memory
END
107/70 14/12/2017
• Multiplication of numbers
• Multiplication :
AREA SIMPLE_PROGRAM, CODE, READONLY
ENTRY
MOV R1, #0X05
MOV R2, #0X03
MUL R1, R1, R2
HERE B HERE
END
108/70 14/12/2017
SERIES ADDITION OF 'N' 32 BIT NUMBERS
110/70 14/12/2017
Program to find the Negative numbers from series of numbers
112