AW32 doesn't work with external crystal

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AW32 doesn't work with external crystal

4,643 Views
admin
Specialist II
I've got a big problem with AW32. There is a schematics and printed circuit of my project. (Crystal frequency is 14.318 MHz )








And there is only testing program:

Code:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

void MCU_init(void){  /* ### MC9S08AW60_64 "Cpu" init code ... */  /*  PE initialization code after reset */  /* Common initialization of the write once registers */  SMCLK &= (unsigned char)~0x17;                       /*  System clock initialization */  ICGC2 = 0x00;                                        while(!ICGS1_ERCS) {                 /* Wait until external reference is not stable */  }  /* Common initialization of the CPU registers */  PTASE = 0xFF;                                        PTBSE = 0xFF;                                        PTCSE |= (unsigned char)0x7F;                                 PTDSE = 0xFF;                                        PTESE = 0xFF;                                        PTFSE = 0xFF;                                        PTGSE |= (unsigned char)0x7F;                                 PTADS = 0x00;                                        PTBDS = 0x00;                                        PTCDS = 0x00;                                        PTDDS = 0x00;                                        PTEDS = 0x00;                                        PTFDS = 0x00;                                        PTGDS = 0x00;                                        /* ### Init_GPIO init code */  PTBDD |= (unsigned char)0x07;                                 /* ### Init_COP init code */  SRS = 0xFF;                                        /* ### Init_TPM init code */  TPM2SC = 0x00;                                        TPM2MOD = 0x8954;                                        (void)(TPM2SC == 0);                                     TPM2SC = 0x4E;                                        /* ### */  asm CLI;                             /* Enable interrupts */} /*MCU_init*/void _Startup(void);void main(void) {  MCU_init(); /* call Device Initialization */  /* include your code here */  PTBD_PTBD0 = 1;  PTBD_PTBD1 = 1;  PTBD_PTBD2 = 1;  for(;;) {    __RESET_WATCHDOG();  /* please make sure that you never leave main */  }}interrupt 0 void isrVreset (void) {  _Startup();}

And there is a problem
while(!ICGS1_ERCS) {                 /* Wait until external reference is not stable */
}
The while loop is looping forever, so this coase overflow of the watchdog and the reset of the microcontroler. I don't know where could be a problem.  :smileysad:

Thank you for help!!!


Labels (1)
0 Kudos
17 Replies

908 Views
thisobj
Contributor III
Mica,

You could try one of the following:

1. Try a new xtal identical to the one you are now using.
2. Try a lower frequency xtal as a test (example 4MHz).  Of course c8 and c9 may have to change according to manufacturer's recommendation.
3. Look at section 2.3.2 in document  MC9S08AW60.pdf which discusses the xtal circuit and the recommended capacitor/resistor types and values.

Frank


0 Kudos

908 Views
thisobj
Contributor III
Mica,

Bigmac raises a good point.  It could be the external clock circuit or some other trace/component problem.  I can see nothing wrong with the register values you are using. For testing purposes, you might further narrow the problem to the external xtal circuit by using the internal clock.
You could do this as follows:

ICSC1 = 0x08;  // internal clock
ICSC2 = 0x00;

(bgn: edit/add)

If you elect to use the internal clock, you would wait on the ICGS1_LOCK to set instead of ERCS as:

  while( !ICGS1_LOCK);     /* pause execution until the FLL has locked */

(end: edit/add)

Frank


Message Edited by thisobj on 2007-06-28 03:02 PM
0 Kudos

