UNIT 2
ARM7 BASED MICROCONTROLLER
      Prof. Vaishali Gongane
          PVG'sCOET &GKPIM, Pune   1
Syllabus
PVG'sCOET &GKPIM, Pune   2
PVG'sCOET &GKPIM, Pune   3
Architecture
  PVG'sCOET &GKPIM, Pune   4
PVG'sCOET &GKPIM, Pune   5
PVG'sCOET &GKPIM, Pune   6
PVG'sCOET &GKPIM, Pune   7
PVG'sCOET &GKPIM, Pune   8
                Applications
• The ARM7TDMI-S: Thumb, makes it ideally
  suited for high-volume applications with memory
  restrictions, or where code density is an issue.
     • Due to their tiny size and low power
  consumption, ideal forapplications            where
  miniaturization is a key requirement.
 •Communication gateways and Protocol converters
 •Modems ,Voice recognition, Low end Imaging
 •Industrial control and Medical systems.
                    PVG'sCOET &GKPIM, Pune         9
PVG'sCOET &GKPIM, Pune   10
PVG'sCOET &GKPIM, Pune   11
BUSES
PVG'sCOET &GKPIM, Pune   12
Bus Structure
   PVG'sCOET &GKPIM, Pune   13
                  Bus Structure
 • In LPC2148 three types of busses are used to connect
    the core with other peripherals on chip.
1. Local Bus to connect the on chip memory controllers
    and fast GPIO’s
2. AMBA Advance High Performance Bus (AHB) for
    interrupt controller
 • AHB (Advanced High Performance BUS)
 -High performance
 -Support pipelined
 - Each AHB peripheral is allocated a 16 kB address space
    within the AHB address space.
                       PVG'sCOET &GKPIM, Pune               14
                  Bus Structure
 2. VLSI Peripheral Bus (VPB) for other on chip
 peripherals.
•VPB(VLSI Peripheral bus )
 -Low power
 -Non pipelined
 -Simple interface
 AHB acts as a bridge for VPB.
•VPB is mainly meant for connect slower peripherals than
 that of processor.
•VPB can drive the peripherals at ¼ CPU clock frequency.
                       PVG'sCOET &GKPIM, Pune              15
PVG'sCOET &GKPIM, Pune   16
PVG'sCOET &GKPIM, Pune   17
PVG'sCOET &GKPIM, Pune   18
PVG'sCOET &GKPIM, Pune   19
System Control LPC 2148
       PVG'sCOET &GKPIM, Pune   20
PVG'sCOET &GKPIM, Pune   21
PVG'sCOET &GKPIM, Pune   22
PVG'sCOET &GKPIM, Pune   23
PVG'sCOET &GKPIM, Pune   24
PVG'sCOET &GKPIM, Pune   25
PVG'sCOET &GKPIM, Pune   26
PVG'sCOET &GKPIM, Pune   27
PVG'sCOET &GKPIM, Pune   28
PVG'sCOET &GKPIM, Pune   29
PVG'sCOET &GKPIM, Pune   30
PVG'sCOET &GKPIM, Pune   31
PVG'sCOET &GKPIM, Pune   32
PVG'sCOET &GKPIM, Pune   33
PVG'sCOET &GKPIM, Pune   34
                 Example
Development board has 12MHz crystal
  frequency. The CPU clock frequency to be
  achieved is 60MHz.
• Find M= CCLK/Fosc = 60×106/12×106 = 5
• 156<FCCO<320 = CCLK × 2× P
= 60 × 2× P
P= 156/120= 1.3 P= 320/120=2.67
P must be an integer between 1.3 and 2.67, so
 P=2
                  PVG'sCOET &GKPIM, Pune        35
• PLLCFG
   7   6      5      4         3          2       1      0
   R   PSEL   PSEL   MSEL      MSEL       MSEL    MSEL   MSEL
   0   0      1      0         0          1       0      0
                         PVG'sCOET &GKPIM, Pune                 36
PVG'sCOET &GKPIM, Pune   37
PVG'sCOET &GKPIM, Pune   38
PVG'sCOET &GKPIM, Pune   39
PVG'sCOET &GKPIM, Pune   40
PVG'sCOET &GKPIM, Pune   41
                Pin Connect Block
