我开发了一个简单的程序来在dsPIC33EV256GM002上产生PWM波形,但我无法禁用它。我使用PWM1和PWM2,我会在PWM1L1引脚(DIP封装上的引脚26)上产生PWM波形,将PWM1H1(DIP封装上的引脚25)保持为数字I / O. 完全是PWM寄存器设置: IOCON1bits.PENL = 1; / * PWM1L由PWM模块 /控制 IOCON1bits.PENH = 0; / PWM1H由GPIO模块控制* / 应该这样做,但是,使用和示波器,我注意到PWM1H1引脚上的PWM波形,具有相反的值(当PWM1L为1时PWM1H为0且veceversa),即使它应该是数字I / O.
您是否发现任何类似的问题?
非常感谢您的帮助与合作
问候
我使用了以下代码:
TRISBbits.TRISB10 = 0; /* Set as a digital output */
TRISBbits.TRISB11 = 0; /* Set as a digital output */
TRISBbits.TRISB12 = 0; /* Set as a digital output */
TRISBbits.TRISB13 = 0; /* Set as a digital output */
TRISBbits.TRISB14 = 0; /* Set as a digital output */
TRISBbits.TRISB15 = 0; /* Set as a digital output */
LATBbits.LATB10 = 0; /* Set as a digital output */
LATBbits.LATB11 = 0; /* Set as a digital output */
LATBbits.LATB12 = 0; /* Set as a digital output */
LATBbits.LATB13 = 0; /* Set as a digital output */
LATBbits.LATB14 = 0; /* Set as a digital output */
LATBbits.LATB15 = 0; /* Set as a digital output */
PORTBbits.RB10=0;
PORTBbits.RB11=0;
PORTBbits.RB12=0;
PORTBbits.RB13=0;
PORTBbits.RB14=0;
PORTBbits.RB15=0;
PTPER = 4000;
/*~~~~~~~~~~ PWM1 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
IOCON1bits.PENL = 1; /* PWM1L is controlled by PWM module */
IOCON1bits.PENH = 0; /* PWM1H is controlled by GPIO module */
IOCON1bits.PMOD = 0; /* Select Independent Output PWM mode */
PDC1 = 500; /* Initial Duty cycle */
DTR1 = 0; /* Deadtime setting */
ALTDTR1 = 0; /* Deadtime setting */
PHASE1 = 0; /* No phase shift */
/*~~~~~~~~~~~ PWM2 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
IOCON2bits.PENH = 1; /* PWM2H is controlled by PWM module */
IOCON2bits.PENL = 0; /* PWM2L is controlled by GPIO module */
IOCON2bits.PMOD = 0; /* Select Independent Output PWM mode */
PDC2 = 2000; /* Initial Duty cycle */
DTR2 = 0; /* Deadtime setting */
ALTDTR2 = 0; /* Deadtime setting */
PHASE2 = 0; /* */
PTCONbits.PTEN = 1; /* Enable the PWM Module */
答案 0 :(得分:1)
我遇到了与dspic33ev32GP002相同的问题并更改了配置位,如下所示:
// FDEVOPT
#pragma config PWMLOCK = OFF
这对我有用。
答案 1 :(得分:0)
问题与IOCONxbits寄存器的写保护有关。 我添加了以下行:
_FDEVOPT( PWMLOCK_OFF );
这解决了这个问题。