How to change clock freq of M9S12C128?

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

How to change clock freq of M9S12C128?

Jump to solution
1,368 Views
mehmedean
Contributor I

hi,

 

our microcontroller is running at 2 MHz and we want to make it 8 MHz. We also want to change prescaler to 1. How can I do that? Any help (with code) is appreciated. thanx.

Labels (1)
0 Kudos
1 Solution
375 Views
pgo
Senior Contributor V

 

Dear mehmedean,

 

Something like the following:

(Adjust   SYNR &  REFDV as required for your case - Read the manual!)

 

  INTCR &= ~0x40; // Disable int pin (PE0)
  PEAR  |=  0x10; // Disable ECLK (PE4)
  EnableInterrupts;

  // Not using PLL Clk
  CLKSEL_PLLSEL = 0;

  // Assuming a 8MHz crystal
  // PLL Clock = 2 * OscClk * (SYNR+1)/(REFDV+1), BUSClk = PLLClk/2
  // PLL Clock = 2 * 8MHz   * (   5+1)/(    1+1) = 48 MHz, BUSClk = 24 MHz
  // c.f. BUSClk = OscClk/2 = 8MHz / 2 = 4 MHz.
  SYNR  = 5;
  REFDV = 1;
 
  // Wait for PLL to lock
  while (CRGFLG_LOCK == 0) {
  }
 
  // Change to PLL Clock 
  CLKSEL_PLLSEL = 1;

 

Note that there are external components required for the PLL. There is a calculator available here:

 

http://www.freescale.com/files/microcontrollers/software_tools/initialization/boot_code_generation/H...

 

(or search for PLL calculator)

 

bye

 

View solution in original post

0 Kudos
2 Replies
376 Views
pgo
Senior Contributor V

 

Dear mehmedean,

 

Something like the following:

(Adjust   SYNR &  REFDV as required for your case - Read the manual!)

 

  INTCR &= ~0x40; // Disable int pin (PE0)
  PEAR  |=  0x10; // Disable ECLK (PE4)
  EnableInterrupts;

  // Not using PLL Clk
  CLKSEL_PLLSEL = 0;

  // Assuming a 8MHz crystal
  // PLL Clock = 2 * OscClk * (SYNR+1)/(REFDV+1), BUSClk = PLLClk/2
  // PLL Clock = 2 * 8MHz   * (   5+1)/(    1+1) = 48 MHz, BUSClk = 24 MHz
  // c.f. BUSClk = OscClk/2 = 8MHz / 2 = 4 MHz.
  SYNR  = 5;
  REFDV = 1;
 
  // Wait for PLL to lock
  while (CRGFLG_LOCK == 0) {
  }
 
  // Change to PLL Clock 
  CLKSEL_PLLSEL = 1;

 

Note that there are external components required for the PLL. There is a calculator available here:

 

http://www.freescale.com/files/microcontrollers/software_tools/initialization/boot_code_generation/H...

 

(or search for PLL calculator)

 

bye

 

0 Kudos
375 Views
mehmedean
Contributor I

Thank you pgo.

 

The code I used is below:

 

  // initialize the PLL
  CLKSEL_PLLSEL  = 0;     // Disengage PLL
  PLLCTL_PLLON   = 1;     // Turn on PLL
  SYNR  = 0x07;  // Set loop multiplier to 6 (SYNR = 5, mult=SYNR + 1)
  REFDV = 0x00;  // set input osc divider to 1 (REFDV = 0, div =REFDV+1)
  _asm("nop"); _asm("nop");   // Delay for stabilization
  while( CRGFLG_LOCK != 1){}; // Wait until clock circuit locks on
  CLKSEL_PLLSEL  = 1;                    // Engage PLL and go!

 

The code above is from somewhere on the internet :smileyhappy: .

0 Kudos