9S08AW32 hangs when using PE for external clock

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

9S08AW32 hangs when using PE for external clock

4,363 Views
fjrg76
Contributor IV
Hi!!

Using ProcessorExpert for specifying an external clock (crystal=8MHz, bus=16 MHz) and then loading the code into the S908AW32 through the "True time simulator and real-time debugger" tool, the program hangs waiting for the PLL to stabilize, so never reaches the main function.

It's not necesary to use the PE, however, setting up the clock module by hand is a bit confused, that's way I tried to use PE, but if there is some C code  for initializing the external clock  using (or even bypassing it) the FLL please let me know it (code, links, app-notes, etc). My board (of my own) already includes a 8 MHz crystal because I need a very exact base-time. I'm reading the app-note AN2494 and the AW32 datasheet, but some other help will be truly apreciated.

Thanks in advanced =)
Labels (1)
0 Kudos
Reply
12 Replies

2,263 Views
bigmac
Specialist III
Hello,
 
The following thread may be of interest.
 
Some if the ICG control bits within the ICGC1 register are write once only, so will all need to be written simultaneously.  Using a low capacitance probe on an oscilloscope, you might check whether you can observe any waveform between the crystal pins and ground.
 
A slightly different issue - If your timebase must be of good short term stability (low jitter), I would suggest that the clock for the relevant TPM module be derived directly from the crystal frequency, rather than the FLL output.  Use suitably configured XCLK instead of BUSCLK as the TPM clock source.
 
Regards,
Mac
 
I have just seen your most recent post with the code you are using.  You appear to be using an MFD value of 16, and an RFD value of 8, within the ICGC2 register.  For an 8 MHz crystal, aside from any startup problems you have, you seem to be attempting to achieve a FLL output frequency well in excess of the 40MHz upper limit (16*8).  The maximimum MFD value should be 4, giving 32MHz FLL output.
 


Message Edited by bigmac on 2008-02-03 04:05 PM
0 Kudos
Reply

2,263 Views
fjrg76
Contributor IV
Hi Big!!

Those values were calculated following the example in the datasheet (8.5.3), but edited for my needs:

Ficg=Fext*P*N/R; P=1, Fext=8M, Ficg=16M

N/R=Ficg/(Fext * P)=16M/8M=2

so N=MFD=16 and R=RFD=8, did I something wrong?? ... Yes something is very bad, but I have corrected to this

ICGC2=0b00000001;

