本帖最后由 mtraveler 于 2011-7-15 13:48 编辑
void pwm_init(void)
{
PINSEL4=0x00000001; //使用PWM1
PWM1PR = 0x0; // 不分频,计数频率为Fpclk
PWM1MCR = 0x03; // 设置PWMMR0匹配时复位PWMTC并产生中断
PWM1PCR = 1<<9;//0x0400; // 允许PWM1输出,单边PWM
PWM1MR0 = Fpclk/25000000;//Fpclk;//40000//Fpclk/2;
PWM1MR1 = PWM1MR0* 1/ 2; //占空比
PWM1LER = 0x03; // PWM0和PWM1匹配锁存
PWM1TCR = 0x02; // 复位PWMTC
PWM1TCR = 0x09; // 启动PWM输出
PWM1TCR = 0x02; // 复位PWMTC
PWM1TCR = 0x09; // 启动PWM输出
}
void Pwm0Handler (void) __irq
{
PWM1IR = 1; /* clear interrupt flag */
IENABLE; /* handles nested interrupt */
if(c_40ns<24999999) c_40ns++;
else
{
c_40ns=0;
FIO0PIN^=0X01;
}
IDISABLE;
VICVectAddr = 0; /* Acknowledge Interrupt */
}
晶振20M,产生50M的时钟,PWM的时钟配置位50M,芯片LPC2368 ,为什么PWM波正常,中断就不正常呢??? |