lpc2138 taking commands merely as a suggestion?

Im working on an embedded project and I’m currently using an Olimex P-Lpc2138

board. After having the device misbehave badly, I decided to try something

simpler - to control the leds on the development board.

After seeing what happened, I realized that something is very wrong.

Even very simple code which just turns on and off the leds repetitively, doesn’t

work correctly - sometimes the PLL would fail to lock, sometimes loops don’t

work and cause he code not to run at all…

I compile the code with -O0 optimizations usually, but oddly enough sometimes

when I try other types of optimization, some work better in making the leds work

correctly.

Obviously I’m getting very frustrated over this, and I’m starting to lose

hope… - I can’t even get dbg in eclipse to debug the code!

I will be glad to provide any other information which might help resolve this, I

just don’t really know what might be needed - please tell me if theres anything

else you need to know, and I will promptly provide the info.

Thanks in advance,

Kosta

I was going to suggest you join the LPC2000 group, but I see that you have posted this there as well. :sunglasses:

Try running without the PLL and disabling the MAM, some people have reported that early versions of the chip have a MAM bug. There has been some discussion of this problem there. NXP denies it, however. You do need to have the PLL limited to 275-290 MHz, anyway.

You also need to read the errata.

Leon

Hehe, yeah :smiley:

Disabling the PLL smoothed out some of the things, so I guess I might have set it up incorrectly… I will look through the PLL code again for bugs, and hopefully find them…

What do you mean about the 275-290Mhz? I thought the LPC2138 was up to 60Mhz…

The errata I did read but nothing relevant was there…

Thanks!

shwouchk:
Hehe, yeah :smiley:

Disabling the PLL smoothed out some of the things, so I guess I might have set it up incorrectly… I will look through the PLL code again for bugs, and hopefully find them…

What do you mean about the 275-290Mhz? I thought the LPC2138 was up to 60Mhz…

The errata I did read but nothing relevant was there…

Thanks!

Leon was probably refering to the PLL’s CCO frequency. 60MHz is correct for the final output of the PLL block. On the LPC2138 the CCO must be operated in the range of 156MHz to 320MHz. Section 8-10 of the LPC2138 manual shows the procedure for calculating the PLL settings, and section 8-11 gives an example of following that procedure to determine the settings.

–Dave

Oh, yeah, I thought he might have reffered to the CCO…

So are you saying that in practice the CCO can only take values of 275-290Mhz even though the manual says 156-32Mhz?

I have the C version of the chip by the way - I dont know if you considered that old or not…

I have also gone through the PLL code and can find no errors - I’ll paste it here just in case someone spots something obvious that I missed:

====================ProcInit.cpp====================

#include “ProcInit.h”

#include “board.h”

// Commit the Changes made to the PLL.

void PllCommit(void);

void ProcInit(void)

{

// Disable memory acceleration:

MAMCR = 0x0;

// Set PLL Settings configured in board.h:

PLLCFG_bit.MSEL = PLL_M - 1; // MSEL should be M-1

PLLCFG_bit.PSEL = PLL_PSEL; // PSEL should be log2(P)

// Commit the changes (Required by the LPC after any changes to the PLL settings)

PllCommit();

// Enable the PLL and connect it as the clock source:

PLLCON_bit.PLLE = 1; // Enable the PLL

// Commit the changes (Required by the LPC after any changes to the PLL settings)

PllCommit();

while (!PLLSTAT_bit.PLOCK); // Wait for PLOK (PLL lock to the requested frequency)

PLLCON_bit.PLLC = 1; // Connect the PLL

// Commit the changes (Required by the LPC after any changes to the PLL settings)

PllCommit();

// TODO: Initialize timer! (for using ticks and interrupts and not big whiles)

};

void PllCommit(void)

{

// This is needed to commit settings to the PLL after changing something:

PLLFEED_bit.FEED = 0xAA;

PLLFEED_bit.FEED = 0x55;

};

