2

我开发了一个简单的程序来在 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,反之亦然)即使它应该是数字 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 */
4

2 回答 2

1

该问题与 IOCONxbits 寄存器的写保护有关。我添加了以下行:

_FDEVOPT( PWMLOCK_OFF );

这解决了问题。

于 2015-07-18T18:51:01.627 回答
1

我在使用 dspic33ev32GP002 时遇到了同样的问题,并像这样更改了配置位:

// FDEVOPT
#pragma config PWMLOCK = OFF 

这对我有用。

于 2015-12-23T13:08:55.163 回答