You are on page 1of 12

PLL Programming

• Objective: To set PCLK 60 MHz


• Oscillator frequency: 10 MHz

Step 1: Det. Value of M and P


Step 2: Enable PLL
Step 3: Load value of M and P into PLLCFG Register
Step 4: Provide proper feed sequence
Step 5: Connect the PLL
Continue..

• M = 6 (Refer System Control lecture for the


calculation)
• P=2
#include <LPC214X.h>
#include <stdint.h>
void pll_configuration();
Continue..
• int main()
• {
• pll_configuration();
• Return 0;
• }

• void pll_configuration()
• {
• PLL0CON=0x01; // Enable PLL
• PLL0CFG=0x25; // P=2, M=6
• PLL0FEED=0xAA;
• PLL0FEED=0x55;
• while(!(PLL0STAT & (1<<10))); //check 10th bit of PLL Status Register
• PLL0CON=PLL0CON|(1<<1); // Connect PLL
• }
Timer Programming
• Objective: Generate Delay of 1 ms using Timer 0
• PCLK = 60 MHz (Setup using PLL0 and APBDIV
register)
• Step1: Delay calculation:
• Time period of the PCLK = 1/60*(10^6)
• Delay required : 1ms
• No of clock count or clock cycles for this delay:
1/T = 10^-3*10^6*60=60000
Continue..
• Program:
#include <LPC214X.h>
#include <stdint.h>
void pll_configuration();
void delay(unsigned int );
• int main()
• {
• pll_configuration();
• APBDIV=0x01 // (Pclk=Cclk)
• delay(60000);
• Return 0;
• }
Continue..
• Void delay(unsigned d)
• {
• T0TC=0x00000000;
• T0CTCR=0x00;
• T0PR=0x00; (The PR can be used to divide PCLK)
• T0MR0=d;
• T0TCR=0x01;
• T0MCR=0x0002;
• while(T0TC!=T0MR0);
• T0TCR = 0x00;
• }
Continue..
• Objective: Write a program to blink an LED with an interval
of 1s.
• PCLK = 60 MHz
• Use PR to divide pclk by 60 (T =1 micro sec)
• Program:
#include <LPC214X.h>
#include <stdint.h>
void pll_configuration();
void delay(unsigned int );
void timer_config();
Continue..
• int main()
• {
• pll_configuration();
• void timer_config();
• IO0DIR=(1<<1);
• while(1)
• {
• IO0SET=(1<<1);
• delay(d); (det. value of d offline)
• IO0CLR=(1<<1);
• delay(d);
• }
• Return 0;
• }
Continue..
• void pll_configuration()
• {
• PLL0CON=0x01;
• PLL0CFG=0x25;
• PLL0FEED=0xAA;
• PLL0FEED=0x55;
• while(!(PLL0STAT & (1<<10)));
• PLL0CON=PLL0CON|(1<<1);
• }
continue..
• void timer_config()
• {
• T0TC=0x00000000;
• T0CTCR=0x00;
• T0PR= 59;
• T0MCR=0x0002;
• }
Continue..
• void delay(unsigned int d)
• {
• T0MR0=d;
• T0TCR=0x01;
• while(T0TC!=T0MR0);
• T0TCR=0x00;
• }
Timer using interrupt

You might also like