Professional Documents
Culture Documents
LPC2148
LPC2148
LPC2148
Agenda
• Features
• PLL
• GPIO
• Timer/Counter
• DAC
• ADC
Features
• The LPC2141/42/44/46/48 microcontrollers, introduced by NXP
semiconductors, are based on a 16-bit/32-bit ARM7 TDMI-S CPU with
real-time emulation and embedded trace support.
• They have an embedded high-speed flash memory ranging from 32 kB
to 512 kB and a 128-bit wide memory interface.
• They also have 8 kB of on-chip RAM, one or two 10-bit ADCs, a 10-bit
DAC, two 32-bit timers/counters, a watchdog timer, a PWM unit,
aReal-Time Clock (RTC) with independent power and 32 kHz clock
input, multiple UART, I2C, and SPI buses, and a PLL and an on-chip
oscillator for clocks.
LPC2148 PLL
• There are two PLL modules in the LPC2141/2/4/6/8 microcontroller. The
PLL0 is used to generate the CCLK clock (system clock) while the PLL1 has
to supply the clock for the USB clock at the fixed rate of 48 MHz.
• The PLL0 and PLL1 accept an input clock frequency in the range of 10
MHz to 25 MHz only. This frequency is multiplied up to the range of 10
MHz to 60 MHz for the system clock and 48 MHz for the USB module
using a Current Controlled Oscillators (CCO). The USB module needs a
48MHz clock, which is generated by a PLL circuit.
• PLL unit uses a CCO, which operates in the range of 156 MHz to 320
MHz. The clock for the PLL module is generated by dividing the CCO
frequency by 2, 4, 8, or 16.
PLL block diagram
Registers for PLL
• PLLCON (PLL Control Register)
• PLLCFG (PLL Configuration Register)
• PLLSTAT (PLL Status Register)
• PLLFEED
PLLCON (PLL Control Register)
• The PLLCON register contains the bits that enable and connect the PLL.
• Enabling the PLL allows it decide the current multiplier and divider values,
while connecting the PLL causes the processor and all chip functions to run
from the PLL output clock.
PLLCFG (PLL Configuration Register)
• The PLLCFG register contains the PLL multiplier and divider values.
Values written to this register do not take effect until a valid PLL feed
sequence has taken place.
PLLSTAT (PLL Status Register)
• Reading this register provides the actual values controlling the PLL, as
well as the status of the PLL.
PLLFEED (PLL Feed Register)
• A correct feed sequence must be written to the PLLFEED register in
order for changes to the PLLCON and PLLCFG registers to take effect.
The feed sequence is:
• Write the value 0xAA to PLLFEED.
• Write the value 0x55 to PLLFEED.
= CCLK x 2 x P
or
= x M x 2 x P
The divider value D must be chosen such that is within its defined
frequency limits.
Step 1: PLL setup
• Choose an oscillator frequency (FOSC). CCLK must be the whole (non-
fractional) multiple of FOSC.
• M = CCLK / FOSC (between 1 and 32)
• The value written to the MSEL bits in PLLCFG is M − 1.
• The value of D written to the PSEL bits in PLLCFG is 00 for P = 1; 01 for
P = 2; 10 for P = 4; 11 for P = 8
• Since CCLK = 60 MHz, we can calculate the value of P using the
formula:
P = / (2 X CCLK)
PLL0CFG=0x24;
/* set the multipler to 5 (actually 4) i.e., 12
x 5 = 60 Mhz (M - 1 = 4). For P=2, set PSEL bits
to 01 in PLL0CFG. */
Step 2: Apply the feed sequence
• Feed Sequence is nothing but assignment of 2 particular ‘fixed’ values
to a register related to the PLL block. This register is called ‘PLL0FEED’.
And those fixed values are 0xAA and 0x55 are in order.
• Hence, the sequence would be:
PLL0FEED=0XAA;
PLL0FEED=0X55;
Step 3: Connect the PLL
• Check whether PLL has locked on to the desired freq by reading the
lock bit in PLL0STST register. If it locked then connect the PLL by
setting the 2nd bit in PLL0CON Register.
while((PLL0STAT&(1<<10))==0);
/* Wait till PLL has locked on to the desired freq.
by reading the lock bit in the PPL0STAT register */
PLL0CON=0x03; //Enable & Connect PLL
Hence, in our case, when PR=0 i.e. TC increments at every PCLK the delay required for
TC to increment by 1 is:
Delay = (0+1)/(60*1000000) Seconds
while(1) {
if(value > 1023) value=0; //For 10-bit DAC,
// max-value is 2^10 - 1 = 1023
DACR = (value<<6);
delayMS(10); value++;
}
}
LPC2148 ADC
Features:
• LPC2148 has two inbuilt 10-bit Successive Approximation ADC. ADC0 has
six channels (AD0.1-AD0.6). ADC1 has 8-Channels (AD1.0-AD1.7).
• ADCs in LPC2148 use Successive Approximation technique to convert
analog signal into digital form.
• Their operating frequency is 4.5 MHz (max.), which decides the conversion
time.
• The ADC reference voltage is measured across GND to VREF
• 10 bit conversion time ≥2.44 µs.
• Burst conversion mode for single or multiple inputs.
• Input multiplexing among 6 or 8 pins (ADC0 and ADC1).
Registers Used For ADC
Register Description
ADxCR A/D Control Register: Used for Configuring the ADC
ADxGDR A/D Global Data Register: This register contains the ADC’s DONE bit and the
result of the most recent A/D conversion
ADxDR0 - A/D Channel Data Register: Contains the recent ADC value for respective
ADxDR7 channel
A/D Status Register: Contains DONE & OVERRUN flag for all the ADC
ADxSTAT channels
ADxGSR A/D Global Start Register: This address can be written (in the AD0 address
range) to start conversions in both A/D converters simultaneously.
Configuring the ADC
Below are the steps for configuring the LPC1768 ADC.
i. Configure the GPIO pin for the ADC function using the PINSEL register.
ii. Enable the CLock to ADC module.
iii. Power on the internal ADC module by setting ADCR.PDN bit (ADCR’s 21st bit).
iv. Select the Particular channel for A/D conversion by setting the corresponding
bits in ADCR.SEL (bit 0 – bit 7).
v. Set the ADCR.START bit for starting the A/D conversion for the selected channel
(ADCR’s 24th bit).
vi. Wait for the conversion to complete, ADGDR. The DONE bit will be set once the
conversion is over.
vii. Read the 10-bit A/D value from ADGdR.RESULT.
Code
int val;
PINSEL1 = 0x01000000; /* P0.28 as AD0.1 */
AD0CR=0x00200802; //CLKDIV=4, ADC ON, Channel 1 selected
AD0CR |= (1<<24); //Start conversion
while((AD0GDR & (1<<31)) == 0);
val = AD0GDR;
// Similarly for AD1
References and further reading
• https://embetronicx.com/arm7-lpc2148-tutorials/
• http://www.ocfreaks.com/cat/embedded/lpc2148-tutorials/
https://www.electronicwings.com/arm7