DSP28335生成正弦波的程序

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

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

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

资源描述

//²úÉúÖÜÆڱ仯µÄÕýÏÒ²¨#includeDSP2833x_Device.h//DSP2833xHeaderfileIncludeFile#includeDSP2833x_Examples.h//DSP2833xExamplesIncludeFile#includeIQmathLib.h#includeqmath.h#includemath.h#defineN33#definePI3.1415925#definePRD600floatM=0.8;inti;//doublea[N];//unsignedintn=0;//floatQ;#definePWM1_INT_ENABLE1#definePWM2_INT_ENABLE1#definePWM3_INT_ENABLE1voidInitEPwm1Example(void);//voidInitEPwm2Example(void);//voidInitEPwm3Example(void);interruptvoidepwm1_timer_isr(void);//interruptvoidepwm2_timer_isr(void);//interruptvoidepwm3_timer_isr(void);//voidInitCmp();//externUint16NN,MM;//Uint16NN=24,MM=1;//Uint16n=0;Uint16cmp1[360],cmp2[360],cmp3[360];Uint32EPwm1TimerIntCount;Uint32EPwm2TimerIntCount;Uint32EPwm3TimerIntCount;voidmain(void){InitSysCtrl();InitEPwm1Gpio();//InitEPwm2Gpio();//InitEPwm3Gpio();DINT;InitPieCtrl();IER=0x0000;IFR=0x0000;InitPieVectTable();EALLOW;//ThisisneededtowritetoEALLOWprotectedregistersPieVectTable.EPWM1_INT=&epwm1_timer_isr;//PieVectTable.EPWM2_INT=&epwm2_timer_isr;//PieVectTable.EPWM3_INT=&epwm3_timer_isr;EDIS;EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=0;//StopalltheTBclocksEDIS;InitEPwm1Example();//InitEPwm2Example();//InitEPwm3Example();//InitCmp();EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=1;EDIS;EPwm1TimerIntCount=0;EPwm2TimerIntCount=0;EPwm3TimerIntCount=0;IER|=M_INT3;PieCtrlRegs.PIEIER3.bit.INTx1=PWM1_INT_ENABLE;//PieCtrlRegs.PIEIER3.bit.INTx2=PWM2_INT_ENABLE;//PieCtrlRegs.PIEIER3.bit.INTx3=PWM3_INT_ENABLE;EINT;//EnableGlobalinterruptINTMERTM;{asm(NOP);}}voidInitEPwm1Example(){EPwm1Regs.TBCTL.bit.SYNCOSEL=TB_CTR_ZERO;//zhuyiEPwm1Regs.TBPRD=PRD;//Ôز¨ÖÜÆÚ=2*1500TBCLKEPwm1Regs.TBPHS.half.TBPHS=0x0000;//Phaseis0EPwm1Regs.TBCTL.bit.PRDLD=TB_SHADOW;EPwm1Regs.TBCTR=0x0000;EPwm1Regs.TBCTL.bit.CTRMODE=TB_COUNT_UPDOWN;//CountupdownEPwm1Regs.TBCTL.bit.PHSEN=TB_DISABLE;//DisablephaseloadingEPwm1Regs.TBCTL.bit.HSPCLKDIV=TB_DIV2;//ClockratiotoSYSCLKOUTEPwm1Regs.TBCTL.bit.CLKDIV=TB_DIV2;EPwm1Regs.CMPCTL.bit.SHDWAMODE=CC_SHADOW;//LoadregisterseveryZERO_PRDEPwm1Regs.CMPCTL.bit.SHDWBMODE=CC_SHADOW;EPwm1Regs.CMPCTL.bit.LOADAMODE=CC_CTR_ZERO;//£¿£¿EPwm1Regs.CMPCTL.bit.LOADBMODE=CC_CTR_ZERO;//EPwm1Regs.CMPA.half.CMPA=1000;EPwm1Regs.AQCTLA.bit.CAU=AQ_CLEAR;//ClearPWM1AonCAUEPwm1Regs.AQCTLA.bit.CAD=AQ_SET;EPwm1Regs.AQCTLB.bit.CAU=AQ_SET;//SETPWM1BonCAU£¬Êä³ö»¥²¹²¨ÐÎEPwm1Regs.AQCTLB.bit.CAD=AQ_CLEAR;//setdeadband//ÉèÖÃÖжÏEPwm1Regs.ETSEL.bit.INTSEL=ET_CTR_PRD;//?SelectINTonZeroPrdeventEPwm1Regs.ETSEL.bit.INTEN=PWM1_INT_ENABLE;//EnableINTEPwm1Regs.ETPS.bit.INTPRD=ET_1ST;}/*voidInitCmp(){//Uint16i=0;if(iN){cmp1[i]=(Uint16)(EPwm1Regs.TBPRD*0.25*(1+M*sin((2*i)*PI/N)+1+M*sin((2*i+1)*PI/N)));//cmp2[i]=(Uint16)(EvaRegs.T1PR*0.25*(1+M*sin((2*i)*PI/N+PI*4/3)+1+M*sin((2*i+1)*PI/N+PI*4/3)));//cmp3[i]=(Uint16)(EvaRegs.T1PR*0.25*(1+M*sin((2*i)*PI/N+PI*2/3)+1+M*sin((2*i+1)*PI/N+PI*2/3)));i++;}else{i=0;}}*///±È½ÏÖµÊÇ°´ÕýÏÒ²¨±ä»¯µÄinterruptvoidepwm1_timer_isr(void){if(iN){//cmp1[i]=(Uint16)(EPwm1Regs.TBPRD*sin((2*i)*PI/N)cmp1[i]=(Uint16)(EPwm1Regs.TBPRD*0.25*(1+M*sin((2*i)*PI/N)+1+M*sin((2*i+1)*PI/N)));//cmp2[i]=(Uint16)(EvaRegs.T1PR*0.25*(1+M*sin((2*i)*PI/N+PI*4/3)+1+M*sin((2*i+1)*PI/N+PI*4/3)));//cmp3[i]=(Uint16)(EvaRegs.T1PR*0.25*(1+M*sin((2*i)*PI/N+PI*2/3)+1+M*sin((2*i+1)*PI/N+PI*2/3)));EPwm1Regs.CMPA.half.CMPA=cmp1[i];i++;}else{i=0;}EPwm1Regs.ETCLR.bit.INT=1;PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;}

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

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

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

×
保存成功