2

我可能只是用这些寄存器之一看不到森林,但我无法让 PWM 在dsPIC33FJ32MC102微控制器上工作(警告:大 PDF)我'米玩弄。我已经遵循了数据表和进一步的应用说明(警告:另一个 PDF)甚至代码示例,但我看不出我做错了什么,尽管在我的测试台上我得到了高输出的 Vcc 和接地低输出。我已将故障引脚都绑定到 Vcc 并禁用了注册键码,因此我的更改应该会看到一些效果。我究竟做错了什么?

#define FOSC    (3686400ULL)
#define FCY     (FOSC/2)

#include <xc.h>
#include <libpic30.h>

...

#pragma config PWMPIN = ON              // Motor Control PWM Module Pin Mode bit (PWM module pins controlled by PORT register at device Reset)
#pragma config PWMLOCK = OFF             

...

void main(void){

...

//setup PWM

//Clear faults
IFS3bits.PWM1IF     = 0;
IFS3bits.FLTA1IF    = 0;
IFS4bits.FLTB1IF    = 0;

//Setup dead times
P1DTCON1bits.DTAPS  = 0b00; //Dead time tick is 1 TCY
P1DTCON1bits.DTBPS  = 0b00;
P1DTCON1bits.DTA    = 10;    //Dead time is 10TCY ~= 3uS
P1DTCON1bits.DTB    = 10;
P1DTCON2bits.DTS1A  = 0;    //Active and Inactive transition dead times
P1DTCON2bits.DTS2A  = 0;    //0 takes A dead time
P1DTCON2bits.DTS3A  = 0;    //1 takes B dead time
P1DTCON2bits.DTS1I  = 1;
P1DTCON2bits.DTS2I  = 1;
P1DTCON2bits.DTS3I  = 1;

P1TCONbits.PTOPS    = 0b0000; //1 CPU tick = 1 PWM tick
P1TCONbits.PTCKPS   = 0b00;
P1TCONbits.PTMOD    = 0b00;
P1TCONbits.PTSIDL   = 0;      //Run when CPU idles

// no longer necessary since I disabled register write lock:
//    __builtin_write_PWMSFR(&P1FLTACON,0x0000,&PWM1KEY);
//    __builtin_write_PWMSFR(&P1FLTBCON,0x0000,&PWM1KEY);
//    __builtin_write_PWMSFR(&PWM1CON1 ,0x0077,&PWM1KEY);

PWM1CON1 = 0x0077;    //Enable all 3 channels
P1FLTACON = 0x0000;   //Disable faults
P1FLTBCON = 0x0000;

//Setup Wave freq/duty
//Fosc = 7.3728 MHz -> Fcy = 3.6864MHz
//Desire a PWM of 20250Hz (smaller scalar error than 20kHz)
//P1TPER = [Fcy/(Fpwm*Scalar)] - 1
//Therefore P1TPER = [3.6864M/(20250*1)] - 1 = 181;
P1TPER              = 181;
P1DC1               = 0x7FFF;   // 0x7FFF for 50%
P1DC2               = 0x7FFF;
P1DC3               = 0x7FFF;

P1OVDCON            = 0x3F00;   //Disable override; override disables PWM
PWM1CON2            = 0x0000;    
P1TCONbits.PTEN     = 1;        //Turn on

...

while(1);
}
4

1 回答 1

0

我相信您已将计时器设置为从 0 计数到 181 (P1TPER),然后重置并重复。但是您已将占空比寄存器设置为 0x7FFF,大于 181。所以我相信占空比值永远不会小于定时器值,因此输出永远不会改变。尝试将占空比寄存器设置为 181/2 = 90 以获得 50% 的占空比。

于 2014-05-12T21:02:22.227 回答