• The pin connect block allows selected pins of the
  microcontroller to have more than one function.
• Configuration registers control the multiplexers to allow
  connection between the pin and the on chip peripherals.
• Peripherals should be connected to the appropriate pins prior
  to being activated, and prior to any related interrupt(s) being
  enabled.
• Activity of any enabled peripheral function that is not mapped
  to a related pin should be considered undefined.
• Selection of a single function on a port pin completely
  excludes all other functions otherwise available on the same
  pin.
                           PVG'sCOET &GKPIM, Pune                   42
                             PINSEL
• To enable pin functions three 32 bit PINSEL registers: PINSEL0,
PINSEL1 and PINSEL2 are used
   • PINSEL0 contains GPIO pins P0.0 to P0.15
   • PINSEL1 contains GPIO pins P0.16 to P0.31
   • PINSEL2 is a special case, and is used to control whether pins
     P1.16...31 are used as GPIO pins, or as a Debug port in
     combination with a hardware JTAG debugger.
• Each associated 'pin' in PINSEL0 and PINSEL1 is assigned a 2-bit
  address.
• P0.0, for example, uses the first two bits in PINSEL0, P0.1 uses the
  next two bits, and so on, until you end up with the following layout:
                            PVG'sCOET &GKPIM, Pune                    43
PVG'sCOET &GKPIM, Pune   44
• The PINSEL registers control the functions of
  device pins as shown below.
Pairs of bits in these registers correspond to
  specific device pins.
00: Primary (default) function, typically GPIO
  01: First alternate function
10: Second alternate function 11: Reserved
                   PVG'sCOET &GKPIM, Pune         45
 Example to select the functionality of
                          Pin
• P0.0 00 GPIO Port 0.0 01 TXD (UART0) 10
  PWM1
11 Reserved
• If we want to choose P0.0 as TXD then we have
  to write
PINSEL0=0x00000001
• If we want to choose P0.0 as PWM1 then write
  PINSEL0=0x00000002
                    PVG'sCOET &GKPIM, Pune        46
PVG'sCOET &GKPIM, Pune   47
PVG'sCOET &GKPIM, Pune   48
ARM Memory
Organization
  PVG'sCOET &GKPIM, Pune   49
                       Effect of
•   The ARM can beendianess
                        set up to access its data in either
    little or big endian format.
• Little endian:
    – Least significant byte of a word is stored in bits 0-7
of an addressed word.
• Big endian:
   – Least significant byte of a word is stored in bits 24-
31 of an addressed word.
• This has no real relevance unless data is stored as
  words and then accessed in smaller sized
  quantities (halfwords or bytes).
    – Which byte / halfword is accessed will depend on the
      endianess of the system involved.
                       PVG'sCOET &GKPIM, Pune                  50
                                                      Endianess
                                                      Example
                                                      r0 = 0x11223344
                                                          31     24 23   16 15   87
                                                                 0
                                                           11      22     33      44
                                                               STR r0, [r1]
                   31        24 23   16 15   87                                         31        24 23   16 15   8        0
                             0                                                          7
      r1 = 0x100                                                  Memory                                                       r1 = 0x100
                        11    22      33         44                                          44      33      22       11
Little-endian                                                   LDRB r2, [r1]                                                   Big-endian
                   31        24 23   16 15   8        0                                 31        24 23   16 15   8        0
                   7                                                                    7
                        00     00      00        44                                          00      00      00       11
                             r2 = 0x44                                                            r2 = 0x11
                                                               PVG'sCOET &GKPIM, Pune                                                       51
PVG'sCOET &GKPIM, Pune   52
PVG'sCOET &GKPIM, Pune   53
PVG'sCOET &GKPIM, Pune   54
PVG'sCOET &GKPIM, Pune   55
PVG'sCOET &GKPIM, Pune   56
PVG'sCOET &GKPIM, Pune   57
PVG'sCOET &GKPIM, Pune   58
  GPIO
Registers
PVG'sCOET &GKPIM, Pune   59
Example
PVG'sCOET &GKPIM, Pune   60
PVG'sCOET &GKPIM, Pune   61
PVG'sCOET &GKPIM, Pune   62
PVG'sCOET &GKPIM, Pune   63
                  Problem
