2

我正在尝试为每个对角线使用一个 PWM 发生器(在我的情况下为 PWM1 和 PWM4)来控制 H 桥转换器。

我希望能够同时控制频率和占空比。为此,我在 PWM4 周期开始时生成触发中断,然后更新两个 PWM 通道的周期、相位和占空比寄存器。

问题是,当此更新发生时,一段时间内会出现一些意外行为。见图片。

PWM4 为青色,PWM1 为品红色,当 PWM4 触发中断发生时黄色切换。

PWM1(洋红色)似乎更新为较慢的频率(应该如此),但 PWM4 继续在旧频率上运行另一段时间。PWM1 还会产生一个更短的脉冲。我测量了更新周期、占空比和相位寄存器值所需的时间,大约是 1us,所以这应该不是问题。以下是 PWM 配置:

void PWM4Config()  {

ANSELEbits.ANSE6 = 0;
ANSELEbits.ANSE7 = 0;
TRISEbits.TRISE6 = 0;
TRISEbits.TRISE7 = 0;

PTPER = 7002;                   //period je 50us
PTCON2bits.PCLKDIV = 0b000;     //1:1  

//fazni stavovi
PHASE4 = 0;
SPHASE4 = 0;

//duty
PDC4 = 3501;
SDC4 = 3501;
//dead time
DTR4 = 0;
//set PWM mode to independent, active high
IOCON4bits.PENH = 1;
IOCON4bits.PENL = 1;
IOCON4bits.POLH = 0;
IOCON4bits.POLL = 0;
IOCON4bits.PMOD = 0b11;
IOCON4bits.OVRENH = 0;
IOCON4bits.OVRENL = 0;
IOCON4bits.OVRDAT = 0b00;
IOCON4bits.FLTDAT = 0b00;
IOCON4bits.CLDAT = 0b00;
IOCON4bits.SWAP = 0;
IOCON4bits.OSYNC = 0;

//set primary time base, edge aligned, independent duty cycles
PWMCON4 = 0x0000;
//PWMCON4bits.IUE = 1;  //privremeno
//config faults
FCLCON4 = 0x0003;

//config trigger & interrupt
IFS6bits.PWM4IF = 0;
IEC6bits.PWM4IE = 1;  
TRGCON4 = 0x0000;       //triger at every period of pwm
TRIG4 = 0x0000;         //triger at start of pwm period
PWMCON4bits.TRGIEN = 0;


}

void PWM1Config()  {

ANSELEbits.ANSE0 = 0;
ANSELEbits.ANSE1 = 0;
TRISEbits.TRISE0 = 0;
TRISEbits.TRISE1 = 0;

PTPER = 7002;                   //period je 50us
PTCON2bits.PCLKDIV = 0b000;     //1:1  

//fazni stavovi
PHASE1 = 3051;
SPHASE1 = 3501;

//duty
PDC1 = 3501;
SDC1 = 3501;
//dead time
DTR1 = 0;
//set PWM mode to independent, active high
IOCON1bits.PENH = 1;
IOCON1bits.PENL = 1;
IOCON1bits.POLH = 0;
IOCON1bits.POLL = 0;
IOCON1bits.PMOD = 0b11;
IOCON1bits.OVRENH = 0;
IOCON1bits.OVRENL = 0;
IOCON1bits.OVRDAT = 0b00;
IOCON1bits.FLTDAT = 0b00;
IOCON1bits.CLDAT = 0b00;
IOCON1bits.SWAP = 0;
IOCON1bits.OSYNC = 0;

//set primary time base, edge aligned, independent duty cycles
PWMCON1 = 0x0000;
//PWMCON1bits.IUE = 1;  //privremeno
//config faults
FCLCON1 = 0x0003;

//config trigger & interrupt
//IFS5bits.PWM1IF = 0;
//IEC5bits.PWM1IE = 1;  
//TRGCON1 = 0x0000;       //triger na svakom periodu pwm-a
//TRIG1 = 0x0000;         //triger je na pocetku pwm-a
//PWMCON1bits.TRGIEN = 0;


}

它们被设置为独立模式,使用主时基。

4

1 回答 1

1

我通过在更新两个 PWM 通道的占空比和频率之前禁用 PWM(通过清除 PTEN 位)解决了这个问题,然后立即启用它。结果是可能有一个 PWM 脉冲比更新时应有的短一些,但互补通道的脉冲重叠不会发生。这更像是一种解决方法,而不是真正的解决方案,但它对我来说是有目的的。

于 2016-09-03T19:08:44.260 回答