908 Views
admin
Specialist II
Code:
void MCU_init(void){  /* ### MC9S08AW60_64 "Cpu" init code ... */  /*  PE initialization code after reset */  /* Common initialization of the write once registers */  /* SOPT: COPE=0,COPT=1,STOPE=0 */  SOPT = 0x53;                                        /* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=1,BGBE=0 */  SPMSC1 = 0x1C;                                        /* SPMSC2: LVWF=0,LVWACK=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,PPDC=0 */  SPMSC2 = 0x00;                                        /* SMCLK: MPE=0,MCSEL=0 */  SMCLK &= (unsigned char)~0x17;                       /*  System clock initialization */  /* ICGC1: HGO=1,RANGE=1,REFS=1,CLKS1=1,CLKS0=0,OSCSTEN=1,LOCD=1 */  ICGC1 = 0xF6;                                        /* ICGC2: LOLRE=0,MFD2=0,MFD1=0,MFD0=0,LOCRE=0,RFD2=0,RFD1=0,RFD0=0 */  ICGC2 = 0x00;                                        while(!ICGS1_ERCS) {                 /* Wait until external reference is not stable */  }  /* Common initialization of the CPU registers */  /* PTASE: PTASE7=1,PTASE6=1,PTASE5=1,PTASE4=1,PTASE3=1,PTASE2=1,PTASE1=1,PTASE0=1 */  PTASE = 0xFF;                                        /* PTBSE: PTBSE7=1,PTBSE6=1,PTBSE5=1,PTBSE4=1,PTBSE3=1,PTBSE2=1,PTBSE1=1,PTBSE0=1 */  PTBSE = 0xFF;                                        /* PTCSE: PTCSE6=1,PTCSE5=1,PTCSE4=1,PTCSE3=1,PTCSE2=1,PTCSE1=1,PTCSE0=1 */  PTCSE |= (unsigned char)0x7F;                                 /* PTDSE: PTDSE7=1,PTDSE6=1,PTDSE5=1,PTDSE4=1,PTDSE3=1,PTDSE2=1,PTDSE1=1,PTDSE0=1 */  PTDSE = 0xFF;                                        /* PTESE: PTESE7=1,PTESE6=1,PTESE5=1,PTESE4=1,PTESE3=1,PTESE2=1,PTESE1=1,PTESE0=1 */  PTESE = 0xFF;                                        /* PTFSE: PTFSE7=1,PTFSE6=1,PTFSE5=1,PTFSE4=1,PTFSE3=1,PTFSE2=1,PTFSE1=1,PTFSE0=1 */  PTFSE = 0xFF;                                        /* PTGSE: PTGSE6=1,PTGSE5=1,PTGSE4=1,PTGSE3=1,PTGSE2=1,PTGSE1=1,PTGSE0=1 */  PTGSE |= (unsigned char)0x7F;                                 /* PTADS: PTADS7=0,PTADS6=0,PTADS5=0,PTADS4=0,PTADS3=0,PTADS2=0,PTADS1=0,PTADS0=0 */  PTADS = 0x00;                                        /* PTBDS: PTBDS7=0,PTBDS6=0,PTBDS5=0,PTBDS4=0,PTBDS3=0,PTBDS2=0,PTBDS1=0,PTBDS0=0 */  PTBDS = 0x00;                                        /* PTCDS: PTCDS6=0,PTCDS5=0,PTCDS4=0,PTCDS3=0,PTCDS2=0,PTCDS1=0,PTCDS0=0 */  PTCDS = 0x00;                                        /* PTDDS: PTDDS7=0,PTDDS6=0,PTDDS5=0,PTDDS4=0,PTDDS3=0,PTDDS2=0,PTDDS1=0,PTDDS0=0 */  PTDDS = 0x00;                                        /* PTEDS: PTEDS7=0,PTEDS6=0,PTEDS5=0,PTEDS4=0,PTEDS3=0,PTEDS2=0,PTEDS1=0,PTEDS0=0 */  PTEDS = 0x00;                                        /* PTFDS: PTFDS7=0,PTFDS6=0,PTFDS5=0,PTFDS4=0,PTFDS3=0,PTFDS2=0,PTFDS1=0,PTFDS0=0 */  PTFDS = 0x00;                                        /* PTGDS: PTGDS6=0,PTGDS5=0,PTGDS4=0,PTGDS3=0,PTGDS2=0,PTGDS1=0,PTGDS0=0 */  PTGDS = 0x00;                                        /* ### Init_GPIO init code */  /* PTBDD: PTBDD2=1,PTBDD1=1,PTBDD0=1 */  PTBDD |= (unsigned char)0x07;                                 /* ### Init_COP init code */  SRS = 0xFF;                          /* Clear WatchDog counter */  /* ### Init_TPM init code */  /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */  TPM2SC = 0x00;                       /* Stop and reset counter */  TPM2MOD = 0x8954;                    /* Period value setting */  (void)(TPM2SC == 0);                 /* Overflow int. flag clearing (first part) */  /* TPM2SC: TOF=0,TOIE=1,CPWMS=0,CLKSB=0,CLKSA=1,PS2=1,PS1=1,PS0=0 */  TPM2SC = 0x4E;                       /* Int. flag clearing (2nd part) and timer control register setting */  /* ### */  asm CLI;                             /* Enable interrupts */} /*MCU_init*/


