Mc9s12
单片机PWM模块为什么要初始化锁相环?
如果有可能,可否解释一下下面程序
初始化锁相环 */
/*************************************************************/
void INIT_PLL(void)
{
CLKSEL &= 0x7f; //set OSCCLK as sysclk
PLLCTL &= 0x8F; //Disable PLL circuit
CRGINT &= 0xDF;
#if(BUS_CLOCK == 40000000)
SYNR = 0x44;
#elif(BUS_CLOCK == 32000000)
SYNR = 0x43;
#elif(BUS_CLOCK == 24000000)
SYNR = 0x42;
#endif
REFDV = 0x81; //PLLCLK=2×OSCCLK×(SYNR+1)/(REFDV+1)=64MHz ,fbus=32M
PLLCTL =PLLCTL|0x70; //Enable PLL circuit
asm NOP;
asm NOP;
while(!(CRGFLG&0x08)); //PLLCLK is Locked already
CLKSEL |= 0x80; //set PLLCLK as sysclk
}
/*************************************************************/
/* 初始化PWM */
/*************************************************************/
void init_pwm(void)
{
PWMCTL_CON01= 1; //联结通道0,1为16位的PWM
PWMPOL_PPOL1= 1; //通道01的极性为高电平有效
PWMPRCLK = 0x55; //A时钟和B时钟的分频系数为32,频率为1MHz
PWMSCLA = 25; //SA时钟频率为20KHz
PWMCLK =0x02; //通道01用SA时钟作为时钟源
PWMPER01 = 200; //通道01的周期为100Hz
PWMDTY01 = 0; //通道01的占空比为0%
PWME_PWME1 = 1; //使能通道01
}
一周热门 更多>