文件名称:开关磁阻电机的驱动程序
文件大小:547B
文件格式:C
更新时间:2016-04-26 05:44:16
srm_spwm
对SRM电机的驱动程序 #include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File #include "IQmathLib.h" #include "UserVariable.h" #include "math.h" int rpmreal=0,te=0,te1=0; long key=0,key2=0,key3=0,key4=0,key11=0; int speed_flag=0,loci_flag=0,speed_flag1=0; _iq a=0;//转速标志 unsigned int Sci_VarRx[100]; unsigned int i=0,j=0; unsigned long a1=40000; int tem1=0,temp,k2,k3,start=0; void calrpm1(){ if(Rpm<300) rpmreal=0; else rpmreal=Rpm; } void main2() { // LCD_GotoXY(2, 80); // Sendchar(" "); LCD_GotoXY(4, 80); Sendchar("1."); LCD_GotoXY(4, 96); Sendchar("2."); LCD_GotoXY(4, 112); Sendchar("3."); LCD_GotoXY(10, 16); SendStr("第十二届挑战杯作品"); LCD_GotoXY(7, 48);//16为一行,0为列,112为最大行代码 SendStr("高速磁悬浮开关磁阻电机系统"); WriteReg(0xF1, 0x0F); LCD_GotoXY(6, 80);//16为一行,0为列,112为最大行代码//共八行 SendStr("作品简介"); LCD_GotoXY(6, 96);//16为一行,0为列,112为最大行代码 SendStr("运行状态显示"); LCD_GotoXY(6, 112);//16为一行,0为列,112为最大行代码 SendStr("轴心轨迹显示"); LCD_GotoXY(6, 144);//16为一行,0为列,112为最大行代码 SendStr("南京航空航天大学高速实验室"); LCD_GotoXY(13, 160);//16为一行,0为列,112为最大行代码 Sendchar("2011/10/20"); } void main1() { LCD_GotoXY(10, 16); SendStr("第十二届挑战杯作品"); LCD_GotoXY(7, 48);//16为一行,0为列,112为最大行代码 SendStr("高速磁悬浮开关磁阻电机系统"); LCD_GotoXY(1, 80);//16为一行,0为列,112为最大行代码 SendStr("电压: 伏"); LCD_GotoXY(1, 96);//16为一行,0为列,112为最大行代码//共八行 SendStr("设定的转速: 转 分"); LCD_GotoXY(1, 112);//16为一行,0为列,112为最大行代码 SendStr("实际的转速: 转 分"); LCD_GotoXY(5, 144);//16为一行,0为列,112为最大行代码 SendStr("南京航空航天大学高速电机实验室"); LCD_GotoXY(26, 96); Sendchar("/"); LCD_GotoXY(26, 112); Sendchar("/"); disint(8,80,(unsigned long)200,0); // disint(15,96,(unsigned long)52700,0);//功能转换很重要! disint(15,112,(unsigned long)Rpm11,1);//功能转换很重要! } void main3() { WriteReg(0x10,0x68); while(loci_flag==1) { key=keyscan(); if(key=='*') { LcdClear(); LCD_ON(); main2(); loci_flag=0; } else if(key==16) { GUI_Point(x_trace[k1],y_trace[k1],1); a6=0;//zhouxin loci sample flag delay_ms(100); if(k1==200) { // LcdClear(); ClearBig(0,0);//clear 32/160 delay_ms(100); k1=0; } } } } void main4() { /* if((k1<100)&&(a5==0)) { // GUI_Point(x_trace[k1],y_trace[k1],1); a6=0;//zhouxin loci sample flag } else { */ // a5=1; k3=k1-1; if(k3<0) k3=k1+49; GUI_Point(x_trace[k3],y_trace[k3],1); if(k3<25) { k2=k3+25; } else if((k3>25)||(k3==25)) { k2=k3-25; } a5=0; delayms(100); GUI_Point(x_trace[k2],y_trace[k2],0); a6=0;//zhouxin loci sample flag // k1++; // } } void main5() { // WriteReg(0x00, 0xC5); GUI_Point(x_trace[k1],y_trace[k1],1); delay_ms(100); if(k1<100) { k2=k1+100; } else if((k1>100)||(k1==100)) { k2=k1-100; } // WriteReg(0x00, 0xC5); GUI_Point(x_trace[k2],y_trace[k2],1); a6=0;//zhouxin loci sample flag // delay_ms(100); k1++; if(k1==200) k1=0; } void menu1() { key=keyscan(); // delayms(1); // key11=keyscan(); if(key!=16) { if(key=='A') { LcdClear(); main2(); speed_flag=0; loci_flag=0; } else if(key=='D') {start=1;speed_flag=1;LCD_ON();main1();} else if(key!='B') key2=key2*10+key; else { key3=key2; key2=0; switch(key3) { case 1:LcdClear();LCD_ON();main1();speed_flag1=1;break; case 2:LcdClear();speed_flag=1;LCD_ON();main1();speed_flag1=1;break; case 3:LcdClear();loci_flag=1;main3();speed_flag1=1;break; case 4:LcdClear();speed_flag=1;LCD_ON();main1();speed_flag1=1;break; case 5:LcdClear();speed_flag=1;LCD_ON();main1();speed_flag1=1;break; case 6:LcdClear();speed_flag=1;LCD_ON();main1();speed_flag1=1;break; } //disint(9,128,key3,0);//赋值额定转速 } } } void menu2() { int i=0; while(speed_flag==1) { delayms(1000); disint(15,112,(unsigned long)Rpm11++,1); key=keyscan(); if(key!=16) { if(key=='A') { LcdClear(); main2(); speed_flag=0; } else if(key!='B') { // disint(15+(i++),96,(unsigned long)key,0); } } } } void main(void) { // voltage=270; InitSysCtrl(); // FILE: DSP281x_SysCtrl.c DINT;//屏蔽全局中断 InitPieCtrl(); // FILE: DSP281x_PieCtrl.c pie默认状态为pie所有的中断都禁止,且标志位清零 IER = 0x0000;//禁止cpu中断并清除所有的cpu中断标志位 IFR = 0x0000; InitPieVectTable(); //piecrtl.enpie已定义 EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &TINT0_ISR; EDIS; // Define PIE interrupt PieCtrlRegs.PIEIER1.all=0x0043; // PDPINTA(EV-A) interrupt //对应向量表中的各位,使能位p62 PieCtrlRegs.PIEIFR1.all=0x0000; //标志寄存器,中断时自动置位 PieCtrlRegs.PIEIER2.all=0x0008; // T1PINT(EV-A) interrupt PieCtrlRegs.PIEIFR2.all=0x0000; PieCtrlRegs.PIEIER3.all=0x0001; // T2PINT(EV-A) interrupt PieCtrlRegs.PIEIFR3.all=0x0000; PieCtrlRegs.PIEIER4.all=0x0008; // T3PINT(EV-B) interrupt PieCtrlRegs.PIEIFR4.all=0x0000; PieCtrlRegs.PIEIER5.all=0x0070; // CAPINT4,CAPINT5,CAPINT6 interrupt PieCtrlRegs.PIEIFR5.all=0x0000; PieCtrlRegs.PIEIER9.all=0x0003; //sci send and recieve interrupt PieCtrlRegs.PIEIFR9.all=0x0000; IER=0x011F; // level1,level2,level3,level4,level5; //int1,2,3,4,5,9 p57 InitCpuTimers(); ConfigCpuTimer(&CpuTimer0, 150, 100); StartCpuTimer0(); InitEv(); InitTimer(); InitAdc(); // InitSci(); InitGpio(); Init_LCD(); delay_ms(10000); LCD_ON(); delay_ms(100); main2(); //the reg 0x10 never set up before // LcdClear(); // WriteReg(0x00, 0xC5);//photo point!!!!!!!!! //temp = lcd_read(0x00); // ClearBig(0,0); //176,24//320240--30/240(row and line) (+64,+8)(line,row) while(1) { EINT; delayms(200); menu1(); menu2(); // delayms(100); // WriteReg(0x00, 0xC5);// // temp = lcd_read(0x00);//正式程序不能加 // tem1 = lcd_read(0xF0); /* delayms(100); main4(); */ /* if(start==1) { while(ii<200) { selfstart(); } } */ } }