I  made a new initialization function, but it cause only that watchdog doesn't overflow but that check of the "external reference" still looping forever ....
0 Kudos

908 Views
bigmac
Specialist III
Hello,
 
Looking at the layout of your board, the ground return path from the capacitors associated with the oscillator seems
to be very long and indirect, and I would anticipate there would be significant inductance.  This may prevent correct
operation of the oscillator, especially at a frequency of 14MHz.  It would be preferable for the return path to go directly
to pin 39 (Vss) using a broad track to minimize inductance - possibly via a "ground plane" on the other side of the board.
 
I cannot say for certain this is the cause of your problem.  You might try soldering a wire directly back to pin 39, and
see if this has any effect.
 
Regards,
Mac
 
0 Kudos

908 Views
admin
Specialist II
bigmac: Thank you. I'll try to reduce the distace between XTAL capacitors and 39th pin. :smileywink:

thisobj: God idea. I forgot write that when i use internal clock with or without FFL, program is runnig correct... :smileyindifferent:


0 Kudos

908 Views
admin
Specialist II
Oh no. :smileysad: Nothing happend. I try to solder wire closer to XTAL capacitors, but the situation don't get better. Program it's still checking if it's external reference stable. :smileysad:

I wonder that the capacity of the XTAL capacitors is excessive. Should I decrease the capacity? Excessive capacity could cause errors?
0 Kudos

908 Views
Andrey
Contributor III
You also need to reset the watchdog inside the while loop:

while(!ICGS1_ERCS){   
     __RESET_WATCHDOG();
}

It's also helpful to check for the LOCK:

