#includeDSP28_Device.hEVAeva=EVA_DEFAULTS;EVBevb=EVB_DEFAULTS;RAMPGENrampgen=RAMPGEN_DEFAULTS;VHZPROFvhzprof=VHZPROF_DEFAULTS;SVGENDQsvgendq=SVGENDQ_DEFAULTS;ROTATEVECTORrotatevector=ROTATEVECTOR_DEFAULTS;staticunsignedintRBBuf;staticunsignedintRABuf;interruptvoidISRTimer1(void);interruptvoidISRTimer2(void);interruptvoidT1UFINT_ISR(void);longf_given=0;longf_now=0;floathappy=0;//显示相关unsignedintf_given_disp=0;//接到的的值unsignedintku=10;//输入电压与电机额定电压的比unsignedintDispBuf[2];//显示缓存,存在EEPROM,(ku,f_given)unsignedintRunFlag=0;//运行标志unsignedintTurnFlag=0;//正反转//_iqha=65545;//_iqhb=65521;//_iqhc;voidShowDisp(void);//显示函数,用于将数据显示到显示板_iqtest1[20];_iqtest2[20];voidmain(void){/*初始化系统*/InitSysCtrl();/*关中断*/DINT;IER=0x0000;IFR=0x0000;/*初始化PIE控制寄存器*/InitPieCtrl();/*初始化PIE矢量表*/InitPieVectTable();/*初始化SCIb寄存器*/InitSci();//初始化24Vxx//Init24Cxx();/*设置CPU定时器*/InitCpuTimers();ConfigCpuTimer(&CpuTimer2,150,20000);ConfigCpuTimer(&CpuTimer1,150,100000);//每0.1秒加1Hz,每秒加Y*1000000赫兹StartCpuTimer1();StartCpuTimer2();/*初始化IO口*///InitGpio();/*初始化EV*/eva.Init(&eva);evb.Init(&evb);/*设置中断服务程序入口地址*/EALLOW;//ThisisneededtowritetoEALLOWprotectedregistersPieVectTable.T1UFINT=&T1UFINT_ISR;PieVectTable.TXBINT=&SCITXINTB_ISR;//设置串口B发送中断的中断向量PieVectTable.RXBINT=&SCIRXINTB_ISR;//设置串口B接受中断的中断向量PieVectTable.TXAINT=&SCITXINTA_ISR;//设置串口A发送中断的中断向量PieVectTable.RXAINT=&SCIRXINTA_ISR;//设置串口A接受中断的中断向量PieVectTable.TINT2=&ISRTimer2;PieVectTable.XINT13=&ISRTimer1;//定时器1和外部中断合用一个中断标志位//此处为XINT13并不是TINT1EDIS;//ThisisneededtodisablewritetoEALLOWprotectedregisters/*使能位于PIE中组2的第6个中断定时器1下溢中断*/PieCtrl.PIEIER2.bit.INTx6=1;/*开中断*/IER|=M_INT2;//EVAIER|=M_INT9;//SCI//允许串口中断IER|=M_INT14;//cputimer2IER|=M_INT13;//cputimer1EINT;//EnableGlobalinterruptINTMERTM;//EnableGlobalrealtimeinterruptDBGMeva.Close(&eva);evb.Open(&evb);rampgen.StepAngleMax=_IQ(0.0128);//最大频率128hz中断频率10kwhile(1){//hc=_IQmpy(ha,hb);只进行保留整数位,对于小数位不进行四舍五入。hc=(ha*hb)/65536}}//===========================================================================//定时器1下溢中断服务程序.//===========================================================================interruptvoidT1UFINT_ISR(void)//EV-A{//asm(ESTOP0);//PieCtrl.PIEACK.bit.ACK2=1;//EvaRegs.EVAIFRA.bit.T1UFINT=1;//清中断标志位//rampgen模块产生矢量旋转的角度需要设置StepAngleMax这里是控制转速的。//rampgen.Freq=_IQ(50)7;rampgen.Freq=_IQ((float)f_now)7;//因为最大频率128Hz,是2的7次方,那么除以128就是以最大频率来看的标幺值rampgen.calc(&rampgen);//vhzprof模块vvvf控制,根据频率比例控制输出电压的量//vhzprof.Freq=_IQ(50);vhzprof.Freq=_IQ((float)f_now)+_IQ(0.11);vhzprof.calc(&vhzprof);//RotateVector模块产生旋转矢量对应的UalphaUbetaif(TurnFlag==0){rotatevector.Angle=rampgen.Angle;//停止标志}else{rotatevector.Angle=-rampgen.Angle;}rotatevector.k=vhzprof.VoltOut;rotatevector.calc(&rotatevector);//svgendq模块根据UalphaUbeta产生比较器需要的TATBTCsvgendq.Ualpha=rotatevector.Ualpha;svgendq.Ubeta=rotatevector.Ubeta;svgendq.calc(&svgendq);happy=rotatevector.Angle;//ev模块eva.Ta=svgendq.Ta;eva.Tb=svgendq.Tb;eva.Tc=svgendq.Tc;eva.SetPwm(&eva);evb.Ta=svgendq.Ta;evb.Tb=svgendq.Tb;evb.Tc=svgendq.Tc;evb.SetPwm(&evb);PieCtrl.PIEACK.bit.ACK2=1;EvaRegs.EVAIFRA.bit.T1UFINT=1;//清中断标志位}interruptvoidSCIRXINTA_ISR(void){PieCtrl.PIEACK.bit.ACK9=1;RABuf=SciaRegs.SCIRXBUF.all;switch(RABuf){}EINT;}interruptvoidSCIRXINTB_ISR(void)//SCI-B{PieCtrl.PIEACK.bit.ACK9=1;//相应PIE组9的其他中断RBBuf=ScibRegs.SCIRXBUF.all;switch(RBBuf){case0://增加输入电压百分比break;case1://运行break;case2://增加频率break;case3://增加频率break;case4://减少输入电压百分比break;case5://停止f_given=0;break;case6://减小频率break;case7://减小频率break;}EINT;}interruptvoidISRTimer1(void){//内部定义的计数变量if(RABuf==0){CpuTimer1.InterruptCount=0;f_given=0;SciaRegs.SCITXBUF=(unsignedint)f_now;f_given_disp=f_now;}if(RABuf==1)//FWDAuto{//unsignedinta;RunFlag=1;eva.Open(&eva);f_given_disp=f_now;TurnFlag=0;CpuTimer1.InterruptCount++;if((CpuTimer1.InterruptCount20)&&(CpuTimer1.InterruptCount0)){f_given++;f_now=f_given;//f_given=f_now;SciaRegs.SCITXBUF=(unsignedint)f_now;}if((CpuTimer1.InterruptCount=20)&&(CpuTimer1.InterruptCount30)){f_given=f_now;SciaRegs.SCITXBUF=(unsignedint)f_now;}if((CpuTimer1.InterruptCount=30)&&(CpuTimer1.InterruptCount50)){f_given--;f_now=f_given;SciaRegs.SCITXBUF=(unsignedint)f_now;}if(CpuTimer1.InterruptCount=50){f_given=0;f_now=0;SciaRegs.SCITXBUF=(unsignedint)f_now;eva.Close(&eva);//RABuf=0;}}if(RABuf==2)//REVAuto{RunFlag=1;eva.Open(&eva);f_given_disp=f_now;TurnFlag=1;CpuTimer1.InterruptCount++;if((CpuTimer1.InterruptCount20)&&(CpuTimer1.InterruptCount0)){f_given++;f_now=f_given;SciaRegs.SCITXBUF=(unsignedint)f_now;}if((CpuTimer1.InterruptCount=20)&&(CpuTimer1.InterruptCount40)){f_given=f_now;SciaRegs.SCITXBUF=(unsignedint)f_now;}if(CpuTimer1.InterruptCount=40){f_given=0;f_now=0;SciaRegs.SCITXBUF=(unsignedint)f_now;eva.Close(&eva);//RABuf=0;}}if(RABuf==3)//FWDHigh{CpuTimer1.InterruptCount=0;TurnFlag=0;RunFlag=1;eva.Open(&eva);f_now=10;f_given=10;f_given_disp=f_now;//CpuTimer1.InterruptCount++;//if(CpuTimer1.InterruptCount=10)//{//RABuf=0;//CpuTimer1.InterruptCount=0;//}SciaRegs.SCITXBUF=(unsignedint)f_now;}if(RABuf==4)//REVHigh{CpuTimer1.InterruptCount=0;TurnFlag=1