Clock speed

Hi after following James Lynch’s tutorial on getting started with the AT91SAM7 chip, I have found that the clock speed I get is much lower than it should be.

I am using the Olimex SAM7-256 header board. I have checked the lowlevelinit.c file for the clock settings. I can cause clock speed changes by changing these clock settings (observed with an oscilloscope by setting output pins on and off).

However, I can’t get the clock speed above 5.16MHz or so. The Olimex oscillator is 18.432 MHz. Any advice on increasing the clock speed to near 55 MHz (chip maximum) would be greatly appreciated. Here are my clock settings:

	// PMC Clock Generator PLL Register setup
	//
	// The following settings are used:  DIV = 14
	//                                   MUL = 72
	//                                   PLLCOUNT = 10
	//
	// Main Clock (MAINCK from crystal oscillator) = 18432000 hz (see AT91SAM7-EK schematic)
	// MAINCK / DIV = 18432000/14 = 1316571 hz
	// PLLCK = 1316571 * (MUL + 1) = 1316571 * (72 + 1) = 1316571 * 73 = 96109683 hz
	//
	// PLLCOUNT = number of slow clock cycles before the LOCK bit is set 
	//            in PMC_SR after CKGR_PLLR is written.
	//
	// PLLCOUNT = 10
	//
	// OUT = 0 (not used)
	// result: AT91C_CKGR_PLLR = 0x00000000480A0E   (PLL Register) 
	pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 14) |
                      (AT91C_CKGR_PLLCOUNT & (10<<8)) |
                      (AT91C_CKGR_MUL & (72<<16)));		//(AT91C_CKGR_MUL & (72<<16)));

	// Wait the startup time (until PMC Status register LOCK bit is set)
 	while(!(pPMC->PMC_SR & AT91C_PMC_LOCK));
 	
	// PMC Master Clock (MCK) Register setup
	//
	// CSS  = 3  (PLLCK clock selected)
	//
	// PRES = 1  (MCK = PLLCK / 2) = 96109683/2 = 48054841 hz
	//
	// Note: Master Clock  MCK = 48054841 hz  (this is the CPU clock speed)
	// result:  AT91C_PMC_MCKR = 0x00000007  (Master Clock Register)
	pPMC->PMC_MCKR = 0x7;

Issue not resolved.

Can anyone confirm they have achieved a clock speed greater than 45 MHz using an Olimex board, and if so, please include your source code.

Daniel

I am running a SAM7-EX256 board at 48MHz, I never tried to run it at 55MHz however.

This is the initialization code I am using:

  /*
   * Flash Memory: 1 wait state, about 50 cycles in a microsecond.
   */
  AT91C_BASE_MC->MC_FMR = (AT91C_MC_FMCN & (50 << 16)) | AT91C_MC_FWS_1FWS;

  /*
   * Watchdog disabled.
   */
  AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;

  /*
   * Enables the main oscillator and waits 56 slow cycles as startup time.
   */
  AT91C_BASE_PMC->PMC_MOR = (AT91C_CKGR_OSCOUNT & (7 << 8)) | AT91C_CKGR_MOSCEN;
  while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS))
    ;

  /*
   * PLL setup: DIV = 14, MUL = 72, PLLCOUNT = 10
   * PLLfreq = 96109714 Hz (rounded)
   */
  AT91C_BASE_PMC->PMC_PLLR = (AT91C_CKGR_DIV & 14) |
                             (AT91C_CKGR_PLLCOUNT & (10 << 8)) |
                             (AT91C_CKGR_MUL & (72 << 16));
  while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK))
    ;

  /*
   * Master clock = PLLfreq / 2 = 48054858 Hz (rounded)
   */
  AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_2;
  while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY))
    ;

The whole code is in the project linked in my signature.

regards,

Giovanni