我想将dsPIC33EP32MC204微控制器用于电机控制应用。但是,即使我遵循了用户手册和系列参考手册,也无法使高速PWM工作(PWM2H引脚上没有PWM脉冲)。这是我的代码:
void Init_PWM(void)
{
PTCONbits.PTEN = 0; //PWM module is disabled
PTCONbits.PTSIDL = 0; // PWMx time base runs in CPU Idle mode
PWMCON2bits.FLTIEN = 0; // Fault interrupt is disabled and the FLTSTAT bit is cleared
PWMCON2bits.ITB = 0; // PTPER register provides timing for this PWM generator
PWMCON2bits.MDCS = 0; // PDCx register provides duty cycle information for this PWM generator
PWMCON2bits.MTBS = 0; // PWM generator uses the primary master time base for synchronization and as the clock source
PWMCON2bits.IUE = 0; // Updates to the active PDCx registers are synchronized to the PWMx period boundary
PTCON2bits.PCLKDIV = 0b000; // PWM Input Clock Prescaler
PWMCON2bits.CAM = 0; // Edge Aligned PWM
PWMCON2bits.DTC = 0b10; // Dead time function is disabled
IOCON2bits.PENH = 1; // PWMx module controls PWMxH pin
IOCON2bits.POLH = 0; // PWMxH pin is active-high
IOCON2bits.OVRENH = 0; // PWMx generator controls PWMxH pin
IOCON2bits.PMOD = 0b01; // PWM I/O pin pair is in Redundant Output mode
PHASE2 = 0; // No Phase Shift
PTPER = 0x4E20; // Period register
PTCONbits.PTEN = 1; //PWM module is enabled
}
main()函数中的相关代码:
TRISBbits.TRISB12 = 0;
Init_PWM();
PDC2 = 0x2710; //Duty Cycle
如果有人能告诉我为什么完成附加的配置后为什么看不到任何PWM脉冲,我将不胜感激。我究竟做错了什么?谢谢!