智能车制作

标题: 飞思卡尔XS128锁相环设置(网上找的,很好用) [打印本页]

作者: long5313828    时间: 2011-2-5 16:57
标题: 飞思卡尔XS128锁相环设置(网上找的,很好用)
/****************************************************************
Code Warrior 5.0
Target : MC9S12XS128
Crystal: 16.000Mhz


******************************************************************/


#include <hidef.h>      /* common defines and macros */
#include <MC9S12XS128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
void delayms(int ms)
{   
   int ii,jj;
   if (ms<1) ms=1;
   for(ii=0;ii<ms;ii++)
     for(jj=0;jj<3338;jj++);    //40MHz--1ms      
}
void SetBusCLK_16M(void)
{   
    CLKSEL=0X00;                // disengage PLL to system
    PLLCTL_PLLON=1;            // turn on PLL
    SYNR=0x00 | 0x01;     // VCOFRQ[7:6];SYNDIV[5:0]
                        // fVCO= 2*fOSC*(SYNDIV + 1)/(REFDIV + 1)
                        // fPLL= fVCO/(2 × POSTDIV)
                        // fBUS= fPLL/2
                        // VCOCLK Frequency Ranges  VCOFRQ[7:6]
                        // 32MHz <= fVCO <= 48MHz    00
                        // 48MHz <  fVCO <= 80MHz    01
                        // Reserved                  10
                        // 80MHz <  fVCO <= 120MHz   11               
    REFDV=0x80 | 0x01;  // REFFRQ[7:6];REFDIV[5:0]
                        // fREF=fOSC/(REFDIV + 1)
                        // REFCLK Frequency Ranges  REFFRQ[7:6]
                        // 1MHz <= fREF <=  2MHz       00
                        // 2MHz <  fREF <=  6MHz       01
                        // 6MHz <  fREF <= 12MHz       10
                        // fREF >  12MHz               11                        
                        // pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
    POSTDIV=0x00;       // 4:0, fPLL= fVCO/(2xPOSTDIV)
                        // If POSTDIV = $00 then fPLL is identical to fVCO (divide by one).
    _asm(nop);          // BUS CLOCK=16M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_32M(void)
{   
    CLKSEL=0X00;                // disengage PLL to system
    PLLCTL_PLLON=1;            // turn on PLL
    SYNR =0x40 | 0x03;  // pllclock=2*osc*(1+SYNR)/(1+REFDV)=64MHz;                     
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;  
    _asm(nop);          // BUS CLOCK=32M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_40M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x04;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=80MHz;
    _asm(nop);          //BUS CLOCK=40M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_48M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x05;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=96MHz;
    _asm(nop);          //BUS CLOCK=48M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_64M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x07;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=128MHz;
    _asm(nop);          //BUS CLOCK=64M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_80M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x09;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=160MHz;
    _asm(nop);          //BUS CLOCK=80M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_88M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x0a;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=176MHz;
    _asm(nop);          //BUS CLOCK=88M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_96M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x0b;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=192MHz;
    _asm(nop);          //BUS CLOCK=96M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_104M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x0c;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=208MHz;
    _asm(nop);          //BUS CLOCK=104M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}
void SetBusCLK_120M(void)
{   
    CLKSEL=0X00;                //disengage PLL to system
    PLLCTL_PLLON=1;            //turn on PLL
    SYNR =0xc0 | 0x0d;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=240MHz;
    _asm(nop);          //BUS CLOCK=120M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));      //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;                //engage PLL to system;
}

作者: lzsxtree    时间: 2011-2-7 01:43
SYNR =0xc0 | 0x05;                        
    REFDV=0x80 | 0x01;
在这两个设置的时候   从他给的值计算  等出的pllclock也不是96啊··   求过程  谢谢啦
作者: chiusir    时间: 2011-2-13 14:41
嗯,多个网站都有我们发布的,其他的代码大家也可以搜索一下,说不定就可以找到哦
作者: 近水楼台    时间: 2011-2-28 21:41
呵呵,我有看到过
作者: 若雪心情    时间: 2011-3-1 16:11
谢谢了
作者: cowboyyx    时间: 2012-1-8 22:23
谢啦……
作者: 二硫碘化钾    时间: 2012-1-14 18:07
谢楼主
作者: agogos    时间: 2012-1-15 21:46
120也能到?
作者: 马合店村    时间: 2012-2-11 13:21

作者: renqinglei    时间: 2012-2-11 13:58
谢谢了
作者: longli    时间: 2012-2-21 23:08

作者: SPRINGSKY    时间: 2012-3-6 09:42
标志一下。
作者: 遗旺的森麟    时间: 2012-4-12 10:40
谢啦!
作者: 封号式寂寞    时间: 2012-5-20 15:08
简单
作者: 益达的甜    时间: 2013-11-15 22:05
龙哥,给你涨涨人气
作者: 后天发货    时间: 2016-5-17 17:59
谢谢楼主!




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2