Hello iansmusical,
The above problem of FLL locking is solved , the problem was WDT, it has always reset the MCU after appx. 9 msec , so that before the Oscillator stabilize the MCU get Reset.Actually what wondering me is that in Datasheet the max. Stabilization time for FLL is 2 msec but in oscilloscope i have seen it took around 21 mSec , n that was the reason why it was never stabilized and get Reset cause of WDT.
can you give me Some suggestions please, why it's taking 21 msec or am i doing something again wrong?
Here is that Actual code :
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
volatile byte NV_FTRIM_INIT @0x0000FF6E ; // LSB ICS_C4
volatile byte NV_ICSTRM_INIT @0x0000FF6F ; // MSB ICS_C3
// Main Programm is working at 20Mhz = 512 * 39062.5 = 20Mhz => 39062.5 is a Default Factory Trimmed frequency in ICS_C3 & ICS_C4 Registers
void main(void)
{
DisableInterrupts;
WDOG_CNT = 0xC520; // write 0xC520 to the 1st unlock word
WDOG_CNT = 0xD928; // write 0xD928 to the 2nd unlock word
//Disable Watchdog
WDOG_CS1 = 0; // disable Watchdog
WDOG_CS2 = 0;
WDOG_TOVAL = 0xFFFF;
WDOG_WIN = 0x0000;
if ( NV_ICSTRM_INIT != 0xFFU) { // 0xFF6FU Test if the device trim value is stored on the specified address
ICS_C3 = NV_ICSTRM_INIT ; // This Registers are not Define in Derivative.h file thats why we have to define this Environment Variable before the start of code
ICS_C4 = ((NV_FTRIM_INIT) & 0x01U); // Trim the internal clock :((NV_FTRIM_INIT) & 0x01U);
}
ICS_C1 = 0x04; // internal reference clock to FLL and FLL is generating 16000-20000 Khz ; Ref. Freqeuncy is set at 31250-39250 Hz * 512 = Appx.16-20 Mhz
ICS_C2 = 0x00; // BDIV = 00, Freq is now 16-20Mhz
PORT_PTAOE = 0x0F;
PORT_PTAD_PTAD2 = 0;
while (ICS_S_LOCK==0) // wait till FLL is locked.
{
PORT_PTAD_PTAD2 = 1;
}
PORT_PTAD_PTAD1=0; // Initialize PORTA1 pin
while (1)
{ PORT_PTAD_PTAD1 = 1;
PORT_PTAD_PTAD2 = 0; } // Set PORTA1 pin in forever loop
}
Thanks and Kind Regards,
Robin