AW60 Clock settings

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

AW60 Clock settings

3,607 Views
Andrey
Contributor III
I'm experiencing rather a strange thing with setting a clock on my AW60 system. I have a 10Mhz external crystal and I'm trying to set the system clock at 40Mhz but what ever values I specify for MFD (multiplier) or RFD (divider), I have the clock operating at 4Mhz I confirmed this with a serial communication to a PC and clock output pin.
Here's my code:

void initClock(void){
   ICGC2_MFD = 0b000; // clock multiplier = 4
   ICGC2_RFD = 0b000; // clock divider = 1;
   ICGC1 = 0b11111000; // configured for
   //                 1 ----------- // High gain operation
   //                    1 ---------- // high frequency range
   //                      1--------  // oscillator using crystal or resonator requested
    //                       11 ----- // FLL engaged, external reference
    //                          0--- // enabled in off mode
    //                             0 -- // loss of clock detection enabled
   //                                0 - // not writable

while ((ICGS1_LOCK==0)||(ICGS1_ERCS==0)){
  _RESET_WATCHDOG();
}
ICGC2_LOCRE = 1; // enable reset if clock fails
ICGC2_LOLRE = 0;  // enable interrupt if lock fails

Thanks for your support guys!

I just removed the crystal off the board, the clock still operates at 4Mhz!


Message Edited by Andrey on 2007-06-04 02:36 PM
Labels (1)
0 Kudos
Reply
7 Replies

524 Views
bigmac
Specialist III
Hello,
 
Firstly, to avoid any ambiguity over the "system clock" terminology, I presume you require a bus frequency of 20MHz.  From fig. 8.1 of the data sheet it can be seen that ICGOUT will have a frequency twice the bus clock, i.e. 40 MHz.  The SCI baud rate is based on the bus frequency.
 
If you are actually getting a bus frequency of approximately 4MHz (ICGOUT ~= 8 MHz), this is suggestive that you may still be in self-clocked mode, following reset, perhaps for some hardware related reason.  Although this would infer that you would remain within the while loop of your initialisation code.
 
I cannot see any obvious problem with your initialisation code.
 
Regards,
Mac
 
0 Kudos
Reply

524 Views
Andrey
Contributor III
Yes, 20Mhz bus is my goal. I checked and I thnk that I am indeed in the self-clocked mode. However I can run my software fine.  I can send and recieve the right characters (given that the baud generator is set correctly), But whatever I set the setting in the ICG register, I am still in the self-clocked mode.
0 Kudos
Reply

524 Views
peg
Senior Contributor IV
Hi Andrey,
 
This is quite possibly due to the high bit of CLKS being cleared before it gets to your initialisation. Once this is done you cannot use the external reference until reset. See the description of the bits in ICGC1.
 
0 Kudos
Reply

524 Views
bigmac
Specialist III
Hello,
 
Further to Peg's observation, the REFS bit within ICGC1 is also a write once bit.  If any zero write prior to your initialisation function call were to occur, this would prevent crystal oscillator mode from being selected, and the crystal would not oscillate.
 
Perchance are you also using Processor Expert for register initialisation?  A write to ICGC1 might be occurring.
 
Since you are (surprisingly) able to use the SCI in self-clocked mode, you might consider reading the value of ICGC1, converting to a binary or hexadecimal ASCI sequence, and sending the value.  This could be one means of verifying the actual register setting.
 
Regards,
Mac
 
0 Kudos
Reply

524 Views
Andrey
Contributor III
I'm not using PE, but I finally got it working, by pacing a write to the ICG register the first one in the program. So, I started to investigate where was it set before? And found that I didn't set the ICG register ever before, because I did not ever call the subroutine!  :smileyvery-happy:

Thanks for all of your help. Sometimes the problems are so simple that we overlook them.
0 Kudos
Reply

524 Views
bigmac
Specialist III
Hello,
 
The cause of the problem is not quite clear to me, nor what you did to fix it.  Perhaps you might like to elaborate a little further.  This could be very useful for others using the same device.
 
Regards,
Mac
 
0 Kudos
Reply

524 Views
Andrey
Contributor III
I simply forgot to call the routine that was initializing the clock.

That's why any changes that I was making in the routine never reflected in action. So, when I placed a piece of code that was writing to the ICG register, the first thing in the main program - it worked.

But I did learn a lot about troubleshooting the clock.
Tip: If you need to verify the bus frequency of the system, just configure the clock output (it is PTC2 on the HCS08AW60) to output the sub-divided frequency of the bus.

SMCLK_MPE =1;                // enable clock output
SMCLK_MCSEL = 0b111;  // divide the bus frequency by 14
                                            // (divided by the maximum to use with a slow oscilloscope,
                                            // or a high bus clock)
PTCDS = 1;                        // high gain enable (for good oscilliscope reading)
PTCSE_TCSE2 = 1;          // slew rate enable (makes a difference if using an internal/self clock)

Also,
See AN2494 Clock Usage Worksheet, very useful if you haven't seen it yet.

Another tip:
If using an external crystal/resonator try placing it as close as possible to the MCU. I overlooked this note in my previous project, and the clock could not start. I had to resolder it right next to the MCU. By "As close as possible" I mean on the same layer and side where the pads and pins comeout, about 0.2" from the pins will do. If it still doesn't start, lower the capasitor values from 22pf to 10pf.

Regards,
Andrey


Message Edited by Andrey on 2007-06-06 02:53 PM

Message Edited by Andrey on 2007-06-06 02:54 PM

Message Edited by Andrey on 2007-06-06 02:55 PM
0 Kudos
Reply