while((ICGS1_LOCK == 0)||(ICGS1_ERCS==0){   
    __RESET_WATCHDOG();
}

then you can set:
ICGC2_LOCRE = 1; // enable reset if clock fails
ICGC2_LOLRE = 0; // desable reset if lock fails
which helps in noisy environments

You might also have a bad crystal

p.s. you need a crystal that is 10Mhz or slower in order for the system to work. Because the minimum multiplier is 2 and the maximum bus frequency is 20Mhz so, 14Mhz crystal is too fast.

Try going down as low as 6pF for the caps.
0 Kudos

908 Views
thisobj
Contributor III
Hello Andrey,

A few comments on your comments here (your comments indented):

It's also helpful to check for the LOCK:

while((ICGS1_LOCK == 0)||(ICGS1_ERCS==0){   
    __RESET_WATCHDOG();
}
The LOCK bit is valid only if FLL is engaged and LOCK is achieved, which is not the case with Mica's posted code since he is using FBE mode; only ERCS bit is relavent in his case.  Also, Mica's last posted code does not use the watchdog.

then you can set:
ICGC2_LOCRE = 1; // enable reset if clock fails
ICGC2_LOLRE = 0; // desable reset if lock fails
which helps in noisy environments
These bits are valid only if FLL engaged.  Again, Mica's code is using FBE mode.

You might also have a bad crystal

p.s. you need a crystal that is 10Mhz or slower in order for the system to work. Because the minimum multiplier is 2 and the maximum bus frequency is 20Mhz so, 14Mhz crystal is too fast.

Try going down as low as 6pF for the caps.

The 10MHz limit applies if FLL is engaged.  In FBE mode ( FLL not engaged), crystal may be up to 16MHz.

Frank




Message Edited by thisobj on 2007-06-29 03:33 PM
0 Kudos

908 Views
admin
Specialist II
I'am absolutely desperate . Nothing help's.  I'll try to change crystals and  s_h_i_t  happened.  I  was so desperate  that  I  try  build  same  device  bud  with  MC9S08AW60CFUE  and s_h_i_t happened again.

I'am  afraid  that  i will be  fired from my job. I'am so  stupid  that  I  chose Freescale microntrolers  a  should chose ATMEL AVR or PIC. :smileysad:

But I don't understand It. When I was do somethink with Freescale MCU everything was beatifull. But now when I use Freescale MCU for my job in entrance project everything s_h_i_t oneself. Dammit :smileysad: 


Message Edited by Mica on 2007-06-30 12:26 AM

Message Edited by Mica on 2007-06-30 12:27 AM
0 Kudos

908 Views
Andrey
Contributor III
Mica,

   It's not the freescale chip. Are you the only person in the company that has any idea about electronics? See if someone at work can help you out, who knows more about electroncs or microcontrollers. We can  try to help you, and give you tips, but can't really troubleshoot things like this virtually over the web.
0 Kudos

908 Views
Andrey
Contributor III
Mica I also noticed that you have 1M ohm resistor in parallel, try to change the value to 10M ohm.
0 Kudos

908 Views
rocco
Senior Contributor II
And one more thing to check, with respect to grounding . . .

I recall having problems with fast crystals when the metal can was not grounded.

Just a thought.
0 Kudos

908 Views
thisobj
Contributor III
Mica,

One other possibility is a damaged xtal load capacitor (c8 or c9).  I assume that these are ceramic.  Sometimes, mounting these by hand using a hot-air or solder gun can damage these rather fragile parts. 

Also, what is the xtal manufacturer's specified C-load?

Frank

0 Kudos

908 Views
bigmac
Specialist III
Hello,
 
You did not mention whether you had tried a much lower frequency crystal (e.g. 4 MHz), as previously suggested by Frank.  I am still of the opinion that your PCB layout is unsuited to high frequency operation.  At a lower frequency, the values of C8 and C9 are also likely to be less critical.  Using a low capacitance oscilloscope probe, you should be able to observe the oscilations at either side of the crystal.
 
Is there a particular reason you cannot use a lower frequency crystal in FEE mode?
 
Regards,
Mac
 
0 Kudos

908 Views
peg
Senior Contributor IV
Hi Mica,
 
Whilst I can understand your frustration in trying to get this oscillator going, I feel you have overstepped the mark with your "rant" in your latest post.
It can only serve to drive people away that may otherwise have continued to attempt to assist you.
I would suggest that if you wish to continue with this that you return with a more humble and professional attitude.
I have not to date participated in this thread as I have had nothing to add to what has already been said and I do not have any direct experience with this MPU. However I have been confirming, behind the scenes, that what has been said has been correct.
 
0 Kudos

908 Views
thisobj
Contributor III
Hello Mica,

Are you initializing register ICGC1?  I couldn't find that anywhere in your code.
If you're using an external crystal reference, you must set this register to something other than the default RESET value.

Frank
0 Kudos

908 Views
admin
Specialist II
I'am using "Device Initialization" in CW. So i believe, that the MCUInit fuction is correct. But now I'am not  sure, I'll try to write initializitation without "Device Initialization".
0 Kudos