DSP28335光伏并网逆变器主函数main.c

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#defineMATH_TYPEFLOAT_MATH#includeDSP28x_Project.h#includeIQmathLib.h#includespwm_pwm.h#includespwm_cap.h#includespwm_ad.h#includeLcd_12864.h#includePID_REG3.h#includeKey.h#includeLed.h#includeDS18B20.h#includeSCI.h//#includeMenu.h#includemath.h#includestdio.h#includestdlib.h#defineSet_DCDC_Voltage360#defineSet_OUT_Voltage220#defineISR_FREQUENCY10//PWM频率10k#defineNumber5//滤波的采样个数#defineNN200//一个周期波内点的个数/*****************************************************//*********************//**********头文件声明***********//*********************//*****************************************************/interruptvoidcpu_timer0_isr(void);interruptvoidepwm1and2_isr(void);interruptvoidecap5_isr(void);interruptvoidecap6_isr(void);interruptvoidadc_isr(void);voidAdjust_phase_freq(void);voidProcess_ADC(void);voidLCD12864Display(void);voidMppt(floatRefVoltage,floatRealVoltage);voidTurn_DC_DC(floatRefVoltage,floatRealVoltage);voidPid_Mppt(_iqRef,_iqFdb);/*****************************************************//*********************//**********全局变量声明***********//*********************//*****************************************************/floatm=0.70;//m为调制比Uint16EPwmCount=0;Uint16EPwmTimerIntCount=0,n=0;//n为正弦波数组变量,EPwmTimerIntCount为Uint16spwm[NN];//cap5&cap6的全局变量Uint32Compare_temp=0;//cap5中使用Uint32Stand_temp=0;//cap6中未处理的周期float32Phase;//相位角float32Freq,fs;//测量频率&实际频率float32Freq_temp[Number];float32Phase_temp[Number];float32EPWM_TIMER;volatileUint16Freq_Flag5,Freq_Flag6;//中断标志位Uint16Freq_cnt,Freq_over;Uint16cnt_Add;Uint16Phase_cnt;//ADC的全局变量volatileUint16ADC_Flag;Uint16ConversionCount;//AD采样次数Uint32Udc=0,Idc=0,Uout=0;float32U_dc=0,I_dc=0,U_out=0;volatileUint16Mppt_Turn_Flag=0;volatileUint16Display_Flag=0;//显示标志//KeyUint16Key_State=0;float32T=0.2;PIDREG3pid1_mppt=PIDREG3_DEFAULTS;Uint16Temperature=0;charInput_Voltage[5]={0};charOutput_Voltage[5]={0};charRef_voltage[5]={0};charwendu[6]={0};char*msg;/*****************************************************//*****************************************************//*********************//**********MAINPROCESSPROGRAM***********//*********************//*****************************************************//*****************************************************/voidmain(void){InitSysCtrl();//ADC时钟EALLOW;SysCtrlRegs.HISPCP.all=ADC_MODCLK;//HSPCLK=SYSCLKOUT/ADC_MODCLKEDIS;//GPIO初始化InitEPwm1Gpio();//PWM1IO初始化//InitEPwm2Gpio();//PWM2IO初始化InitEPwm3Gpio();//PWM3IO初始化//InitECap5Gpio();//捕获IO初始化//InitECap6Gpio();//捕获IO初始化Init_Lcd_Gpio();//初始化液晶IO口Init_Led_Gpio();//初始化LEDIO口//Init_Key_Gpio();//初始化按键//InitScicGpio();//初始化串口//Init_DS18B20_Gpio();//初始化DS18B20Light_ON;//openlightBEEP_OFF;//closebeepDINT;InitPieCtrl();IER=0x0000;IFR=0x0000;InitPieVectTable();MemCopy(&RamfuncsLoadStart,&RamfuncsLoadEnd,&RamfuncsRunStart);InitFlash();InitAdc();//ADC初始化Init_AD();EALLOW;//ThisisneededtowritetoEALLOWprotectedregistersPieVectTable.TINT0=&cpu_timer0_isr;//PieVectTable.EPWM1_INT=&epwm1and2_isr;//PieVectTable.ECAP5_INT=&ecap5_isr;//PieVectTable.ECAP6_INT=&ecap6_isr;PieVectTable.ADCINT=&adc_isr;EDIS;//ThisisneededtodisablewritetoEALLOWprotectedregistersIER|=M_INT1;//EnableCPUInterrupt1//IER|=M_INT3;//epwm1and2_isr//IER|=M_INT4;//ecap5_isr&ecap6_isr//PieCtrlRegs.PIEIER3.bit.INTx1=1;//epwm1and2_isr//PieCtrlRegs.PIEIER4.bit.INTx5=1;//ecap5_isr//PieCtrlRegs.PIEIER4.bit.INTx6=1;//ecap6_isrPieCtrlRegs.PIEIER1.bit.INTx6=1;//adc_isrPieCtrlRegs.PIEIER1.bit.INTx7=1;//cpu_timer0_isrInitCpuTimers();ConfigCpuTimer(&CpuTimer0,150,20000);//定时时间0.02sCpuTimer0Regs.TCR.all=0x4001;//Usewrite-onlyinstructiontosetTSSbit=0//InitECapture5();//初始化cap5//InitECapture6();//初始化cap6Init_LCD();//初始化液晶//scic_fifo_init();//InitializetheSCIFIFO//scic_echoback_init();//InitalizeSCIforechoback//msg=\r\n\n\nHelloWorld!\0;//scic_msg(msg);//msg=\r\nYouwillenteracharacter,andtheDSPwillechoitback!\n\0;//scic_msg(msg);EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=0;EDIS;InitEPWM1();//初始化PWM1//forSPWM//InitEPWM2();//初始化PWM2//forSPWMInitEPWM3();//初始化PWM3//forDC-DCEALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=1;EDIS;//初始化全局变量fs=50.0;EPWM_TIMER=1000000000.0/fs/NN/2/6.66667;EPWM_TIMER=EPWM_TIMER+1;//计算占空比while(nNN){spwm[n]=(int)EPWM_TIMER*(((sin(PI/(NN/2)*n)*m)+1)/2);n++;}n=0;EPwm1Regs.TBPRD=((Uint16)EPWM_TIMER);EPwm2Regs.TBPRD=((Uint16)EPWM_TIMER);//EnableglobalInterruptsandhigherpriorityreal-timedebugevents:EnableInterrupts();EINT;//EnableGlobalinterruptINTMERTM;//EnableGlobalrealtimeinterruptDBGM//Step6.IDLEloop.Justsitandloopforever(optional):for(;;){if(ADC_Flag)//0.02s{Process_ADC();ADC_Flag=0;}if(Display_Flag!=0)//1s{LCD12864Display();Display_Flag=0;}if(Mppt_Turn_Flag!=0)//0.1s{Turn_DC_DC(Set_DCDC_Voltage,U_dc);//Mppt(Set_OUT_Voltage,U_out);Mppt_Turn_Flag=0;}}}voidLCD12864Display(void){ltoa(((long)U_dc),Input_Voltage);ltoa(((long)U_out),Output_Voltage);ltoa(((long)Set_OUT_Voltage),Ref_voltage);if(U_dc200.0){//print(1,1,频率:50HZ);print(1,2,输入电压:V);//print(1,3,输出电压:V);//print(1,4,设置电压:V);print(1,1,DC-DC升压实验);print(6,2,200);//print(6,3,Output_Voltage);//print(6,4,Ref_voltage);

1 / 14
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功