with N=4 and R=2 :smileyhappy: ... but :smileysad: it is still not working. I've visited the link you told me, but doesn't say which was the final code, so I cannot follow it =( I feel that guy was talking to himself :smileyhappy:

I'm writing each of the two registers as a byte, so I guess there is not problem with that.

In one pin of the crystal I have 0V and in the other 5V and the distance from the crystal to the chip is aprox 0.375 in, and both are in the same plane, and  the caps are 39 pF

Using PE as an experiment, in the very first rutine when the debugger reaches the line 6 the it lost its track and resets, which makes me think that the crystal is not working in anyway

1 void _EntryPoint(void)
2 {
3  ... /* some init code */

4   /*  System clock initialization */
5  /* ICGC1: HGO=0,RANGE=1,REFS=0,CLKS1=1,CLKS0=0,OSCSTEN=1,LOCD=0,??=0 */
6  setReg8(ICGC1, 0x54);                
7  /* ICGC2: LOLRE=0,MFD2=0,MFD1=0,MFD0=0,LOCRE=0,RFD2=0,RFD1=0,RFD0=0 */
8  setReg8(ICGC2, 0x00);                

9    ... /* some other init code */

10  while(!ICGS1_ERCS) {                 /* Wait until external reference is not stable */
11  }

How can I tell the CPU to conect the PTG5..6 to work as a input/output crystal??



0 Kudos
Reply

2,263 Views
bigmac
Specialist III
Hello,
 
Do you also have a high value resistor (1-10 Mohm) between the two oscillator pins.  This is required to bias the oscillator wthin the linear region, to provide correct crystal start-up.  Even if the crystal were faulty, I would expect to see a voltage level at both pins of approximately one half Vdd.
 
Your new ICGC1 value is now problematic because you require REFS bit set to 1 for crystal operation.  The value used in your older post appeared to be OK.
 
Prior to entering the ERCS wait loop, or perhaps even within the loop, you should reset the COP timer to prevent timeout, just in case the crystal is slow to start.
 
Regards,
Mac
 
0 Kudos
Reply

2,263 Views
JimDon
Senior Contributor III
Ok, I think I got it. I have a Witztronic Viper board, which has an AW60 and an 8 Mhz xtal.

This code will set a 32 Mhz CLK, 16 Mhz bus clock.
It seems to lock just fine, i tested it. He used a 1 Meg bypass and 18 pf start caps.
I set High Gain, High Frequency, xtal modes. If you use low power it does not seem to lock.
Here is the schematic:
http://witztronics.com/product_info.php?products_id=39

Code:
void _EntryPoint(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,—–=1,˜™=0,??=0,??=1,??=1 */  setReg8(SOPT, 0x53);                    /* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */  setReg8(SPMSC1, 0x1C);                  /* SPMSC2: LVWF=0,LVWACK=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */  setReg8(SPMSC2, 0x00);                  /* SMCLK: MPE=0,MCSEL=0 */  clrReg8Bits(SMCLK, 0x17);               /*  System clock initialization */  /* ICGC1: HGO=1,RANGE=1,REFS=1,CLKS1=1,CLKS0=1,OSCSTEN=1,LOCD=0,??=0 */  setReg8(ICGC1, 0xFC);                   /* ICGC2: LOLRE=0,MFD2=0,MFD1=0,MFD0=0,LOCRE=0,RFD2=0,RFD1=0,RFD0=0 */  setReg8(ICGC2, 0x00);                   ICGTRM = *(unsigned char*)0xFFBE;    /* Initialize ICGTRM register from a non volatile memory */  while(!ICGS1_LOCK) {                 /* Wait */  }  /*** End of PE initialization code after reset ***/  __asm   jmp _Startup ;               /* Jump to C startup code */}

 




Message Edited by JimDon on 2008-02-03 01:49 AM

Message Edited by JimDon on 2008-02-03 01:51 AM
0 Kudos
Reply

2,263 Views
fjrg76
Contributor IV
HI Big!!

No, I don't have the parallel resistor :smileysad: so I' will get it and then solder it.

The REFS bit was set to 0 by ProcessorExpert, and I dont know why, but using a PE was an experiment to see what could be the right definition, but doesnt work.

I'll try the watch-dog to see what happen.

Thanks for you support, but for today is enough, I'm gonna sleep, and I hope to hear something from you soon. Thank you :smileyhappy:
0 Kudos
Reply

2,263 Views
bigmac
Specialist III
Hello,


fjrg76 wrote:
No, I don't have the parallel resistor
:smileysad: so I' will get it and then solder it.

The REFS bit was set to 0 by ProcessorExpert, and I dont know why, but using a PE was an experiment to see what could be the right definition, but doesnt work.


It is possible that PE may have cleared REFS bit if you had selected external oscillator option, rather than external crystal.  The first option requires a single pin, and the second option two pins for the external connection.

Regards,
Mac
 

0 Kudos
Reply

2,263 Views
JimDon
Senior Contributor III
Well, the I meg bypass is a requirement.

As are the caps. If you set it up like that, I know that the code I have shown will work.




Code:
 XTAL               EXTAL
  o                  0
  |                  |
  |                  |                 |     |-------|    |  o-----| XTAL  |----o  |     |-------|    |
  |         |        |
  |        ___       |
  |         _        |
  |                  |  o-----/\/\/\/\-----o
  |       1M         |
 ---                --- ---                ---  2 x 18-20pf  |                  |  |                  | ___                ___  _                  _

 


Message Edited by JimDon on 2008-02-03 09:39 AM
0 Kudos
Reply

2,263 Views
fjrg76
Contributor IV
Hi to everyone that helped me, specially Big and Jim, for your time and patience.
 
In fact, the 1M parallel resistor is needed :smileyhappy: I added and it worked. I was playing with some options (including those that I said before and the ones you told me) for ICGC1 and ICGC2 to see the differences in the CPU speed, and it worked for all of them.
 
By the way, the caps I'm using are both 33 pF, perhaps I should change them to the values you suggest me.
 
Thanks again and we'll see you around :smileyhappy:
0 Kudos
Reply

2,263 Views
JimDon
Senior Contributor III
Well, thanks for getting back to us.

The caps depend somewhat on the rock.
All the examples I looked had 18-20pf - If 33 works so be it.

0 Kudos
Reply

2,263 Views
bigmac
Specialist III
Hello again,

fjrg76 wrote:
So, I will add a question: how can I tell the CPU to use the PTG5..6 as a crystal input??

By setting the CLKS bits within ICGC1 to 10 or 11, and the REFS bit to 1.  The pins must be reserved out of reset, so the CLKS bits must not have been previously set to other than these values.
 
Regards,
Mac
 
0 Kudos
Reply

2,263 Views
JimDon
Senior Contributor III
How did you set the HGO and RANGE bits in the ICGC1 register?

0 Kudos
Reply

2,263 Views
fjrg76
Contributor IV
Hi Jim, below is the config I'm using.

I cannot see any signal from the crystal pins using an oscilloscope, so I'm wondering if pins PTG6 and PTG5 are being used by the ICG. Suposing there are noise and bad ground planes, I may see something (at least noisy) from the crystal, however I cannot see anything, which makes me think those pines are disconected from the ICG. The datasheet said  that if some conditions are not met (8.2.1 and 8.2.1), those pins are not used by the ICG. But I cannot understand them at all =(

Here something is talked about

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=6619&query.id=12364...

So, I will add a question: how can I tell the CPU to use the PTG5..6 as a crystal input??

Thanks =)

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



void main(void) {
    SOPT_COPE=0;

    ICGC1=0b11111000;
    ICGC2=0b01100011;
    while(ICGS1_LOCK==0);
   
    PTCDD_PTCDD6=1;

  EnableInterrupts; /* enable interrupts */
  /* include your code here */

    for(;:smileywink:{            /* for speed testing  */
        PTCD_PTCD6=1;
        PTCD_PTCD6=0;
    }

  for(;:smileywink: {
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}

0 Kudos
Reply