基于DSP28035的SPWM生成程序_第1頁(yè)
基于DSP28035的SPWM生成程序_第2頁(yè)
基于DSP28035的SPWM生成程序_第3頁(yè)
基于DSP28035的SPWM生成程序_第4頁(yè)
基于DSP28035的SPWM生成程序_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)專心-專注-專業(yè)精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)#include DSP28x_Project.h#include IQmathLib.h/#include math.h#define PWM1_INT_ENABLE 1#define PWM2_INT_ENABLE 1#define PWM3_INT_ENABLE 1#define PWM4_INT_ENABLE 1void InitEPwm1Example(void);void InitEPwm2Example(void);void InitEPwm3Exampl

2、e(void);interrupt void epwm1_timer_isr(void);/interrupt void epwm2_timer_isr(void);/interrupt void epwm3_timer_isr(void);Uint32 EPwm1TimerIntCount;Uint32 EPwm2TimerIntCount;Uint32 EPwm3TimerIntCount;Uint32 EPwm4TimerIntCount;Uint32 TonC1,TonC2;Uint16 k;float32 Tc,N;#define PI 3.float32 M=0.8;float32

3、 fz=20000;float32 fr=50;void main(void) InitSysCtrl(); InitEPwm1Gpio(); / InitEPwm2Gpio(); / InitEPwm3Gpio(); DINT; InitPieCtrl(); IER = 0 x0000; IFR = 0 x0000; InitPieVectTable(); EALLOW; / This is needed to write to EALLOW protected registers PieVectTable.EPWM1_INT = &epwm1_timer_isr; / PieVectTab

4、le.EPWM2_INT = &epwm2_timer_isr; / PieVectTable.EPWM3_INT = &epwm3_timer_isr; EDIS; EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; / Stop all the TB clocks EDIS; InitEPwm1Example(); / InitEPwm2Example(); / InitEPwm3Example(); EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; EPwm1TimerIntCount =

5、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; / Enable Global interrupt INTM ERTM; for(;) asm( NOP); void InitEPwm1Example(

6、) EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;/zhuyi EPwm1Regs.TBPRD = 1500; /載波周期=2*1500TBCLK EPwm1Regs.TBPHS.half.TBPHS = 0 x0000; / Phase is 0 EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; EPwm1Regs.TBCTR = 0 x0000; EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; / Count up down EPwm1Regs.TBCTL.bit.PHSEN

7、= TB_DISABLE; / Disable phase loading EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; / Clock ratio to SYSCLKOUT EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; / Load registers every ZERO_PRD EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_

8、CTR_ZERO_PRD; EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO_PRD; EPwm1Regs.CMPA.half.CMPA =1000; EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; / Clear PWM1A on CAU EPwm1Regs.AQCTLA.bit.CAD = AQ_SET; EPwm1Regs.AQCTLB.bit.CAU = AQ_SET; / SET PWM1B on CAU EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR; /set dead band EPwm1

9、Regs.ETSEL.bit.INTSEL = ET_CTR_PRDZERO; /? Select INT on Zero Prd event EPwm1Regs.ETSEL.bit.INTEN = PWM1_INT_ENABLE; / Enable INT EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;interrupt void epwm1_timer_isr(void) EPwm1TimerIntCount+; if( EPwm1Regs.TBCTR=1500) k=0; N=fz/fr; Tc=1/fz; TonC1=Tc/4*(1+M*sin(k*PI/N);

10、 k+=2; if(k(2*N-2) k=0; EPwm1Regs.CMPA.half.CMPA = TonC1; / EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; / Clear PWM1A on CAU / EPwm1Regs.AQCTLA.bit.CAD = AQ_SET; / EPwm1Regs.AQCTLB.bit.CAU = AQ_SET; / SET PWM1B on CAU / EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR; else k=1; N=fz/fr; Tc=1/fz; TonC2=Tc/4*(1+M*sin(k*

11、PI/N); k+=2; if(k(2*N-1) k=1; EPwm1Regs.CMPA.half.CMPA = TonC2;/ EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; / Clear PWM1A on CAU/ EPwm1Regs.AQCTLA.bit.CAD = AQ_SET; / EPwm1Regs.AQCTLB.bit.CAU = AQ_SET; / SET PWM1B on CAU / EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR; / Clear INT flag for this timer EPwm1Regs.ETCL

12、R.bit.INT = 1; / Acknowledge this interrupt to receive more interrupts from group 3 PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;#include DSP280 x_Device.h / DSP280 x Headerfile Include File#include DSP280 x_Examples.h / DSP280 x Examples Include Filevoid InitePWM(void) EALLOW;EPwm1Regs.TBPRD = 600; / Per

13、iod = 601 TBCLK countsEPwm1Regs.CMPA = 350; / Compare A = 350 TBCLK countsEPwm1Regs.CMPB = 200; / Compare B = 200 TBCLK countsEPwm1Regs.TBPHS = 0; / Set Phase register to zeroEPwm1Regs.TBCTR = 0; / clear TB counterEPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; / Ph

14、ase loading disabledEPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; / TBCLK = SYSCLKEPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;EPwm1Regs.CMPCT

15、L.bit.LOADAMODE = CC_CTR_ZERO; / load on CTR = ZeroEPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; / load on CTR = ZeroEPwm1Regs.AQCTLA.bit.PRD = AQ_CLEAR;EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;EPwm1Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;E

16、Pwm1Regs.PCCTL.bit.CHPEN = CHP_DISABLE;EPwm1Regs.TZCTL.bit.TZA = TZ_NO_CHANGE;EPwm1Regs.TZCTL.bit.TZB = TZ_NO_CHANGE;EDIS;#includeDSP28_Device.h #includestdio.h #includemath.h #includefloat.h #defineNX404 #definePI3. floatM=0.8;intk0,h1,h2;doubleaNX;externinttp=1250;voidzkb();interruptvoideva_T1UFIN

17、T_ISR(void);voidmain(void)k0=0;h1=0;h2=0;InitSysCtrl();DINT;/禁止全局中斷 IER=0;IFR=0;EALLOW;/EnablePWMpins GpioMuxRegs.GPAMUX.all=0 x00FF;/EVAPWM1-6pins /GpioMuxRegs.GPBMUX.all=0 x00FF;/EVBPWM7-12pins EDIS;InitPieCtrl();InitPieVectTable();EALLOW;PieVectTable.T1UFINT=&eva_T1UFINT_ISR;EDIS;IER|=M_INT2;PieC

18、trl.PIEIER2.bit.INTx6=1;InitEv();zkb();EvaRegs.T1CON.all=EvaRegs.T1CON.all|0 x0040;/啟動(dòng)定時(shí)器1 EINT;while(1)asm(NOP);voidzkb()unsignedintn=0;floatq,l,j;while(n=375&l3375)an=3375;elsean=375;n=n+1;*/if(l=(tp*0.1)&(l(tp*0.9)an=tp*0.9;elsean=tp*0.1;n=n+1;interruptvoideva_T1UFINT_ISR(void)/EV-A inth2;intflag;flag=(EvaRegs.EVAIFRA.all)&0

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論