================================================

=======================board.h====================

#include “lpc2138.h”

// PLL Settings:

// The Fosc * PLL multiplier make up the CPU clock:

#define FOSC 14745600 // Onboard Oscillator.

// We want operate at ~60Mhz which means we multiply by 4.

#define PLL_M 4 // Pll Multiplier. MSEL should be PLL_M - 1.

// We need the Fcco to be between 156Mhz and 320Mhz. Fcco = Fosc2PLL_M*PLL_P.

// PLL_P = 2 fits the requirement, which means we set PSEL to 1

#define PLL_PSEL 1

================================================

P.S.

If that is indeed what you meant then it is impossible for my board since I cant set it up so that the CCO is within 275Mhz-290Mhz

shwouchk:
P.S.

If that is indeed what you meant then it is impossible for my board since I cant set it up so that the CCO is within 275Mhz-290Mhz

I usually set the CCO to the frequency closest to 156MHZ that will satisfy all the other requirements. But that is just because I have found with PLL hardware that I have designed myself that the oscillator phase noise was lower at the lower end of the range that the VCO was designed for. I have no idea where those 275-290MHz numbers came from, but I have not worked with an LPC2138 for over a year now. That is an extremely small range though!!!

–Dave

I think that they were derived from the values in the NXP errata document for the LPC2138. You need to read it if you want to get things working properly.

Leon

leon_heller:
I think that they were derived from the values in the NXP errata document for the LPC2138. You need to read it if you want to get things working properly.

Leon

Leon, I did not recall any PLL related errata for the LPC2138, so I just rechecked it when I saw this post of yours. There still does not appear to be any errata directly related to the PLL, although the MAM is mentioned. I set the MAM and required wait states just before setting up the PLL. This is the document that I am refering to:

http://www.nxp.com/acrobat_download/err … s/2138.pdf

I have not run into any PLL issues with the older chips like the LPC2138 or the LPC2148, and it seems to work fine when properly set up.

–Dave

thanks for all the relpies.

leon, I have already stated after your first reply regarding the errata that I have read it and nothing relevant was there - need I repeat myself?

dshuman, Thanks for the input - I’ll keep that in mind - 275-290Mhz really is extremely small, esp. considering that for my crystal I cant set ANY CCO freq that will be inside that range… however, my code works a little better now - I think it is because I changed the debug symbols from dwarf-2 to stub, but I don’t know really…

here’s what I’m using on the lpc2103. There may be some differences on the 2138.

void init_pll(void)

{

/*

  • Initialize PLL (Configured for a 14.7456MHz crystal) to

  • boost processor clock to 58.9824MHz

*/

/* set multiplier and divider values - PLLCFG = P + (M - 1) */

PLLCFG=0x23;

PLLFEED=0xAA;

PLLFEED=0x55;

/* enable the PLL */

PLLCON=0x1;

PLLFEED=0xAA;

PLLFEED=0x55;

/* Wait for the PLL to lock to set frequency */

#define PLOCK 0x400

while(!(PLLSTAT & PLOCK)){}

/* Connect the PLL as the clock source */

PLLCON=0x3;

PLLFEED=0xAA;

PLLFEED=0x55;

}

void init_mam(void)

{

/*

  • enable MAM and set number of clocks used for

  • flash memory fetch

*/

MAMTIM=0x4;

MAMCR=0x2;

}

Thanks!

I am discovering layers of layers of s*** that I did wrong, etc… funny enough, the PLL config was actually correct - I used a bad linker script and apparently having the debugging info in a dwarf-2 format was bad…

Ive managed to proceed from doubting the board works/having trouble with lighting leds in the correct fashion, to having trouble initializing the lcd correctly/outputting the correct chars…

right now I need to reset the board twice before it initializes the display correctly (probably some timing/order issues). it also outputs incorrect characters which is a bit weird… Anyway, hopefully tommorow I figure it out…

Thanks!