Question about 'standard' values loaded for cclk and pclk

26 Aug 2010
user avatar Simon Ford wrote:

Yep, the PCLK defaults that the LPC1768/2368 comes up with after reset are /4, and we don't fiddle with them during startup. However, if you use an mbed interface to drive a peripheral, we certainly may choose to change the PCLK for that specific interface; for example, to reach a requested high baudrate.

Can we change the clock frequency of a peripheral after PLL0 has been enabled and connected? The errata sheet for the LPC1768 says we can't. Please see my other post, added today.

How do you guys choose arbitrary peripheral clock frequencies?

Thanks.

24 Jan 2011

All -

After playing around with it, I found that the USB clock is apparently much more tolerant of clocking errors than is suggested by this thread. In other words, I have clocked mbeds above 96 MHz and still have USB. So far I have tried 98,304,000 Hz (to get a specific 2.048 MBit serial rate) and 100,000,000 Hz just to see if I could.

At 100 MHz the USB printf output misses the first two characters, but performs flawlessly (at 460.8 KB) after that. I tried getting greedy and going for 110 MHz, but that didn't work so well. As it is, I'm very happy with the "bonus" 4 million clocks per second.

Regards,

- Gary

24 Jan 2011

Do you mean the USB UART?

24 Jan 2011

Igor -

From the discussion in this thread over a year ago, Simon suggested that USB would not work if the CPU were not at 96 MHz. I'm not sure which USB he was talking about, but the download/debug USB connector at the end of the mbed board still works for download and debug when I change the clock to 100 MHz. The CPU temperature seems very similar at both speeds (using my finger as a temperature probe).

My point in posting is that at first I didn't want to change the clock rate because I didn't want to have trouble downloading new programs or seeing debug text through the USB serial port. When I finally tried it, I was happy to see that I lost nothing but gained the desired clock rate. Testing with an oscilloscope verifies that it actually does work.

Regards,

- Gary

- - - CODE SNIPPET - - -

int main() {
    pc.baud(460800);

    printf("\r\nInitialising ...\r\n");
    LPC_SC->PLL0CON   = 0x00;             /* PLL0 Disable                    */
    LPC_SC->PLL0FEED  = 0xAA;
    LPC_SC->PLL0FEED  = 0x55;

    LPC_SC->CCLKCFG   = 0x00000003;       /* Select Clock Divisor = 4        */
    LPC_SC->PLL0CFG   = 0x00020031;       /* configure PLL0                  */
    LPC_SC->PLL0FEED  = 0xAA;             /* divide by 3 then multiply by 50 */
    LPC_SC->PLL0FEED  = 0x55;             /* PLL0 frequency = 400,000,000    */

    LPC_SC->PLL0CON   = 0x01;             /* PLL0 Enable                     */
    LPC_SC->PLL0FEED  = 0xAA;
    LPC_SC->PLL0FEED  = 0x55;
    while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0                 */

    LPC_SC->PLL0CON   = 0x03;             /* PLL0 Enable & Connect           */
    LPC_SC->PLL0FEED  = 0xAA;
    LPC_SC->PLL0FEED  = 0x55;
    while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */

//    SystemCoreClockUpdate();            /* Should now be at 100,000,000    */
    SystemCoreClock = (12000000 * 2 /
                      (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) *
                      ((LPC_SC->PLL0STAT & 0x7FFF) + 1)  /
                      ((LPC_SC->CCLKCFG & 0xFF)+ 1));
    printf ("System clock = %d\r\n", SystemCoreClock);

    .
    .
    .

}
25 Jan 2011

I think Simon was talking about the USB Host on the mbed (not the USB Uart / debugging interface) I could be wrong though.

29 Jan 2011

Hello everyone. If I compile a program including the mbed library right now at what frequency will run the cpu ? Is it 96Mhz? Thanks.

29 Jan 2011

The Handbook (see Technical reference) is a useful thing and a worthy starting place.

23 Jul 2011

For anyone who's coming upon this thread now, some updated info: as of mbed library v28, clock settings are as follows:

PLL Registers:
 - PLL0CFG = 0x0000000B    // this sets N = 1, M = 12
 - CLKCFG  = 0x00000002    // this sets final div by 3
Clock Variables:
 - Fin = 12000000
 - M   = 12
 - N   = 1
 - CCLKDIV = 3
Clock Results:
 - Fcco = 288000000  // output of PLL0: ( 2 * M * Fin ) / N = 288MHz
 - CCLK = 96000000   // final div by 3 clocks the core at 96MHz

None of this is really new but I just thought some other newcomer might find the more current info helpful.

23 Jul 2011

You can use PLL0 for the CPU and PLL1 for USB on p31 and p32 (for reference, look at fig. 7, page 29 of the LPC17xx user manual), which means you can run the CPU at 100MHz and USB at 48MHz if you want.

If I understand it correctly, the "USB serial" connection of the mbed has nothing to do with the LPC17xx USB peripheral. It just bridges the UART0 peripheral to the mbed USB connector.

25 Jul 2011

Ivo van Poorten wrote:

If I understand it correctly, the "USB serial" connection of the mbed has nothing to do with the LPC17xx USB peripheral. It just bridges the UART0 peripheral to the mbed USB connector.

Yes, this is another thing I have discovered - there's nothing special about the "USBTX" and "USBRX" pin names, they're just aliases for the 1768's UART0 pins. They are connected to a UART on the mbed interface chip, which handles the USB communication. However, in a custom design, there's nothing stopping you from using these pins as a standard UART, which is helpful if you want to make use of the ISP bootloader. (I mention this because that was the reason I started on my investigation of the clock setup, to make sure that the ISP entry code would work as expected - but there are several other threads on this topic, I don't mean to derail this one.)

21 May 2012

My LPC 1768 "mbed-005.1" apparently runs SystemCoreClock at 96 MHz:

PLL Registers:
 - PLL0CFG = 0x0000000B
 - CLKCFG  = 0x00000002
Clock Variables:
 - Fin = 12000000
 - M   = 12
 - N   = 1
 - CCLKDIV = 3
Clock Results:
 - Fcco = 288000000
 - CCLK = 96000000