• Write the configuration of GPIO registers for
  interfacing 8 LEDs connected to P0. 19 to
  P0.26.
• Write the configuration of GPIO registers for
  interfacing LEDs connected to P1. 16, P1. 18,
  P1. 20, P1. 22.
                   PVG'sCOET &GKPIM, Pune         64
PVG'sCOET &GKPIM, Pune   65
PVG'sCOET &GKPIM, Pune   66
PVG'sCOET &GKPIM, Pune   67
PVG'sCOET &GKPIM, Pune   68
PVG'sCOET &GKPIM, Pune   69
PVG'sCOET &GKPIM, Pune   70
  Count Control Register (CTCR, TIMER0: T0CTCR
                         and TIMER1: T1CTCR
• The Count Control Register (CTCR) is used to select
  between Timer and Counter mode, and in Counter mode to
  select the pin and edge(s) for
• When Counter Mode is chosen as a mode of operation, the
  CAP input (selected by the CTCR bits 3:2) is sampled on
  every rising edge of the PCLK clock. After comparing two
  consecutive samples of this CAP input, one of the following
  four events is recognized:
• rising edge, falling edge, either of edges or no changes in
  the level of the selected CAP input.
• Only if the identified event corresponds to the one selected
  by bits 1:0 in the CTCR register, the Timer Counter register
  will be incremented. counting.
                        PVG'sCOET &GKPIM, Pune               71
Count Control Register (CTCR, TIMER0: T0CTCR - and
                          TIMER1: T1CTCR
                  PVG'sCOET &GKPIM, Pune             72
 Timer
Features
PVG'sCOET &GKPIM, Pune   73
PVG'sCOET &GKPIM, Pune   74
 Timer
Registers
PVG'sCOET &GKPIM, Pune   75
PVG'sCOET &GKPIM, Pune   76
PVG'sCOET &GKPIM, Pune   77
PVG'sCOET &GKPIM, Pune   78
PVG'sCOET &GKPIM, Pune   79
PVG'sCOET &GKPIM, Pune   80
Steps to configure the timer
          PVG'sCOET &GKPIM, Pune   81
Prescale calculations
      PVG'sCOET &GKPIM, Pune   82
      Basic LED Blinking code using
                 Timers
#include <lpc214x.h>
#define PRESCALE 60000 //60000 PCLK clock
cycles to increment TC by 1
void delayMS(unsigned int milliseconds);
void initTimer0(void);
                  PVG'sCOET &GKPIM, Pune   83
PVG'sCOET &GKPIM, Pune   84
PVG'sCOET &GKPIM, Pune   85
PVG'sCOET &GKPIM, Pune   86
             Using Match register
void delay_ MR()
{
T0CTCR=0X0000; //Timer Mode T0PR=59999; //Prescaler Value
T0MR0=1000; //Match Register Value
T0MCR=0x00000004; //TC and PC will be stopped and TCR[0] will
be set to 0 if MR0 matches the TC.
T0TCR=0X02; //Reset Timer T0TCR=0X01; //Timer ON
while(T0TC!=T0MR0);
T0TCR=0; //Timer OFF
}                       PVG'sCOET &GKPIM, Pune   87
LED Interfacing with LPC2148
Schematic Diagram
                               88
PCLK= 15 MHz
Considering a delay of 1 ms
                              PVG'sCOET &GKPIM, Pune   89
void init_timer()                void delay(unsigned int n)
{                                {
T0CTCR = 0x0;                    T0TCR=0x02;
T0PR = 14999;                    T0TCR=0x01;
T0TCR = 0x02;                    while (T0TC < n);
}                                T0TCR=0x00;
                                 }
                    PVG'sCOET &GKPIM, Pune                90
#include<lpc214x.h> int main(void)
{
init_timer();
IO0DIR = 0xFFFFFFFF;
while(1)
{ IO0SET = 0xFFFFFFFF; //Turn on LEDs
delay(1000);
IO0CLR = 0xFFFFFFFF; //Turn them off
delay(1000);
}
                  PVG'sCOET &GKPIM, Pune   91