[求助]
dspic33fj128mc804的PWM1波设置影响了uart,求解
|
只要一使能PWM1,串口的的输出端就出现2.5us宽的脉冲,频率好像和pwm设置的有关系。
而且pwm波的波形不是很正常,不是正常的方波,一个周期里会有两次低电平,不知道问题在哪里。哪位大侠做过的uart接收的数据控制pwm波占空比的
PWM2输出是正常的
这是pwm波的使能程序
void init_PWM()
{
P1TPER = 2404; /* P1TPER = ((1 / 400kHz) / 1.04ns) = 2404, where 400kHz //决定PWM波的工作频率
is the desired switching frequency and 1.04ns is PWM resolution. */
//2404----7khz
//1204----11.76k
/*~~~~~~~~~~~~~~~~~~~~~~~ PWM1 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
P1TCONbits.PTMOD = 0b00; //边沿对起
P1TCONbits.PTCKPS= 0b00; //预分频1:1
P1TCONbits.PTOPS = 0b00; //后分频1:1
PWM1CON1bits.PEN1H = 1; //使能PWM1H脚
PWM1CON1bits.PEN1L = 0; //使能PWM1L脚
PWM1CON1bits.PEN2H = 1; //使能PWM2H脚
PWM1CON1bits.PEN2L = 0; //使能PWM2L脚
PWM1CON1bits.PEN3H = 1; //使能PWM3H脚
PWM1CON1bits.PEN3L = 0; //使能PWM3L脚
PWM1CON1bits.PMOD1=1; //PWM脚处于独立输出模式,0为互补
PWM1CON1bits.PMOD2=1; //PWM脚处于独立输出模式,0为互补
PWM1CON1bits.PMOD3=1; //PWM脚处于独立输出模式,0为互补
PWM1CON2bits.SEVOPS = 0; //特殊事件后分频为1:1
PWM1CON2bits.IUE = 1; //立即更新P1DCX
PWM1CON2bits.OSYNC = 1; //强制输出在下一tcy边沿发生
PWM1CON2bits.UDIS = 0; //0:允许从占空比和周期缓冲寄存器更新
P1DC1 = 0; /*占空比设置,P1DC1=P1TPER,50%*/
P1DC2 = 0; /*占空比设置,P1DC2=P1TPER,50%*/
P1DC3 = 0; /*占空比设置,P1DC3=P1TPER,50%*/
_PWM1IE = 1; //允许PWM中断
_PWM1IP = 5; //中断优先级5
P1TCONbits.PTEN = 1; /* Enable the PWM Module */
///////////////////////////
P2TCONbits.PTMOD = 0b00; //边沿对起
P2TCONbits.PTCKPS= 0b00; //预分频1:1
P2TCONbits.PTOPS = 0b00; //后分频1:1
PWM2CON1bits.PEN1H = 1; //使能PWM1H脚
PWM2CON1bits.PEN1L = 0; //使能PWM1L脚
PWM2CON1bits.PMOD1=1; //PWM脚处于独立输出模式,0为互补
PWM2CON2bits.SEVOPS = 0; //特殊事件后分频为1:1
PWM2CON2bits.IUE = 1; //立即更新P1DCX
PWM2CON2bits.OSYNC = 1; //强制输出在下一tcy边沿发生
PWM2CON2bits.UDIS = 0; //0:允许从占空比和周期缓冲寄存器更新
P2DC1 = 0; /*占空比设置,P1DC1=P1TPER,50%*/
_PWM2IE = 1; //允许PWM中断
_PWM2IP = 5; //中断优先级5
// P2TCONbits.PTEN = 1; /* Enable the PWM Module */
} |
|
- 图片:IMG_5940.JPG [[url=]设为封面[/url]] [[url=]删除[/url]]
|
-
-