完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在生成的pwm波生成的栅极脉冲信号时,使用AQ生成的是方波 ,但是运行仿真时,使用示波器测试后发现是三角波,哪位大神可以帮忙解答一下程序如下
#include "Example_2823xEPwm_duty.h" #include "DSP2833x_Device.h" // DSP2833x Headerfile Include File #include "DSP2833x_Examples.h" // DSP2833x Examples Include File #define Hall_num1 0x5 //BLDC电机的霍尔相序 #define Hall_num2 0x1 #define Hall_num3 0x3 #define Hall_num4 0x2 #define Hall_num5 0x6 #define Hall_num6 0x4 //#include "DSP2833x_GlobalPrototypes.h" //Uint16 *ExRamStart = (Uint16 *)0x100000; void EPwm_Setup(void); //所有函数不用出现 void changephase(void); void Init_FMQ_voice(void); void Start_car(void); void Stop_car(void); void HVDMC_Protection(void); void MOS_V1_V4PWM(void) ; // 切换V1V4MOS驱动 void MOS_V1_V6PWM(void) ; // 切换V1V6MOS驱动 void MOS_V3_V6PWM(void) ; // 切换V3V6MOS驱动 void MOS_V3_V2PWM(void) ; // 切换V3V2MOS驱动 void MOS_V5_V2PWM(void) ; // 切换V5V2MOS驱动 void MOS_V5_V4PWM(void) ; // 切换V5V4MOS驱动 interrupt void MotorControl_ISR(void); Uint16 hall=0; //赋值0 在Example_2823xEPwm_duty.h外部变量 Uint16 ThreeHall_H[3]={0,0,0}; Uint16 ThreeHall_State=0; Uint16 ThreeHall_text[50]={0}; Uint16 ThreeHall_OldState=0; Uint16 ThreeHall_Speed_count=0; Uint16 count1=0; Uint16 count2=0; Uint16 duty=5000; void main(void) { //初始化系统、中断 InitSysCtrl(); //Initialize System Control InitPieCtrl(); // Initialize the PIE control registers to their default state. InitPieVectTable(); // Initialize the PIE vector table with pointers to the shell Interrupt // Interrupts that are used in this example are re-mapped to InitePwmGpio(); //Initialize pwmGPIO √ // InitECapGpio(); // √ Init_FMQ_voice(); // √ 在线调试所以先不对电机三霍尔的GPIO初始化 // InitFlash(); EPwm_Setup(); //初始化EPwm; // InitECap(); //初始化捕获 CpuTimer0Regs.PRD.all = 30000000; // 200ms 500MS 75 000000 HVDMC_Protection( ); //PWM的保护初始化 EALLOW; PieVectTable.EPWM1_INT = &MotorControl_ISR; //指向中断函数 PWM中断 EDIS; EALLOW; PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // 使能 PIE 时钟 PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // 中断向量 EPWM1 //启动EPWM 1 中断 EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation EPwm1Regs.ETSEL.bit.INTSEL = 1; // Enable interrupt CNT_zero event EPwm1Regs.ETPS.bit.INTPRD = 1; // 产生周期事件中断 EPwm1Regs.ETCLR.bit.INT = 1; // 使能更多中断 IER |= M_INT3; //使能 中断向量 EINT; // 使能全局中断 INTM ERTM; // 使能全局中断 DBGM EDIS; // Step 6. IDLE loop. Just sit and loop forever (optional): //Start_car(); for(;;); } /*换向函数*/ void changephase(void) { //捕获霍尔信号 ThreeHall_H[0]=GpioDataRegs.GPCDAT.bit.GPIO67; ThreeHall_H[1]=GpioDataRegs.GPCDAT.bit.GPIO68; ThreeHall_H[2]=GpioDataRegs.GPCDAT.bit.GPIO69; ThreeHall_State=ThreeHall_H[0]+(ThreeHall_H[1]<<1)+(ThreeHall_H[2]<<2); if ( ThreeHall_State!=ThreeHall_OldState ) { /*ThreeHall_text[count1]=ThreeHall_State; count1++; // 记录霍尔状态数据 if( count1>49) count1=0; */ switch (ThreeHall_State) { case Hall_num1: //换向 V1、V4导通 { MOS_V1_V4PWM(); break; } case Hall_num2: //换向 V1、V6导通 { MOS_V1_V6PWM() ; break; } case Hall_num3: //换向 V3、V6导通 { MOS_V3_V6PWM() ; break; } case Hall_num4: //换向 V3、V2导通 { MOS_V3_V2PWM() ; break; } case Hall_num5: //换向 V5、V2导通 { MOS_V5_V2PWM() ; break; } case Hall_num6: //换向 V5、V4导通 { MOS_V5_V4PWM() ; break; } default: { Stop_car(); } break; } } /* else if ( ThreeHall_State==ThreeHall_OldState ) // ( Hall_Three.Hall_State==Hall_Three.OldHall_State ) { ThreeHall_Speed_count++; if( ThreeHall_Speed_count>=5000 ) { Stop_car(); } switch (ThreeHall_State) { case Hall_num1: //换向 V1、V4导通 { MOS_V1_V4PWM(); break; } case Hall_num2: //换向 V1、V6导通 { MOS_V1_V6PWM() ; break; } case Hall_num3: //换向 V3、V6导通 { MOS_V3_V6PWM() ; break; } case Hall_num4: //换向 V3、V2导通 { MOS_V3_V2PWM() ; break; } case Hall_num5: //换向 V5、V2导通 { MOS_V5_V2PWM() ; break; } case Hall_num6: //换向 V5、V4导通 { MOS_V5_V4PWM() ; break; } default: { Stop_car(); } break; } } ThreeHall_OldState=ThreeHall_State;*/ } /*6种PWM状态的开关管*/ void MOS_V1_V4PWM(void) //开关管V1和V4导通 { // Set action EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=0x0; EPwm1Regs.AQCSFRC.bit.CSFB=0x1; EPwm2Regs.AQCSFRC.bit.CSFA=0x1; EPwm2Regs.AQCSFRC.bit.CSFB=0x2; EPwm3Regs.AQCSFRC.bit.CSFA=0x1; EPwm3Regs.AQCSFRC.bit.CSFB=0x1; EPwm1Regs.AQCTLA.bit.CAU = 0x2; EPwm1Regs.AQCTLA.bit.CAD = 0x1; EPwm1Regs.AQCTLB.bit.CBU = 0x0; EPwm1Regs.AQCTLB.bit.CBD = 0x0; EPwm2Regs.AQCTLA.bit.CAU = 0x0; EPwm2Regs.AQCTLA.bit.CAD = 0x0; EPwm2Regs.AQCTLB.bit.CBU = 0x2; EPwm2Regs.AQCTLB.bit.CBD = 0x2; EPwm3Regs.AQCTLA.bit.CAU = 0x0; EPwm3Regs.AQCTLA.bit.CAD = 0x0; EPwm3Regs.AQCTLB.bit.CBU = 0x0; EPwm3Regs.AQCTLB.bit.CBD = 0x0; EDIS; // Hall_Three.MOSFET_State = 0x32; } void MOS_V1_V6PWM(void) //开关管V1和V6导通 { // Set actions EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=0x0; EPwm1Regs.AQCSFRC.bit.CSFB=0x1; EPwm2Regs.AQCSFRC.bit.CSFA=0x1; EPwm2Regs.AQCSFRC.bit.CSFB=0x1; EPwm3Regs.AQCSFRC.bit.CSFA=0x1; EPwm3Regs.AQCSFRC.bit.CSFB=0x2; EPwm1Regs.AQCTLA.bit.CAU = 0x2; EPwm1Regs.AQCTLA.bit.CAD = 0x1; EPwm1Regs.AQCTLB.bit.CBU = 0x0; EPwm1Regs.AQCTLB.bit.CBD = 0x0; EPwm2Regs.AQCTLA.bit.CAU = 0x0; EPwm2Regs.AQCTLA.bit.CAD = 0x0; EPwm2Regs.AQCTLB.bit.CBU = 0x0; EPwm2Regs.AQCTLB.bit.CBD = 0x0; EPwm3Regs.AQCTLA.bit.CAU = 0x0; EPwm3Regs.AQCTLA.bit.CAD = 0x0; EPwm3Regs.AQCTLB.bit.CBU = 0x2; EPwm3Regs.AQCTLB.bit.CBD = 0x2; EDIS; //Hall_Three.MOSFET_State= 0x25; } void MOS_V3_V6PWM(void) //开关管V3和V6导通 { // Set actions EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=0x1; EPwm1Regs.AQCSFRC.bit.CSFB=0x1; EPwm2Regs.AQCSFRC.bit.CSFA=0x0; EPwm2Regs.AQCSFRC.bit.CSFB=0x1; EPwm3Regs.AQCSFRC.bit.CSFA=0x1; EPwm3Regs.AQCSFRC.bit.CSFB=0x2; EPwm1Regs.AQCTLA.bit.CAU = 0x0; EPwm1Regs.AQCTLA.bit.CAD = 0x0; EPwm1Regs.AQCTLB.bit.CBU = 0x0; EPwm1Regs.AQCTLB.bit.CBD = 0x0; EPwm2Regs.AQCTLA.bit.CAU = 0x2; EPwm2Regs.AQCTLA.bit.CAD = 0x1; EPwm2Regs.AQCTLB.bit.CBU = 0x0; EPwm2Regs.AQCTLB.bit.CBD = 0x0; EPwm3Regs.AQCTLA.bit.CAU = 0x0; EPwm3Regs.AQCTLA.bit.CAD = 0x0; EPwm3Regs.AQCTLB.bit.CBU = 0x2; EPwm3Regs.AQCTLB.bit.CBD = 0x2; EDIS; // Hall_Three.MOSFET_State = 0x54; } void MOS_V3_V2PWM(void) //开关管V3和V2导通 { // Set actions EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=0x1; EPwm1Regs.AQCSFRC.bit.CSFB=0x2; EPwm2Regs.AQCSFRC.bit.CSFA=0x0; EPwm2Regs.AQCSFRC.bit.CSFB=0x1; EPwm3Regs.AQCSFRC.bit.CSFA=0x1; EPwm3Regs.AQCSFRC.bit.CSFB=0x1; EPwm1Regs.AQCTLA.bit.CAU = 0x0; EPwm1Regs.AQCTLA.bit.CAD = 0x0; EPwm1Regs.AQCTLB.bit.CBU = 0x2; EPwm1Regs.AQCTLB.bit.CBD = 0x2; EPwm2Regs.AQCTLA.bit.CAU = 0x2; EPwm2Regs.AQCTLA.bit.CAD = 0x1; EPwm2Regs.AQCTLB.bit.CBU = 0x0; EPwm2Regs.AQCTLB.bit.CBD = 0x0; EPwm3Regs.AQCTLA.bit.CAU = 0x0; EPwm3Regs.AQCTLA.bit.CAD = 0x0; EPwm3Regs.AQCTLB.bit.CBU = 0x0; EPwm3Regs.AQCTLB.bit.CBD = 0x0; EDIS; // Hall_Three.MOSFET_State = 0x54; } void MOS_V5_V2PWM(void) //开关管V5和V2导通 { // Set actions EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=0x1; EPwm1Regs.AQCSFRC.bit.CSFB=0x2; EPwm2Regs.AQCSFRC.bit.CSFA=0x1; EPwm2Regs.AQCSFRC.bit.CSFB=0x1; EPwm3Regs.AQCSFRC.bit.CSFA=0x0; EPwm3Regs.AQCSFRC.bit.CSFB=0x1; EPwm1Regs.AQCTLA.bit.CAU = 0x0; EPwm1Regs.AQCTLA.bit.CAD = 0x0; EPwm1Regs.AQCTLB.bit.CBU = 0x2; EPwm1Regs.AQCTLB.bit.CBD = 0x2; EPwm2Regs.AQCTLA.bit.CAU = 0x0; EPwm2Regs.AQCTLA.bit.CAD = 0x0; EPwm2Regs.AQCTLB.bit.CBU = 0x0; EPwm2Regs.AQCTLB.bit.CBD = 0x0; EPwm3Regs.AQCTLA.bit.CAU = 0x2; EPwm3Regs.AQCTLA.bit.CAD = 0x1; EPwm3Regs.AQCTLB.bit.CBU = 0x0; EPwm3Regs.AQCTLB.bit.CBD = 0x0; EDIS; // Hall_Three.MOSFET_State = 0x54; } void MOS_V5_V4PWM(void) //开关管V5和V4导通 { // Set actions EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=0x1; EPwm1Regs.AQCSFRC.bit.CSFB=0x1; EPwm2Regs.AQCSFRC.bit.CSFA=0x1; EPwm2Regs.AQCSFRC.bit.CSFB=0x2; EPwm3Regs.AQCSFRC.bit.CSFA=0x0; EPwm3Regs.AQCSFRC.bit.CSFB=0x1; EPwm1Regs.AQCTLA.bit.CAU = 0x0; EPwm1Regs.AQCTLA.bit.CAD = 0x0; EPwm1Regs.AQCTLB.bit.CBU = 0x0; EPwm1Regs.AQCTLB.bit.CBD = 0x0; EPwm2Regs.AQCTLA.bit.CAU = 0x0; EPwm2Regs.AQCTLA.bit.CAD = 0x0; EPwm2Regs.AQCTLB.bit.CBU = 0x2; EPwm2Regs.AQCTLB.bit.CBD = 0x1; EPwm3Regs.AQCTLA.bit.CAU = 0x2; EPwm3Regs.AQCTLA.bit.CAD = 0x1; EPwm3Regs.AQCTLB.bit.CBU = 0x0; EPwm3Regs.AQCTLB.bit.CBD = 0x0; EDIS; // Hall_Three.MOSFET_State = 0x54; } void Stop_car(void) { EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=0x1; EPwm1Regs.AQCSFRC.bit.CSFB=0x1; EPwm2Regs.AQCSFRC.bit.CSFA=0x1; EPwm2Regs.AQCSFRC.bit.CSFB=0x1; EPwm3Regs.AQCSFRC.bit.CSFA=0x1; EPwm3Regs.AQCSFRC.bit.CSFB=0x1; EDIS; } void Start_car(void) { EALLOW; EPwm1Regs.CMPA.half.CMPA = duty; EPwm1Regs.CMPB = duty; EPwm2Regs.CMPA.half.CMPA = duty; EPwm2Regs.CMPB = duty; EPwm3Regs.CMPA.half.CMPA = duty; EPwm3Regs.CMPB = duty; EDIS; } interrupt void MotorControl_ISR(void) { changephase(); EPwm1Regs.ETCLR.bit.INT = 1; // 使能中断 PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; //开中断向量 Start_car(); ThreeHallout_PWM(); } void ThreeHallout_PWM(void) { EPwm1Regs.CMPA.half.CMPA = duty; EPwm1Regs.CMPB = duty; EPwm2Regs.CMPA.half.CMPA = duty; EPwm2Regs.CMPB = duty; EPwm3Regs.CMPA.half.CMPA = duty; EPwm3Regs.CMPB = duty; } void HVDMC_Protection(void) { EALLOW; EPwm1Regs.TZSEL.bit.CBC6=0x1; EPwm2Regs.TZSEL.bit.CBC6=0x1; EPwm3Regs.TZSEL.bit.CBC6=0x1; EPwm1Regs.TZSEL.bit.OSHT1 = 1; //enable TZ1 for OSHT EPwm2Regs.TZSEL.bit.OSHT1 = 1; //enable TZ1 for OSHT EPwm3Regs.TZSEL.bit.OSHT1 = 1; //enable TZ1 for OSHT EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO; // EPWMxA will go low EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO; // EPWMxB will go low EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO; // EPWMxA will go low EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO; // EPWMxB will go low EPwm3Regs.TZCTL.bit.TZA = TZ_FORCE_LO; // EPWMxA will go low EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO; // EPWMxB will go low EDIS; } //========================================================================== // No more. //========================================================= |
|
相关推荐
1个回答
|
|
仿真看一下
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
基于 DSP5509 进行数字图像处理中 Sobel 算子边缘检测的硬件连接电路图
3262 浏览 0 评论
796 浏览 0 评论
普中科技F28335开发板中,如何使用aic23播放由代码生成的正弦波
3695 浏览 0 评论
4454 浏览 1 评论
1376 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 00:24 , Processed in 0.509844 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号