Content originally posted in LPCWare by cararra on Thu Jul 04 06:46:37 MST 2013
The problem is this code:
int RC_Oscillator_Delay;
// This part switches to RC oscillator - but it is not reliably working
LPC_SYSCON->PDRUNCFG &= ~(3<<0); // page 32 of LPC1317 user manual - power up the fast 12MHz RC Osc
LPC_SYSCON->MAINCLKSEL = 0x0; // select RC oscillator (from the 4MHz xtal oscillator it is running on) - page 20 of the LPC1317 user manual
// Normally there is a delay before RC oscillator is operational - at least 300 counts in my system
for(RC_Oscillator_Delay = 0; RC_Oscillator_Delay<300; RC_Oscillator_Delay++);
Its a hit and miss affair whether RC oscillator switch over has worked.
For example, the above code works on a bench lab supply.
But not on a mains adapter based power supply.
Sometimes it works on 10000 counts.
What I really want is for the RC oscillator to start up reliably and switch to it from xtal operation.
The manuals don't seem to have any information about RC oscillator start up delays.
Any suggestion is helpful.
Thanks.