我可能只是有一个看不见的森林为树的时刻与这些寄存器之一,但我不能让脉宽调制工作的dsPIC33FJ32MC102微控制器(警告:大PDF)我正在玩我已经遵循了数据表和进一步的application note(警告:另一个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);
}

最佳答案

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

关于c - 无法在dsPIC33F上初始化PWM,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23574618/

10-09 08:44