microchip - dsPIC33EV256GM002 PWM 设置

标签 microchip pwm dspic

我开发了一个简单的程序来在 dsPIC33EV256GM002 上产生 PWM 波形,但我无法禁用它。我使用 PWM1 和 PWM2,并在 PWM1L1 引脚(DIP 封装上的引脚 26)上生成 PWM 波形,并将 PWM1H1(DIP 封装上的引脚 25)保持为数字 I/O。 理论上 PWM 寄存器设置: IOCON1 位.PENL = 1;/* PWM1L 由 PWM 模块控制 / IOCON1 位.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 */

最佳答案

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

_FDEVOPT( PWMLOCK_OFF );

这解决了问题。

关于microchip - dsPIC33EV256GM002 PWM 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31465695/

相关文章:

c - 是否可以用HI-TECH C为PIC12 MCU创建多线程程序

c - Fletcher 校验和从 32 位重制为 8 位

c++ - 在 C++ 中通过 ssh 远程发送 shell 命令

当其他 channel (同一定时器)具有 i2c 备用功能时,我可以使用不同的定时器 channel 吗

bit-manipulation - 如何旋转一个字中的位

c - 微型计算机,串口。请求多个字节

bluetooth - Microchip的双BLE模块RN-4677是否使用MLDP配置文件

c - 其他声音然后是原始 .wav 文件

c - 使用STM32L TIM PWM控制伺服电机

assembly - 如何在 PIC24F 汇编代码中实现循环