svpwm源程序

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

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

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

资源描述

/TIFile$Revision:/main/8$//Checkin$Date:April21,200815:41:53$//###########################################################################////FILE:Example_2833xEPwmUpDownAQ.c////TITLE:空间电压矢量产生程序SVPWM////ASSUMPTIONS:////ThisprogramrequirestheDSP2833xheaderfiles.////MonitorePWM1-ePWM3pinsonanoscilloscopeasdescribed//below.////EPWM1AisonGPIO0-------5脚//EPWM1BisonGPIO1-------6脚////EPWM2AisonGPIO2-------7脚//EPWM2BisonGPIO3-------10脚////EPWM3AisonGPIO4-------11脚//EPWM3BisonGPIO5-------12脚//////###########################################################################//$TIRelease:DSP2833x/DSP2823xHeaderFilesV1.20$//$ReleaseDate:August1,2008$//############################################################################includeDSP28x_Project.h//DeviceHeaderfileandExamplesIncludeFile//Prototypestatementsforfunctionsfoundwithinthisfile.voidInitEPwm1Example(void);voidInitEPwm2Example(void);voidInitEPwm3Example(void);voidsvpwmGen(void);interruptvoidsvpwm_isr(void);volatilefloatUalpha,Ubeta;volatilefloatA,B,C;volatilefloatT0,T1,T2,T3,T4,T5,T6;volatilefloatTaon,Tbon,Tcon;floatUa,Ub,Uc;floatTs;inta,b,c;intN=0,sector=0;#defineTPRD800#defineUdc800voidmain(void){//Step1.InitializeSystemControl://PLL,WatchDog,enablePeripheralClocks//ThisexamplefunctionisfoundintheDSP2833x_SysCtrl.cfile.InitSysCtrl();//Step2.InitalizeGPIO://ThisexamplefunctionisfoundintheDSP2833x_Gpio.cfileand//illustrateshowtosettheGPIOtoit'sdefaultstate.//InitGpio();//Skippedforthisexample//ForthiscasejustinitGPIOpinsforePWM1,ePWM2,ePWM3//ThesefunctionsareintheDSP2833x_EPwm.cfileInitEPwm1Gpio();InitEPwm2Gpio();InitEPwm3Gpio();//Step3.ClearallinterruptsandinitializePIEvectortable://DisableCPUinterruptsDINT;//InitializethePIEcontrolregisterstotheirdefaultstate.//ThedefaultstateisallPIEinterruptsdisabledandflags//arecleared.//ThisfunctionisfoundintheDSP2833x_PieCtrl.cfile.InitPieCtrl();//DisableCPUinterruptsandclearallCPUinterruptflags:IER=0x0000;IFR=0x0000;//InitializethePIEvectortablewithpointerstotheshellInterrupt//ServiceRoutines(ISR).//Thiswillpopulatetheentiretable,eveniftheinterrupt//isnotusedinthisexample.Thisisusefulfordebugpurposes.//TheshellISRroutinesarefoundinDSP2833x_DefaultIsr.c.//ThisfunctionisfoundinDSP2833x_PieVect.c.InitPieVectTable();//Interruptsthatareusedinthisexamplearere-mappedto//ISRfunctionsfoundwithinthisfile.EALLOW;//ThisisneededtowritetoEALLOWprotectedregistersPieVectTable.EPWM1_INT=&svpwm_isr;//PieVectTable.EPWM2_INT=&epwm2_isr;//PieVectTable.EPWM3_INT=&epwm3_isr;EDIS;//ThisisneededtodisablewritetoEALLOWprotectedregisters//Step4.InitializealltheDevicePeripherals://ThisfunctionisfoundinDSP2833x_InitPeripherals.c//InitPeripherals();//Notrequiredforthisexample//Forthisexample,onlyinitializetheePWMEALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=0;EDIS;InitEPwm1Example();InitEPwm2Example();InitEPwm3Example();EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=1;EDIS;//Step5.Userspecificcode,enableinterrupts://EnableCPUINT3whichisconnectedtoEPWM1-3INT:IER|=M_INT3;//EnableEPWMINTninthePIE:Group3interrupt1-3PieCtrlRegs.PIEIER3.bit.INTx1=1;//PieCtrlRegs.PIEIER3.bit.INTx2=1;//PieCtrlRegs.PIEIER3.bit.INTx3=1;//EnableglobalInterruptsandhigherpriorityreal-timedebugevents:EINT;//EnableGlobalinterruptINTMERTM;//EnableGlobalrealtimeinterruptDBGM//Step6.IDLEloop.Justsitandloopforever(optional):for(;;){asm(NOP);}}//main结束//=======================================================================interruptvoidsvpwm_isr(void){svpwmGen();//SetComparevaluesEPwm1Regs.CMPA.half.CMPA=Taon;//adjustdutyforoutputEPWM1AEPwm2Regs.CMPA.half.CMPA=Tbon;//adjustdutyforoutputEPWM2AEPwm3Regs.CMPA.half.CMPA=Tcon;//adjustdutyforoutputEPWM3A//ClearINTflagforthistimerEPwm1Regs.ETCLR.bit.INT=1;//Acknowledgethisinterrupttoreceivemoreinterruptsfromgroup3PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;}voidInitEPwm1Example(){//SetupTBCLKEPwm1Regs.TBPRD=TPRD;//TPRD=800,Period=1600TBCLKcountsEPwm1Regs.TBPHS.half.TBPHS=0;//SetPhaseregistertozeroEPwm1Regs.TBCTR=0x0000;//Clearcounter//SetupcountermodeEPwm1Regs.TBCTL.bit.CTRMODE=TB_COUNT_UPDOWN;//SymmetricalmodeEPwm1Regs.TBCTL.bit.PHSEN=TB_DISABLE;//////////////////////////MastermoduleEPwm1Regs.TBCTL.bit.PRDLD=TB_SHADOW;EPwm1Regs.TBCTL.bit.SYNCOSEL=TB_CTR_ZERO;/////////////////////Syncdown-streammodule//SetupTpwmEPwm1Regs.TBCTL.bit.HSPCLKDIV=TB_DIV2;//ClockratiotoSYSCLKOUTEPwm1Regs.TBCTL.bit.CLKDIV=5;//原为TB_DIV1,对于上下计数:Tpwm=2xTBPRDxTTBCLKFpwm=1/(Tpwm)//SetupshadowingEPwm1Regs.CMPCTL.bit.SHDWAMODE=CC_SHADOW;EPwm1Regs.CMPCTL.bit.SHDWBMODE=CC_SHADOW;EPwm1Regs.CMPCTL.bit.LOADAMODE=CC_CTR_ZERO;//loadonCTR=ZeroEPwm1Regs.CMPCTL.bit.LOADBMODE=CC_CTR_ZERO;//loadonCTR=Zero//SetactionsEPwm1Regs.AQCTLA.bit.CAU=AQ_SET;//setactionsforEPWM1AEPwm1Regs.AQCTLA.bit.CAD=AQ_CLEAR;//SetDead-bandEPwm1Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE;//enableDead-bandmoduleEPwm1Regs.DBCTL.bit.POLSEL=DB_ACTV_HIC;//ActiveHicomplementaryEPwm1Regs.DBFED=50;//FED=50TBCLKsEPwm1Regs.DBRED=50;//RED=50TBCLKs//InterruptwherewewillchangetheCompareValuesEPwm1Regs.ETSEL.bit.INTSEL=ET_CTR_ZERO;//SelectINTonZero

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

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

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

×
保存成功