Microchip
直播中

张琪

7年用户 228经验值
私信 关注
[问答]

无法从dspic33fj128mc802获得任何pwm信号

嗨,各位,也许这在某处是一个简单的省略,但是我不能从dspic33fj128mc802的PWM1H1端口得到任何pwm信号。预期的输出应该是在RB14的TrISB语句,如你在下面的代码中看到的。我试着在没有PPS的情况下产生这个信号,但是没有运气!我会感激任何输入。注意。//PWM具有由电机控制单元include//Configuration Register-FOSCpragma config FCKSM=3//时钟切换和故障安全模式都被禁用pragma config OSCIOFNC=0//OSCO pin是通用I/O pinpragma config POSCMD=33//主振荡器被禁用//配置寄存器-FOSCSEL#pragma配置IESO=0//从用户选择的振荡器在复位#pragma配置FNOSC=7//选择FRC振荡器在复位//配置寄存器-电机控制PWM FPOR#pragma配置PWMPIN=0//A开始所有电机控制PWM输出在Resetpragma config HPOL=1//电机控制高输出为活动高pragma config LPOL=1//电机控制低输出为活动高//define PPSUnLock_builtin_write_OSCCONL(OSCCON&0xBF)//define PPSLock_builtin_write_OSCCONL(OSCCON|0)x40)int main(){//OSCTUNRegisCTUNRegisterCTCTCTCTCTCTCTCTUNbits.TUN=0; //选择FRC=7.37MHz///选择FRC=7.37MHz//7.37MHz///CLKDIV注册CLKDIV注册CLCDCDCDCDCDCDCDVV RegisterCLCLCLCDCDCDCDCDCDCDCDCDCDV比特.ROI=0;0;//选择FRC=7.37MHz=7.37MHz//CLKDIV RegisCLKDIV RegisCLKDIV注册注册CDDIVCDCDCDCDDIV比特.CLI=7.37MHz=0;ROI=0;ROI=0;//中断对时钟恢复没有影响,CLKDI时钟恢复CLKDIK28.8KHz->FCYCLKDIVbits.DOZEN=1;//DOZE定义cpu和外围时钟之间的比率//定义RB14作为PWM1H1TRISBbits的输出.TRISB14=0;//引脚RB14被指定为输出//PWM1时基控制寄存器P1TCONbits.PTEN=0;//不允许时钟传递到PWM1定时器yetP1TCONbits.PTCKPS。等于0;//Precale是1:1,因此Timer2时钟=28.8KHzP1TCONbits.PTMOD=0;//PWM1在自由运行模式//PWM1计数器和周期P1TMRbits.PTMR=0;//PWM1计数器寄存器中的初始值P1TPER=576;//PWM1周期寄存器->PWM周期//PWM1控制寄存器1PWM1CON1bits.PMOD3=1;//PWM1H3和PWM1L3输出是独立的modePWM1CON1bit.PMOD2=1;//PWM1H2和PWM1L2输出是独立的modePWM1CON1bit.PMOD1=1;//PWM1H1和PWM1L1输出是独立的modePWM1CON1bit.PEN3H=0;//PWM1H3禁用PWM1CON1bit.PEN2H=0;//PWM1H2禁用PWM1CON1bit.PEN1H=0。1; //PWM1H1启用PWM1CON1bits.PEN3L=0;//PWM1H3禁用PWM1CON1bits.PEN2L=0;//PWM1H2禁用PWM1CON1bits.PEN1L=0;//PWM1H1禁用//PWM1控制寄存器2PWM1CON2bits.IUE=0;//更新与时间基PWM1CON2bits.UDIS=0同步;//从周期和dut更新y周期寄存器被启用//PWM1占空比寄存器1P1DC1=29;//占空比寄存器1将产生1msec脉冲//PPSUnLock;//对PWM1H1//RPOR7bits使用RP14.RP14R=0;//将PWM1H1重定向到RP14//PPSLock;//启用时基控制寄存器P1TCONbits.PTEN=1;//启用时钟传递到PWM1时限(1);

以上来自于百度翻译


      以下为原文

    Hi guys,
Probably this is a simple omission somewhere, but I cannot get any pwm signal from PWM1H1 port of the dspic33fj128mc802. The expected output is supposed to be at RB14 by TRISB-statement as you see in the code below.  I tried to produce this signal with and without PPS, but no luck!  I would appreciate any input.   Take care.

// PWM has a single HIGH output generated by motor control unit
#include

// Configuration Register - FOSC
#pragma config FCKSM = 3    // both clock switching and fail-safe modes are disabled
#pragma config OSCIOFNC = 0 // OSCO pin is a general purpose I/O pin
#pragma config POSCMD = 3   // primary oscillators are disabled

