Content originally posted in LPCWare by NXP_Paul on Tue Oct 30 06:50:16 MST 2012
We will be replacing the pseudo code found in the LPC18xx and LPC43xx User's Manuals with actual code:
#define PLL0_PSEL_MAX (1<<5)
#define PLL0_NSEL_MAX (1<<8)
#define PLL0_MSEL_MAX (1<<15)
/* post-divider: compute pdec from psel */
unsigned pdec_new (unsigned psel) {
unsigned x=0x10, ip;
switch (psel) {
case 0: return 0xFFFFFFFF;
case 1: return 0x62;
case 2: return 0x42;
default:for (ip = psel; ip <= PLL0_PSEL_MAX; ip++)
x = ((x^x>>2) & 1)<<4 | x>>1 & x3F;
return x;
} }
/* pre-divider: compute ndec from nsel */
unsigned ndec_new (unsigned nsel) {
unsigned x=0x80, in;
switch (nsel) {
case 0: return 0xFFFFFFFF;
case 1: return 0x302;
case 2: return 0x202;
default:for (in = nsel; in <= PLL0_NSEL_MAX; in++)
x = ((x^x>>2^x>>3^x>>4) & 1) << 7 | x>>1 & 0xFF;
return x;
} }
/* multiplier: compute mdec from msel */
unsigned mdec_new (unsigned msel) {
unsigned x=0x4000, im;
switch (msel) {
case 0: return 0xFFFFFFFF;
case 1: return 0x18003;
case 2: return 0x10003;
default: for (im = msel; im <= PLL0_MSEL_MAX; im++)
x = ((x^x>>1) & 1)<< 14 | x>>1 & 0xFFFF;
return x;
} }
/* bandwidth: compute seli from msel */
unsigned anadeci_new (unsigned msel) {
unsigned tmp;
if (msel > 16384) return 1;
if (msel > 8192) return 2;
if (msel > 2048) return 4;
if (msel >= 501) return 8;
if (msel >= 60) {
tmp=1024/(msel+9);
return (1024==(tmp*(msel+9)))==0 ? tmp*4:(tmp+1)*4 ;
}
return (msel & 0x3c) + 4;
}
/* bandwidth: compute selp from msel */
unsigned anadecp_new (unsigned msel) {
if (msel < 60) return (msel>>1) + 1;
return 31;
}
Thank you for bringing this to our attention.
Regards
NXP Technical Support