最近刚学pic电机控制,用的是dsPIC30f2010,采用全桥电路控制三相无刷电机,参考了微芯的程序,把程序最简单话了,但是没有PWM输出,不知道为什么,代码如下:
#include "p30F2010.h"
#define FCY 10000000 // xtal = 5.0Mhz; PLLx8
#define MILLISEC FCY/10000 // 1 mSec delay constant
#define FPWM 39000
#define POLEPAIRS 5 // number of pole pairs of the motor
#define INDEX 1 // Hall sensor position index
void InitMCPWM(void);
int main(void)
{
LATE = 0x0000;
TRISE = 0xFFC0; // PWMs are outputs
CNEN1 = 0x00E0; // CN5,6 and 7 enabled
CNPU1 = 0x00E0; // enable internal pullups
IFS0bits.CNIF = 0; // clear CNIF
IEC0bits.CNIE = 1; // enable CN interrupt
InitMCPWM();
while(1)
{
PWMCON1 = 0x0777; // enable PWM outputs
OVDCON =0x0210; //这里我把程序简化了,想直接看看有没有PWM输出
DelayNmSec(500);
} // end of while (1)
} // end of main
void InitMCPWM(void)
{
PTPER = FCY/FPWM - 1; // set the pwm period register
PWMCON1 = 0x0700; // disable PWMs
OVDCON = 0x0000; // allow control using OVD register
PDC1 = 200; // init PWM DC 1, 2 and 3 to 100
PDC2 = 200;
PDC3 = 200;
SEVTCMP = PTPER; // set ADC to trigeer at ...
PWMCON2 = 0x0F00; // 16 PWM values
PTCON = 0x8000; // start PWM however output ...
// is enabled by OVDCON which is OFF
}
求大神么指教啊 |