Adapting a project for a different crystal frequency

I have an LPC-H2148 header board with the system clock running off of a 12 MHz external crystal. I’d like to recreate an LPC2138 project that is based on schematic with a 14.7456 MHz external crystal. With the exception of the external crystal and the uC, my hardware set up is exactly the same. As I understand, the LPC2148 is essentially an LPC2138 with some built in USB capabilities (which is not implemented for this project).

The only peripheral used is on UART0. I am very new to microcontrollers, and I think I only need to make changes to the parts of the project code shown below:

// OLD clock setup with 14.7456 MHz crystal
// Fosc = 14.7456 MHz, M=4 (MSEL bits = 0011), P=2(PSEL bits =01)
// CCLK = Fosc * M = 58.9824 MHz;    Fcco = CCLK*2*P = 235.9296 MHz

    PLLCFG=0x23;

// NEW clock setup with 12.0000 MHz crystal
// Fosc = 12.0000 MHz, M=5 (MSEL bits = 0100), P=2(PSEL bits =01)
// CCLK = Fosc * M = 60.0000 MHz;    Fcco = CCLK*2*P = 240.0000 MHz

    PLLCFG=0x24;
// OLD baud rate setup on UART0 with 14.7456 MHz crystal
//PCLK = 58.9824 MHz, DIVADDVAL = 0, MULVAL=1
//Baud Rate = PCLK/[16*(256*DLM + DLL)*(1 + DIVADDVAL/MULVAL)] = 9600 baud
    U0DLM = 0x01;		 // DLM=1
    U0DLL = 0x80;		 // DLL=128     


// NEW baud rate setup on UART0 with 12.0000 MHz crystal
//PCLK = 60.0000 MHz, DIVADDVAL = 0, MULVAL=1
//Baud Rate = PCLK/[16*(256*DLM + DLL)*(1 + DIVADDVAL/MULVAL)] = 9590.792839 baud
    U0DLM = 0x01;		 // DLM=1
    U0DLL = 0x87;		 // DLL=135

Am I on the right track here…or way off?

Should the slight difference in the PCLK speeds (58.9824 vs 60.0000) be of concern?

Should the fractional baud rate (and/or the slightly lower baud rate) with the 12 MHz crystal be of concern?

Are there other issues I may need to address to get this project to work with the 12 MHz crystal?

Is there a better way (other than replacing the crystal) to accomplish this?

Thanks.

patrick

Are you using the UART? If not, you may not need to change the code at all. Have you tried just compiling and running your old code?

I will be using UART0. The original code is for the SFE GPS Logger V2.4. My project will be similar. I’d like to get the SFE GPS Logger code working with my board before I start modifying the set up for my own project needs…like implementing access to the logged data on the SD card via USB.

I haven’t yet attempted to modify and re-compile the original code as I’m still working on the hardware set up.

Any thoughts regarding the concerns I posted initially would be GREATLY appreciated by this newbie.

patrick

I don’t think there will be a big impact because of the change of frequency, 58.9824 MHz and 60 MHz are quite close. I wouldn’t bother with the UART fractional baud rate registers. I’m running at 115200 bps from a 5x12 MHz PCLK without problems.

What I do for my projects is create a single c file that configures the PLL, CCLK, PCLK and MAM then calculate dividers in other hardware drivers (UART, SD card, timers etc.) at runtime.