gpt4 book ai didi

无法在 dsPIC33F 上初始化 PWM

转载 作者:太空宇宙 更新时间:2023-11-04 00:06:07 31 4
gpt4 key购买 nike

我可能只是在使用这些寄存器之一时遇到了一个看不见森林的时刻,但我无法让 PWM 在 dsPIC33FJ32MC102 上工作微 Controller (警告:大 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),然后重置并重复。但是您已将占空比寄存器设置为大于 181 的 0x7FFF。所以我相信占空比值永远不会小于定时器值,因此输出永远不会改变。尝试将占空比寄存器设置为 181/2 = 90 以获得 50% 的占空比。

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

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com