How to change clock freq of M9S12C128?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to change clock freq of M9S12C128?

ソリューションへジャンプ
1,790件の閲覧回数
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.

ラベル(1)
0 件の賞賛
返信
1 解決策
797件の閲覧回数
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 件の賞賛
返信
2 返答(返信)
798件の閲覧回数
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 件の賞賛
返信
797件の閲覧回数
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 件の賞賛
返信