Syllabus

System Control Block ( PLL and VPB divider), Memory Map, GPIO, Pin Connect Block, Timer

System Control Block

Phase Locked Loop (PLL)

  • LPC214x has two PLLs: PLL0 and PLL1
  • PLL0 is used to generate clock for CPU (CCLK) & peripherals (PCLK)
  • PLL1 is used for USB
  • It uses crystal oscillator input frequency (FOSC) 10–25 MHz and generates output up to 60 MHz
  • Parameters m & p determine output frequency, CCLK = m x FOSC
  • In the feedback path of PLL there is current controlled osc (CCO) whose frequency should be kept within 156 – 320 MHz.

Computing m and p values for generating CCLK of 60 MHz from FOSC 12 MHz

  • = CCLK/FOSC = 60/12 = 5
  • If p is chosen to be 2, CCO (= 2 x p x 60) is within 156 – 320 MHz.

pll.png

PLL Registers

  • PLLxCON – Controls PLL activation; used to enable and connect PLL
  • PLLxCFG – Multiplier value (bits [4:0]) and divider value (bits [6:5] are configured
  • PLLxSTAT – Shows current enable & connect status, m & p values, lock status
  • PLLxFEED – Writing feed sequence, i.e. ‘0xAA’ and ‘0x55’ in sequence, to this register– It enables changes made to PLLCON, PLLCFG registers to take effect APBDIV – Sets PCLK freq to 1/4, same or 1/2 of CCLK (by writing 0x00, 0x01, 0x02)

PLL configuration sequence

  1. Determine m and p values for desired CCLK and PCLK from FOSC
  2. Enter (m-1) in bits [4:0] and enter 00/01/10/11 for p values 1/2/4/8 in bits [6:5] of PLLCFG register.
  3. Enable PLL using PLLCON register (by setting bit[0]).
  4. Issue feed sequence, i.e. write constants 0xAA, 0x55 into PLLFEED reg
  5. Wait for PLL to lock (by checking bit[10],
  6. Connect & enable PLL using PLLCON reg. (by setting bits[1:0])
  7. Issue again feed sequence 

Examples

  • Configuring PLL0 for generating 60 MHz CCLK from 12 MHz FOSC multiplier = CCLK / FOSC = 60 / 12 = 5; (m-1) = 4 is placed in bits [4:0]
  • ‘p’  is chosen as 2, since CCO (= 2 x p x 60) is to be within 156 – 300 MHz
     

Enabling but not connecting PLL0, enabling and connecting:

  • Bit [0] of PLL0CON register is set for only enabling and bits[1:0] are set for enabling and connecting.
  • PLL0CON    =    0x01;    // enable PLL but not connect
  • PLL0CON    =    0x03;    // enable PLL and connect

Issue of PLL feed sequence:

  • PLL0FEED    =    0xAA;    // first fixed value
  • PLL0FEED    =    0x55;    // second fixed value

Checking PLL0 lock status & waiting till PLL0 locks onto the target frequency:

PLOCK, the bit [10] of PLL0STAT register, is polled and checked for lock status.

PLOCK = 0x40;

while(!(PLLSTAT & PLOCK));  // poll lock status & wait till PLL0 locks

VPB Divider

Programming APB divider for desired PCLK frequency:

Value 0x00, 0x01 or 0x02 in APBDIV register sets the PCLK frequency to one-fourth, same as or half of CCLK frequency.

APBDIV = 0x02    // set PCLK frequency to (CCLK/2)

Memory Map

memory_map.png

General Purpose Input Output (GPIO)

Pins not selected for peripheral functions are GP I/O port pin
I/O port pins dynamically configured as input/output using GPIO reg. 

Two sets of GPIO registers: Both control same I/O pins

  1. One set on APB, provides legacy (normal) GPIO functionality
  2. Another set on ARM local bus, provides enhanced (fast) GPIO function
    • In enhanced mode, registers are byte addressable
    • Includes mask registers to treat bits in groups

GPIO registers

  • IOxPIN – To get logic value on a I/O pin
  • IOxSET – To set an output configured pin (by writing 1 in corresponding bit)
  • IOxCLR - To clear an output configured pin (by writing 1 in corresponding bit)
  • IOxDIR – To select input /output function (by placing 0/1) for an I/O pin
    • (x = 0/1, i.e. Port-0 or Port-1)

Examples

Configuring & initializing GPIO pin:

PINSEL1=0x00000000;        // configure pins from P0.16 to P0.19 as GPIO
IO0DIR=0x000F0000;          // set pins P0.16 – P0.19 to output function
IO0SET=0x000F0000 ;        // set pins P0.16 & P0.18 of Port-0 HIGH
IO0CLR=0x000F0000 ;       // reset logic level of pin P0.16 of Port-0 LOW

Pin Connect Block

Features

  • 64 pins are attached to two 32-bit I/O ports, Port-0 & Port-1. 
  • Port-0, Port-1 pins are designated as P0.0 – P0.31 & P1.0 - P1.31. 
  • Pins P0.24, P0.26, P0.27, P1.0-P1.15 are unavailable. 
  • Pin functions are multiplexed, up to 4 functions assigned to each pin.
    • Port-0 pins multiplex peripheral pin, & comm. interface pin functions 
    • Port-1 pins multiplex JTAG interface, Trace function 
    • Advantages: keeps size small, adds more functionalities to devices 
    • Disadvantages: if functions not carefully selected, some can’t be availed 
  • Pin function select Registers: PINSEL0, PINSEL1, PINSEL2
    • PINSEL0 selects functions of pins P0.0 to P0.15, 
    • PINSEL1 selects functions of pins P0.16 to P0.31
    • PINSEL2 selects functions of pins P1.16 to P1.31 

pin-connect-block.png

Pin function selection: Examples

  1. Configuring P0.0 and P0.1 of Port-0 as I/O pins for TxD0 and RxD0 functions of UART0 in ‘C’:
    • PINSEL0=0x00000000;    //clear bits[3:2], [1:0] of PINSEL0 register, hence assign P0.0, P0.1 general purpose I/O function
    • PINSEL0=0x00000005;    //place 01 in bits[3:2], [1:0] of PINSEL0 register which selects TxD0 for P0.0 & RxD0 for P0.1 pins
  2. For using DAC, select Aout function for P0.25 pin.
    • PINSEL1=0X00080000...//place 10 into bits[19:18] of PINSEL1 reg.select Aout function for P0.25

Timer in LPC 2148

  • No. of Timers : 2, (Timer0 and Timer1) n
  • The LPC2148 has two functionally identical general purpose timers: 
  • Timer0 and Timer1. 
  • Both Timer/Counter with a programmable 32-bit Prescaler.
  • Counter or Timer operation.
  • Up to four 32-bit capture channels per timer, that can take a snapshot of the
    • timer value when an input signal transitions. A capture event may also
    • optionally generate an interrupt.
  • 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
  • Up to 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.
  • Capture Register:-   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 genreate an Interrupt. Hence these can be also used to demodulated PWM signals.
  •  Match Register:-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. We are only concerned with match registers in this PPT.

Functional Block Diagram

timer.png

  • Timer Operation:
  • Uses PCLK clock
  • Prescale Counter (PC) increments on each PCLK clock input pulse o Prescale Register (PR) holds 32-bit value
  • When PC = PR, increments Timer/Counter (TC) and resets PC o Hence, TC counting rate is controlled by PR
    • Each timer has 4 capture channels, 4 capture inputs (CAPx.0-CAPx.3) 
    • A transition on capture input, copies TC value into Capture Reg (CR) 
    • Can optionally generate interrupt also 
    • CCR configures capturing event (rising, falling or both edges) 
    • Each timer has 4 match channels, 4 match outputs (MATx.0-MATx.3)
  • For each match channel, there is a MR that holds 32-bit value
  • When TC = MR, an event (reset or stop TC, generate int) is triggered o MCR configures type of event to generate

Timer Registers

  • Timer Counter (TC): Incremented when PC = PR
  • Timer Control Register (TCR): Enables / disables, resets TC
  • Prescale Register (PR): Holds max value for PC to count up to. Controls counting rate
  • Prescale Counter (PC): Increments on every PCLK clock
  • Capture Registers 0 – 3: Transition on cap inputs copy TC into respective reg
  • Capture Control Register (CCR): Prescribes active event (rising/falling edge), int
  • Match Registers 0 – 3 (MR): Holds a value, matched with TC, matching triggers event
  • Match Control Register (MCR): Prescribes action (enabling/ disabling interrupt generation, resetting/disabling TC, or stopping TC and PC) to be triggered on match
  • Count Control Register (CTCR): Selects Timer or Counter mode;
  • Interrupt Register (IR): Has 4 bits for match interrupt, 4 bits for capture interrupt.When interrupt occurs corresponding bit is set. Writing high in a bit resets corresponding interrupt

Programming Timer Registers

The registers for a typical application are configured in the following order:

  1. TxCTCR and TxIR registers are programmed.
  2. TxPR and TxMRy are initialized with appropriate values.
  3. TxMCR and TxCCR are programmed.
  4. TC and PR are reset by programming TxTCR register.
  5. Timer is enabled by programming TxTCR register.

Applications

PWM, data acquisition, measurements of freq, speed, velocity, position

Timer Calculations

How to calculate value of prescaler ?

TIMER_Calculations.PNG

/* TOGGLE LEDS FROM P0.0 TO P0.15 WITH EXACT DELAY OF 3 SEC */

#include<lpc21xx.h>
void delay(void);

int main(
{
 VPBDIV=0X02;            //30MHZ //
PINSEL0=0X00000000;
 IODIR0=0X0000FFFF;
 IOCLR0=0X0000FFFF;
while(1)
  {
   IOSET0=0X0000FFFF;
   delay();
   IOCLR0=0X0000FFFF;
   delay();
  }
}

void delay(void)
{
 T0PR=29999;
 T0MR0=3000;
 T0TC=0x00000000;
 T0TCR=0X01;             //START TIMER//
while(T0TC !=T0MR0);    //1 SEC //
T0TCR=0X02;             //STOP TIMER //
}

References

  • WikiNote Foundation
Tags:
Created by Vishal E on 2017/04/12 23:21