// Configuration Register - FOSCSEL
#pragma config IESO = 0     // start with a user-selected oscillator at reset
#pragma config FNOSC = 7    // select FRC oscillator with postscalar at reset

// Configuration Register - Motor Control PWM FPOR
#pragma config PWMPIN = 0   // All Motor Control PWM outputs are active at Reset
#pragma config HPOL = 1     // Motor control HIGH outputs are active high
#pragma config LPOL = 1     // Motor control LOW outputs are active high

//#define PPSUnLock       __builtin_write_OSCCONL(OSCCON & 0xBF)
//#define PPSLock         __builtin_write_OSCCONL(OSCCON | 0x40)

int main ()
{

// OSCTUN Register
OSCTUNbits.TUN = 0;    // select FRC = 7.37MHz

// CLKDIV Register
CLKDIVbits.ROI = 0;    // interrrupts have no effect on clock recovery
CLKDIVbits.FRCDIV = 6; // FRCDIVN = FRC/64 = 7.37/64 = 115.15KHz -> FOSC
CLKDIVbits.DOZE = 1;   // FOSC/4 = 115.15/4 = 28.8KHz -> FCY
CLKDIVbits.DOZEN = 1;  // DOZE defines the ratio between cpu and peripheral clocks

// Define RB14 as an output for PWM1H1
TRISBbits.TRISB14 = 0;  // Pin RB14 is assigned as output

// PWM1 timebase control register
P1TCONbits.PTEN = 0;    // Do not enable the clock delivery to PWM1 timer yet
P1TCONbits.PTCKPS = 0;  // Prescale is 1:1 so Timer2 clock = 28.8KHz
P1TCONbits.PTMOD   = 0; // PWM1 is in free-running mode

// PWM1 counter and period
P1TMRbits.PTMR = 0;     // Initial value in PWM1 counter register
P1TPER = 576; // PWM1 period register -> PWM period

// PWM1 control register1
PWM1CON1bits.PMOD3 = 1; // PWM1H3 and PWM1L3 outputs are independent mode
PWM1CON1bits.PMOD2 = 1; // PWM1H2 and PWM1L2 outputs are independent mode
PWM1CON1bits.PMOD1 = 1; // PWM1H1 and PWM1L1 outputs are independent mode
PWM1CON1bits.PEN3H = 0; // PWM1H3 is disabled
PWM1CON1bits.PEN2H = 0; // PWM1H2 is disabled
PWM1CON1bits.PEN1H = 1; // PWM1H1 is enabled
PWM1CON1bits.PEN3L = 0; // PWM1H3 is disabled
PWM1CON1bits.PEN2L = 0; // PWM1H2 is disabled
PWM1CON1bits.PEN1L = 0; // PWM1H1 is disabled

// PWM1 control register2
PWM1CON2bits.IUE = 0; // Updates are synchronized with timebase
PWM1CON2bits.UDIS = 0; // Updates from period and duty cycle registers are enabled

// PWM1 duty cycle register1
P1DC1 = 29;    // Duty cycle register1 will produce 1msec pulse

//PPSUnLock;
// Use RP14 for PWM1H1
//RPOR7bits.RP14R = 0; //Redirect PWM1H1 to RP14
//PPSLock;

// Enable timebase control register
P1TCONbits.PTEN = 1;    // Enable the clock delivery to PWM1 timer

while (1);
}

回帖(2)

辛文斌

2019-5-31 10:29:59
我前面没有这个芯片的数据表,但是我已经设置了几种不同配置的PWM输出。需要查找的是:提供时基的是什么(有时是定时器,并且定时器需要运行)。pwm时基定时器是否实际运行(启用定时器中断并在其中粘贴断点)pwm模块是否实际运行(启用pwm中断并在其中粘贴断点)最后,如果所有这些工作正常,检查IOCONx寄存器(如果您的芯片上有这些寄存器),以确保pwm输出与引脚绑定。

以上来自于百度翻译


      以下为原文

    I don't have a datasheet for that chip in front of me, but I've set a few PWM outputs up in various configurations.  Some things to look for:

  • What is providing the time base (sometimes it's a timer and that timer needs to run).
  • Is the pwm timebase timer actually running (enable the timer interrupt and stick a breakpoint in there)
  • Is the pwm module actually running (enable the pwm interrupt and stick a breakpoint in there).
  • Finally, if all of those are working, check the IOCONx registers (if you have them on your chip) to make sure the pwm output is being tied to the pins.
举报

王荣

2019-5-31 10:41:38
事实上,这是一个MPLABX问题。它没有正确运行。我创建了一个相同的项目,然后它运行没有任何黑客。谢谢你的帮助。

以上来自于百度翻译


      以下为原文

    Actually, it was an mplabx problem.  It was not running correctly.  I created an identical project, and then it ran without any hick up.  Thank you for the help.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分