Reply by burra_77 June 30, 20052005-06-30
Hi,

Have a problem with switching clock on the 56F8322. I make my codewith
CW 7.2 and PE 2.96.I load the code with the factory preprogrammed
bootloader ver. 1.0.2. The bootloader is programmed to use an internal
clock and my program switch from the internal to en external crystal.
But this don't work it seems like when it switches it waits for PLL
lock but this never happens. If I disable the PLL in PE and use system
clock (IP Bus) 2 or 4 and set PE to use the internal clock and change
crystal with my own code it works. When i don't use PLL I don't get
right timings on the other peripheral clocks. I use an 8 MHz external
crystal and it seams to work fine. Have mounted the same crystal on a
56F8300DEMO and there it works fine. I think that this is a problem
with the bootloader. Have anybody had the same problem or have any
suggestions on what to do.

Bertil Bk
TK enginering

The code for changing crystal

void init_external_crystal(void);

void main(void)
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS
CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization.
***/
/*** End of Processor Expert internal initialization.
***/
init_external_crystal();

/* Write your code here */

for(;;)
{
}

} void init_external_crystal(void)
{
setRegBits(GPIO_C_PER, 3); /* Disable pull-up on XTAL
pins */

Cpu_Delay100US(4000); /* Wait about 40ms for external oscillator stabilization */

clrRegBit(OSCTL, CLK_MODE); /* Select an external oscillator
mode */
asm(nop);
asm(nop);
setRegBit(PLLCR,PRECS); // (PLLCR_PRECS_MASK | PLLCR_LCKON_MASK |
PLLCR_ZSRC0_MASK)); /* Enable PLL, LCKON and select clock source from
prescaler */
asm(nop);
setRegBit(OSCTL,ROPD);
asm(nop);
setRegBit(OSCTL,COHL);

//set external prescaler output
clrRegBit(PLLCR,ZSRC1);
setRegBit(PLLCR,ZSRC0);
setRegBit(OSCTL,COHL);
asm(nop);
setRegBit(PLLCR,PLLPD);
asm(nop);
setReg(PLLDB, 0x001D); /* Set the clock prescalers */
asm(nop);
setRegBit(PLLCR,LCKON);
clrRegBit(PLLCR,PLLPD);
asm(nop);
while(!getRegBit(PLLSR, LCK0)){} /* Wait for PLL lock */
setReg(PLLCR, 0x0082); /* Select clock source from postscaler */
/*** End of PE initialization code after reset ***/
}